PluginProbe
ShiftController Employee Shift Scheduling / 4.9.26
ShiftController Employee Shift Scheduling v4.9.26
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 / sh4 / schedule / html / widget / daygrid.php

daygrid.php in ShiftController Employee Shift Scheduling 4.9.26, at sh4/schedule/html/widget/daygrid.php

144 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if (! defined('ABSPATH')) exit; // Exit if accessed directly
2 interface SH4_Schedule_Html_Widget_IDayGrid
3 {
4 public function reset();
5 public function setRange( $timeMin, $timeMax );
6 public function add( $start, $end, $content );
7 public function render();
8 }
9
10 class SH4_Schedule_Html_Widget_DayGrid implements SH4_Schedule_Html_Widget_IDayGrid
11 {
12 protected $timeMin = 0;
13 protected $timeMax = 86400;
14 protected $slots = array();
15
16 public function __construct(
17 HC3_Hooks $hooks,
18 HC3_Time $t,
19 HC3_Ui $ui
20 )
21 {
22 $this->self = $hooks->wrap( $this );
23 $this->ui = $ui;
24 $this->t = $t;
25 }
26
27 public function reset()
28 {
29 $this->slots = array();
30 return $this;
31 }
32
33 public function setRange( $timeMin, $timeMax )
34 {
35 $this->timeMin = $this->t->setDateTimeDb( $timeMin )->getTimestamp();
36 $this->timeMax = $this->t->setDateTimeDb( $timeMax )->getTimestamp();
37 }
38
39 public function add( $start, $end, $content )
40 {
41 $slot = new stdClass();
42
43 $start = $this->t->setDateTimeDb( $start )->getTimestamp();
44 $end = $this->t->setDateTimeDb( $end )->getTimestamp();
45
46 if( ($end <= $this->timeMin) OR ($start >= $this->timeMax) ){
47 return;
48 }
49
50 if( $start < $this->timeMin ){
51 $start = $this->timeMin;
52 }
53
54 if( $end > $this->timeMax ){
55 $end = $this->timeMax;
56 }
57
58 $slot->start = $start;
59 $slot->end = $end;
60 $slot->content = $content;
61 $slot->offset = 0;
62
63 $this->slots[] = $slot;
64 }
65
66 public function render()
67 {
68 /* slots */
69 $thisLength = $this->timeMax - $this->timeMin;
70 $top = 0;
71
72 $slots = $this->slots;
73
74 /* split by rows */
75 $rows = array();
76 foreach( $slots as $slot ){
77 /* find suitable row */
78 $myRow = count($rows);
79 for( $ri = 0; $ri < count($rows); $ri++ ){
80 $failedRow = FALSE;
81 foreach( $rows[$ri] as $checkSlot ){
82 if(
83 ( $checkSlot->start < $slot->end ) &&
84 ( $checkSlot->end > $slot->start )
85 ){
86 $failedRow = TRUE;
87 }
88 if( $failedRow ){
89 break;
90 }
91 }
92 if( ! $failedRow ){
93 $myRow = $ri;
94 break;
95 }
96 }
97 if( ! isset($rows[$myRow]) ){
98 $rows[$myRow] = array();
99 }
100 $rows[$myRow][] = $slot;
101 }
102
103 /* add offset */
104 for( $ri = 0; $ri < count($rows); $ri++ ){
105 for( $si = 0; $si < count($rows[$ri]); $si++ ){
106 $checkWith = $si ? $rows[$ri][$si-1]->end : $this->timeMin;
107 $offset = $rows[$ri][$si]->start - $checkWith;
108 $rows[$ri][$si]->offset = $offset;
109 }
110 }
111
112 $out = array();
113 foreach( $rows as $row ){
114 $rowView = $this->ui->makeGrid()
115 ->gutter(0)
116 ;
117
118 foreach( $row as $slot ){
119 $left = floor( 100 * 100 * (($slot->start - $this->timeMin) / $thisLength ) ) / 100;
120
121 $slotDuration = $slot->end - $slot->start;
122 if( $slotDuration + $slot->start > $this->timeMax ){
123 $slotDuration = $this->timeMax - $slot->start;
124 }
125
126 $width = floor( 100 * 100 * ($slotDuration / $thisLength ) ) / 100;
127 $offset = floor( 100 * 100 * ($slot->offset / $thisLength ) ) / 100;
128
129 // echo "left = $left, width = $width, offset = $offset<br>";
130
131 $rowView
132 ->add( $slot->content, $width . '%', $width . '%', $offset . '%' )
133 ;
134 }
135
136 $out[] = $rowView;
137 }
138
139 $out = $this->ui->makeList( $out )
140 ->gutter(1)
141 ;
142 return $out;
143 }
144 }