Пример #1
0
 public function __construct($config)
 {
     $this->device_id = $config['device_id'];
     $this->modelClass = Plan::className();
     array_shift($config);
     parent::__construct($config);
 }
Пример #2
0
 public function __construct($config)
 {
     $this->plan_id = $config['plan_id'];
     $this->modelClass = Day::className();
     array_shift($config);
     parent::__construct($config);
 }
Пример #3
0
 public function __construct($config)
 {
     $this->modelClass = Subject::className();
     parent::__construct($config);
 }
Пример #4
0
 /**
  * Saves model to database
  *
  * @param bool $insert
  */
 public function save($insert = true)
 {
     $this->device_id = $this->_plan->device_id;
     if (!($this->subject_id > 0)) {
         $this->saveSubject();
     }
     if ($insert) {
         $dayTimeValue = 86400;
         switch ($this->repetition) {
             case self::DAY_REPEAT:
                 $additionalTime = $dayTimeValue;
                 break;
             case self::WEEK_REPEAT:
                 $additionalTime = 7 * $dayTimeValue;
                 break;
             case self::TWO_WEEK_REPEAT:
                 $additionalTime = 14 * $dayTimeValue;
                 break;
             case self::THREE_WEEK_REPEAT:
                 $additionalTime = 21 * $dayTimeValue;
                 break;
             case self::FOUR_WEEK_REPEAT:
                 $additionalTime = 28 * $dayTimeValue;
                 break;
             default:
                 $this->repetition_end_date = $this->date;
                 $additionalTime = $dayTimeValue;
                 break;
         }
         /** @noinspection PhpUndefinedFieldInspection */
         for ($i = \Yii::$app->formatter->asTimestamp($this->date); $i <= \Yii::$app->formatter->asTimestamp($this->repetition_end_date); $i += $additionalTime) {
             if ($day = Day::find()->where(['plan_id' => $this->_plan->id, 'is_open' => 1, 'day_nr' => date('N', $i)])->one()) {
                 for ($j = $this->time_from; $j < $this->time_to; ++$j) {
                     $jTimestamp = Yii::$app->formatter->asTimestamp($this->getDayTimes()[$j]);
                     if ($jTimestamp >= Yii::$app->formatter->asTimestamp($day->time_from) && $jTimestamp <= Yii::$app->formatter->asTimestamp($day->time_to)) {
                         $this->date = Yii::$app->formatter->asDate($i, 'y-MM-dd');
                         $this->hour_nr = $j;
                         parent::save($insert);
                     }
                 }
             }
         }
     } else {
         parent::save($insert);
     }
 }