Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
75.00% |
3 / 4 |
CRAP | |
96.77% |
30 / 31 |
| MeetingTimeAvailability | |
0.00% |
0 / 1 |
|
75.00% |
3 / 4 |
12 | |
96.77% |
30 / 31 |
| getMatrix | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| createMatrix | |
100.00% |
1 / 1 |
3 | |
100.00% |
15 / 15 |
|||
| unsetWhenMeeting | |
100.00% |
1 / 1 |
4 | |
100.00% |
7 / 7 |
|||
| substractBusyTableStats | |
0.00% |
0 / 1 |
4.03 | |
87.50% |
7 / 8 |
|||
| <?php | |
| namespace frontend\models; | |
| use Yii; | |
| use common\models\EventSpan; | |
| use yii\base\Model; | |
| /** | |
| * Meeting time availability model | |
| */ | |
| class MeetingTimeAvailability extends Model | |
| { | |
| private $matrix; | |
| public function getMatrix() | |
| { | |
| return $this->matrix; | |
| } | |
| /** | |
| * Make meeting up. | |
| * | |
| * @return Meeting|null the saved model or null if saving fails | |
| */ | |
| public function createMatrix($eventSpans, $specialTablesCount = 0) | |
| { | |
| $this->matrix = []; | |
| // Prepare matrix | |
| foreach ($eventSpans as $eventSpan) { | |
| $esId = $eventSpan->id; | |
| $tablesQuantity = $eventSpan->tables_quantity + $specialTablesCount; | |
| $meetingTime = new \DateTime($eventSpan->time_from, new \DateTimeZone(Yii::$app->formatter->timeZone)); | |
| $meetingTime->setDate(1970, 1, 1); | |
| $interval = intval($eventSpan->time_interval) * EventSpan::TIME_INTERVAL_UNIT; | |
| $meetingInterval = new \DateInterval('PT' . $interval . 'S'); | |
| for ($estOn = 0; $estOn < $eventSpan->time_quantity; $estOn++) { | |
| $this->matrix[$esId][$estOn] = [ | |
| 'key' => $esId.':'.$estOn, | |
| 'label' => Yii::$app->formatter->asTime($meetingTime), | |
| 'tables' => $tablesQuantity, | |
| ]; | |
| $meetingTime->add($meetingInterval); | |
| } | |
| } | |
| return $this->matrix; | |
| } | |
| public function unsetWhenMeeting($meetings) | |
| { | |
| // Test if I & partner have free time | |
| if(!empty($meetings)){ | |
| foreach($meetings as $meeting){ | |
| $esId = $meeting->event_span_id; | |
| $estOn = $meeting->event_span_time_on; | |
| if(isset($this->matrix[$esId][$estOn])){ | |
| unset($this->matrix[$esId][$estOn]); | |
| } | |
| } | |
| } | |
| } | |
| public function substractBusyTableStats($busyTableStats) | |
| { | |
| // Compute common free tables for times | |
| foreach($busyTableStats as $busyTimeTable){ | |
| $esId = $busyTimeTable['event_span_id']; | |
| $estOn = $busyTimeTable['event_span_time_on']; | |
| if(isset($this->matrix[$esId][$estOn])){ | |
| $this->matrix[$esId][$estOn]['tables'] -= intval($busyTimeTable['busy_tables_quantity']); | |
| if($this->matrix[$esId][$estOn]['tables'] < 0){ | |
| unset($this->matrix[$esId][$estOn]); | |
| } | |
| } | |
| } | |
| } | |
| } |