PluginProbe
ShiftController Employee Shift Scheduling / 2.1.0
ShiftController Employee Shift Scheduling v2.1.0
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 / models / schedule_model.php

schedule_model.php in ShiftController Employee Shift Scheduling 2.1.0, at application/models/schedule_model.php

79 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 class Schedule_model extends MY_Model_Virtual
3 {
4 var $start;
5 var $end;
6 var $staff_id;
7
8 function shifts()
9 {
10 if( $this->staff_id )
11 {
12 $um = new User_Model;
13 $um->get_by_id( $this->staff_id );
14 $sm = $um->shift;
15 }
16 elseif( $this->location_id )
17 {
18 $lm = new Location_Model;
19 $lm->get_by_id( $this->location_id );
20 $sm = $lm->shift;
21 }
22 else
23 {
24 $sm = new Shift_Model;
25 }
26
27 if( $this->start )
28 $sm->where( 'date >=', $this->start );
29 if( $this->end )
30 $sm->where( 'date <=', $this->end );
31
32 $sm
33 ->order_by( 'date', 'ASC' )
34 ->order_by( 'start', 'ASC' )
35 ->include_related( 'user', 'id' )
36 ->where( 'user_id IS NOT ', 'NULL', FALSE );
37
38 return $sm->get();
39 }
40
41 function unpublish()
42 {
43 $count = 0;
44 foreach( $this->shifts() as $sh )
45 {
46 if( $sh->status == SHIFT_MODEL::STATUS_DRAFT )
47 continue;
48 if( $sh->unpublish() )
49 {
50 $count++;
51 }
52 else
53 {
54 $error = $this->{$this->model}->error->string;
55 }
56 }
57 return $count;
58 }
59
60 function publish()
61 {
62 $count = 0;
63 foreach( $this->shifts() as $sh )
64 {
65 if( $sh->status == SHIFT_MODEL::STATUS_ACTIVE )
66 continue;
67 if( $sh->publish() )
68 {
69 $count++;
70 }
71 else
72 {
73 $error = $this->{$this->model}->error->string;
74 }
75 }
76 return $count;
77 }
78 }
79