private function _fixAllDayEvents()
 {
     foreach ($this->_getData() as $e) {
         $eeModel = EventEntry::findOne($e['event_entry_id']);
         $startDate = date('d-m-Y', $eeModel->start_timestamp);
         $dateArray = explode('-', $startDate);
         $endDate = date('d-m-Y', $eeModel->end_timestamp);
         $newStartTimestamp = mktime(7, 0, 0, $dateArray[1], $dateArray[0], $dateArray[2]);
         $newEndTimestamp = mktime(21, 0, 0, $dateArray[1], $dateArray[0], $dateArray[2]);
         $eeModel->start_timestamp = $newStartTimestamp;
         $eeModel->end_timestamp = $newEndTimestamp;
         //if (! $eeModel->save())
         //   print_r($eeModel->getErrors());
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = EventEntry::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'event_id' => $this->event_id, 'booking_status_id' => $this->booking_status_id, 'start_timestamp' => $this->start_timestamp, 'end_timestamp' => $this->end_timestamp, 'all_day_option_id' => $this->all_day_option_id, 'confirm_by' => $this->confirm_by, 'confirm_date' => $this->confirm_date, 'sort_order' => $this->sort_order, 'status_id' => $this->status_id, 'old_id' => $this->old_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
 public function actionCreateevent()
 {
     $request = \yii::$app->request;
     $bookingModel = new Booking();
     $eventModel = new Event();
     $eventEntryModel = new EventEntry();
     $validate = false;
     $bookingModel->load($request->post());
     if (yii::$app->CalendarComponent->canCreateEvents($bookingModel->calendar_id)) {
         $validate = true;
     } else {
         $bookingModel->addError('event_id', 'Cannot use this calendar. Double check the read only setting - ');
     }
     if ($validate && $bookingModel->validate()) {
         $eventModel->load(['Event' => $bookingModel->attributes]);
         if ($eventModel->validate()) {
             try {
                 $transaction = \yii::$app->db->beginTransaction();
                 $eventModel->save(false);
                 $eventEntryModel->load(['EventEntry' => $bookingModel->attributes]);
                 $eventEntryModel->event_id = $eventModel->primaryKey;
                 if ($eventEntryModel->validate()) {
                     $eventEntryModel->save(false);
                     yii::$app->AjaxResponse->error = false;
                 } else {
                     yii::$app->AjaxResponse->message = array_values($eventEntryModel->getErrors());
                 }
                 $transaction->commit();
                 yii::$app->AjaxResponse->message = $bookingModel->jsObject;
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         } else {
             yii::$app->AjaxResponse->message = array_values($eventModel->getErrors());
         }
     } else {
         yii::$app->AjaxResponse->message = array_values($bookingModel->getErrors());
     }
     yii::$app->AjaxResponse->sendContent();
 }
Example #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getEventEntries()
 {
     return $this->hasMany(EventEntry::className(), ['event_id' => 'id']);
 }
 /**
  * Finds the EventEntry model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return EventEntry the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = EventEntry::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }