public function actionCreate() { $model = new Event(); $model->setAttributes($this->getJsonInput()); if (!$model->validate()) { $this->sendResponse(400, CHtml::errorSummary($model)); } else { if (!$model->save(false)) { throw new CException('Cannot create a record'); } } $model->refresh(); $this->sendResponse(200, CJSON::encode($model)); }
private function createCombineEvents() { // event from etopaz not linked $events = Event::model()->with(['team_home_convert', 'team_away_convert'])->findAll(['select' => 'date, team_home, team_away', 'condition' => 'event_id is null and src_type = ' . Event::SRCTYPE_ETOPAZ, 'group' => 'date, team_home, team_away']); foreach ($events as $event) { // find combine event $cattr = ['src_type' => Event::SRCTYPE_COMBINE, 'date' => $event->date, 'team_home' => $event->teamHomeConverted, 'team_away' => $event->teamAwayConverted]; $cevent = Event::model()->findByAttributes($cattr); /* @var $cevent Event */ // create if not exists if (!$cevent) { $cevent = new Event(); $cevent->setAttributes($cattr, false); $cevent->save(); } } }
public function actionCalculate($id, $code) { // Загрузка таблицы для блока $table = Table::model()->findByPK((int) $id); if ($table === null) { throw new CHttpException('404'); } // Устанавливаем источники данных $person = null; $event = null; $personForm = new PersonForm(); $eventForm = new EventForm(); $this->performAjaxValidation(array($personForm, $eventForm), $code); if ($table->source_destiny_table == Table::SOURCE_FROM_USER && ($personFormData = Yii::app()->getRequest()->getPost('PersonForm')) !== null) { $personForm->setAttributes($personFormData); if ($personForm->validate()) { $person = new Person(); $person->setAttributes(array('name' => $personForm->name, 'gender' => $personForm->gender, 'date' => $personForm->date, 'time' => $personForm->getTime(), 'city_id' => $personForm->city_id)); } } if ($table->source_event_table == Table::SOURCE_FROM_USER && ($eventFormData = Yii::app()->getRequest()->getPost('EventForm')) !== null) { $eventForm->setAttributes($eventFormData); if ($eventForm->date != '' || $eventForm->city_id != '' || $eventForm->hour != '' || $eventForm->minute != '') { if ($eventForm->validate()) { $event = new Event(); $event->setAttributes(array('date' => $eventForm->date, 'time' => $eventForm->getTime(), 'city_id' => $eventForm->city_id)); } } } if (Yii::app()->request->isAjaxRequest) { if ($personForm->hasErrors() || $eventForm->hasErrors()) { $personForm->addErrors($eventForm->getErrors()); Yii::app()->ajax->failure($personForm->getErrors()); } else { $arr = explode('-', $code); $blockId = key_exists(0, $arr) ? (int) $arr[0] : ''; $this->widget('application.modules.bazi.widgets.TableWidget', array('model_id' => $table->id, 'block_id' => $blockId, 'person' => $person, 'event' => $event)); } } return false; }
public function actionManage() { $model = new Event('search'); $model->unsetAttributes(); if (isset($_GET['Event'])) { $model->setAttributes($_GET['Event']); } $this->render('manage', array('model' => $model)); }
/** * Запускаем отрисовку виджета * * @return void */ public function run() { // Авторизован ли пользователь if (Yii::app()->user->isAuthenticated() === false) { return; } if (($user = Yii::app()->user->getProfile()) === null) { return; } // Загрузка таблицы для блока $table = Table::model()->with(array('descriptions'))->findByPK((int) $this->model_id); if ($table === null) { return; } // Устанавливаем источники данных $person = null; $event = null; $personForm = new PersonForm(); $eventForm = new EventForm(); $description = ''; if ($table->source_destiny_table == Table::SOURCE_USER) { $person = new Person(); $person->setAttributes(array('name' => $user->profile->name, 'gender' => $user->profile->gender, 'date' => $user->profile->birth_date, 'time' => $user->profile->birth_time, 'city_id' => $user->profile->city_id)); } elseif ($table->source_destiny_table == Table::SOURCE_ADMIN) { $person = $table->person; } elseif ($table->source_destiny_table == Table::SOURCE_FROM_USER && ($personFormData = Yii::app()->getRequest()->getPost('PersonForm')) !== null) { $personForm->setAttributes($personFormData); if ($personForm->validate()) { $person = new Person(); $person->setAttributes(array('name' => $personForm->name, 'gender' => $personForm->gender, 'date' => $personForm->date, 'time' => $personForm->getTime(), 'city_id' => $personForm->city_id)); } } if ($table->source_event_table == Table::SOURCE_USER) { $event = new Event(); $event->setAttributes(array('date' => date('Y-m-d'), 'time' => date('H:i'), 'city_id' => $user->profile->city_id)); } elseif ($table->source_event_table == Table::SOURCE_ADMIN) { $event = $table->event; } elseif ($table->source_event_table == Table::SOURCE_FROM_USER && ($eventFormData = Yii::app()->getRequest()->getPost('EventForm')) !== null) { $eventForm->setAttributes($eventFormData); if ($eventForm->date != '' || $eventForm->city_id != '' || $eventForm->hour != '' || $eventForm->minute != '') { if ($eventForm->validate()) { $event = new Event(); $event->setAttributes(array('date' => $eventForm->date, 'time' => $eventForm->getTime(), 'city_id' => $eventForm->city_id)); } } } if ($person !== null) { $validateResult = $person->validate(); $validateResult = $validateResult && ($event !== null ? $event->validate() : true); } if ($validateResult) { $calculator = new Calculator($person, $event); // Запуск расчета $calculator->run(); if ($table->active_luck_pillar > 0) { $calculator->numCurrentLuckColumn = (int) $table->active_luck_pillar; } // Определяем описание $description = $table->description; } else { if ($person !== null) { $personForm->addErrors($person->getErrors()); } if ($event !== null) { $eventForm->addErrors($event->getErrors()); } } if (Yii::app()->request->isAjaxRequest) { $this->controller->renderPartial('//bazi/widgets/TableWidget/_chart', array('model' => $table, 'calculator' => $calculator, 'description' => $description), false, true); } else { $this->render($this->view, array('model' => $table, 'calculator' => $calculator, 'description' => $description, 'personForm' => $personForm, 'eventForm' => $eventForm)); } }