PluginProbe
ShiftController Employee Shift Scheduling / 2.2.4
ShiftController Employee Shift Scheduling v2.2.4
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
shiftcontroller / application / controllers / admin / stats.php

stats.php in ShiftController Employee Shift Scheduling 2.2.4, at application/controllers/admin/stats.php

99 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2
3 class Stats_controller extends Backend_controller
4 {
5 function __construct()
6 {
7 $this->conf = array(
8 'path' => 'admin/stats',
9 );
10 parent::__construct( User_model::LEVEL_ADMIN );
11 }
12
13 function staff( $id, $display = 'week' )
14 {
15 $um = new User_Model;
16 $um->get_by_id( $id );
17 if( ! $um->exists() )
18 return;
19
20 $this->data['object'] = $um;
21
22 $um->shift->where( 'status', SHIFT_MODEL::STATUS_ACTIVE );
23
24 /* find min and max date */
25 $max_date = $um->shift->select_max('date')->get()->date;
26 $min_date = $um->shift->select_min('date')->get()->date;
27
28 $shifts = $um->shift
29 ->get_iterated();
30
31 /* compile dates */
32 $dates = array();
33
34 $date = $min_date;
35
36 $this->hc_time->setDateDb( $date );
37 switch( $display )
38 {
39 case 'week':
40 $this->hc_time->setStartWeek();
41 break;
42 case 'month':
43 $this->hc_time->setStartMonth();
44 break;
45 }
46 $date = $this->hc_time->formatDate_Db();
47
48 while( $date <= $max_date )
49 {
50 switch( $display )
51 {
52 case 'week':
53 $start = $this->hc_time->formatDate_Db();
54 $this->hc_time->setEndWeek();
55 $end = $this->hc_time->formatDate_Db();
56 break;
57 case 'month':
58 $start = $this->hc_time->formatDate_Db();
59 $this->hc_time->setEndMonth();
60 $end = $this->hc_time->formatDate_Db();
61 break;
62 }
63
64 $dates[ $start . '-'. $end ] = array(
65 'shift_count' => 0,
66 'shift_duration' => 0,
67 'timeoff_count' => 0,
68 'timeoff_duration' => 0,
69 );
70
71 $this->hc_time->modify( '+1 day' );
72 $date = $this->hc_time->formatDate_Db();
73 }
74
75 foreach( $shifts as $sh )
76 {
77 reset( $dates );
78 foreach( array_keys($dates) as $dk )
79 {
80 list( $start, $end ) = explode( '-', $dk );
81 if(
82 ($sh->date >= $start) &&
83 ($sh->date <= $end)
84 )
85 {
86 $dates[$dk]['shift_count']++;
87 $dates[$dk]['shift_duration'] += $sh->get_duration();
88 }
89 }
90 }
91
92 $this->data['dates'] = $dates;
93 $this->data['display'] = $display;
94
95 // $this->conf['path'] = 'admin/users';
96 $this->set_include( 'edit/stats', 'admin/users' );
97 $this->load->view( $this->template, $this->data);
98 }
99 }