| 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 |
} |