# shiftcontroller/2.1.0/application/controllers/admin/stats.php

ShiftController Employee Shift Scheduling, version 2.1.0. 99 lines.

- Page: https://pluginprobe.com/plugins/shiftcontroller/2.1.0/code/application/controllers/admin/stats.php
- Raw: https://pluginprobe.com/plugins/shiftcontroller/2.1.0/raw/application/controllers/admin/stats.php
- Modified: 2013-11-19T19:08:10+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/shiftcontroller/2.1.0/code/application/controllers/admin/stats.php#L10-L20`.

```php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Stats_controller extends Backend_controller
{
	function __construct()
	{
		$this->conf = array(
			'path'		=> 'admin/stats',
			);
		parent::__construct( User_model::LEVEL_ADMIN );
	}

	function staff( $id, $display = 'week' )
	{
		$um = new User_Model;
		$um->get_by_id( $id );
		if( ! $um->exists() )
			return;

		$this->data['object'] = $um;

		$um->shift->where( 'status', SHIFT_MODEL::STATUS_ACTIVE );

	/* find min and max date */
		$max_date = $um->shift->select_max('date')->get()->date;
		$min_date = $um->shift->select_min('date')->get()->date;

		$shifts = $um->shift
			->get_iterated();

	/* compile dates */
		$dates = array();

		$date = $min_date;

		$this->hc_time->setDateDb( $date );
		switch( $display )
		{
			case 'week':
				$this->hc_time->setStartWeek();
				break;
			case 'month':
				$this->hc_time->setStartMonth();
				break;
		}
		$date = $this->hc_time->formatDate_Db();

		while( $date <= $max_date )
		{
			switch( $display )
			{
				case 'week':
					$start = $this->hc_time->formatDate_Db();
					$this->hc_time->setEndWeek();
					$end = $this->hc_time->formatDate_Db();
					break;
				case 'month':
					$start = $this->hc_time->formatDate_Db();
					$this->hc_time->setEndMonth();
					$end = $this->hc_time->formatDate_Db();
					break;
			}

			$dates[ $start . '-'. $end ] = array(
				'shift_count'		=> 0,
				'shift_duration'	=> 0,
				'timeoff_count'		=> 0,
				'timeoff_duration'	=> 0,
				);

			$this->hc_time->modify( '+1 day' );
			$date = $this->hc_time->formatDate_Db();
		}

		foreach( $shifts as $sh )
		{
			reset( $dates );
			foreach( array_keys($dates) as $dk )
			{
				list( $start, $end ) = explode( '-', $dk );
				if( 
					($sh->date >= $start) && 
					($sh->date <= $end)
					)
				{
					$dates[$dk]['shift_count']++;
					$dates[$dk]['shift_duration'] += $sh->get_duration();
				}
			}
		}

		$this->data['dates'] = $dates;
		$this->data['display'] = $display;

//		$this->conf['path'] = 'admin/users';
		$this->set_include( 'edit/stats', 'admin/users' );
		$this->load->view( $this->template, $this->data);
	}
}
```
