# shiftcontroller/2.1.0/application/models/schedule_model.php

ShiftController Employee Shift Scheduling, version 2.1.0. 79 lines.

- Page: https://pluginprobe.com/plugins/shiftcontroller/2.1.0/code/application/models/schedule_model.php
- Raw: https://pluginprobe.com/plugins/shiftcontroller/2.1.0/raw/application/models/schedule_model.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/models/schedule_model.php#L10-L20`.

```php
<?php
class Schedule_model extends MY_Model_Virtual
{
	var $start;
	var $end;
	var $staff_id;

	function shifts()
	{
		if( $this->staff_id )
		{
			$um = new User_Model;
			$um->get_by_id( $this->staff_id );
			$sm = $um->shift;
		}
		elseif( $this->location_id )
		{
			$lm = new Location_Model;
			$lm->get_by_id( $this->location_id );
			$sm = $lm->shift;
		}
		else
		{
			$sm = new Shift_Model;
		}

		if( $this->start )
			$sm->where( 'date >=', $this->start );
		if( $this->end )
			$sm->where( 'date <=', $this->end );

		$sm
			->order_by( 'date', 'ASC' )
			->order_by( 'start', 'ASC' )
			->include_related( 'user', 'id' )
			->where( 'user_id IS NOT ', 'NULL', FALSE );

		return $sm->get();
	}

	function unpublish()
	{
		$count = 0;
		foreach( $this->shifts() as $sh )
		{
			if( $sh->status == SHIFT_MODEL::STATUS_DRAFT )
				continue;
			if( $sh->unpublish() )
			{
				$count++;
			}
			else
			{
				$error = $this->{$this->model}->error->string;
			}
		}
		return $count;
	}

	function publish()
	{
		$count = 0;
		foreach( $this->shifts() as $sh )
		{
			if( $sh->status == SHIFT_MODEL::STATUS_ACTIVE )
				continue;
			if( $sh->publish() )
			{
				$count++;
			}
			else
			{
				$error = $this->{$this->model}->error->string;
			}
		}
		return $count;
	}
}

```
