Example #1
0
 /**
  * Обработка формы
  *
  * @param EventForm $form
  * @param sfWebRequest $request
  */
 protected function processForm(EventForm $form, sfWebRequest $request)
 {
     $form->bind($request->getParameter($form->getName()));
     if ($form->isValid()) {
         $event = $form->save();
         if ($request->isXmlHttpRequest()) {
             $event = EventTable::getInstance()->queryWithCount(null, 'e')->where('e.id = ?', $event->id)->fetchOne();
             return $this->renderPartial('event/show', array('event' => $event));
         } else {
             return $this->redirect('event_show', $event);
         }
     }
     return sfView::SUCCESS;
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = new EventForm('view', $id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['EventForm'])) {
         $model->attributes = $_POST['EventForm'];
         $model->postItem->attributes = $_POST['PostItem'];
         $model->event->attributes = $_POST['Event'];
         if ($model->validate() && $model->save()) {
             $this->redirect(array('view', 'id' => $model->event->post_item_id));
         }
     }
     $this->render('update', array('model' => $model));
 }
 public function configure()
 {
     parent::configure();
     $this->widgetSchema['title'] = new sfWidgetFormTextarea();
     unset($this['id'], $this['geo_lat'], $this['geo_lng'], $this['place_id']);
     $this->useFields(array('title', 'description', 'fire_at'));
     $this->disableLocalCSRFProtection();
 }
 public function EventForm()
 {
     $this->commonScripts();
     Requirements::css('events/css/event.registration.form.css');
     Requirements::javascript("events/js/event.registration.form.js");
     $data = Session::get("FormInfo.Form_EventForm.data");
     $form = new EventForm($this->owner, 'EventForm', false);
     // we should also load the data stored in the session. if failed
     if (is_array($data)) {
         $form->loadDataFrom($data);
     }
     // Optional spam protection
     if (class_exists('SpamProtectorManager')) {
         SpamProtectorManager::update_form($form);
     }
     return $form;
 }
 /** Edit an event
  */
 public function editAction()
 {
     $form = new EventForm();
     $form->details->setLegend('Edit event');
     $form->submit->setLabel('Save event');
     $this->view->form = $form;
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         if ($form->isValid($formData)) {
             $address = $form->getValue('eventLocation');
             $coords = $this->_geocoder->getCoordinates($address);
             if ($coords) {
                 $lat = $coords['lat'];
                 $long = $coords['lon'];
                 $pm = new Pas_Service_Geoplanet();
                 $place = $pm->reverseGeoCode($lat, $lon);
                 $woeid = $place['woeid'];
             } else {
                 $lat = NULL;
                 $lon = NULL;
                 $woeid = NULL;
             }
             $insertdata = array('eventTitle' => $form->getValue('eventTitle'), 'eventDescription' => $form->getValue('eventDescription'), 'eventLocation' => $form->getValue('eventLocation'), 'organisation' => $form->getValue('organisation'), 'eventStartTime' => $form->getValue('eventStartTime'), 'eventEndTime' => $form->getValue('eventEndTime'), 'eventStartDate' => $form->getValue('eventStartDate'), 'eventEndDate' => $form->getValue('eventEndDate'), 'eventRegion' => $form->getValue('eventRegion'), 'eventType' => $form->getValue('eventType'), 'latitude' => $lat, 'longitude' => $long, 'adultsAttend' => $form->getValue('adultsAttend'), 'childrenAttend' => $form->getValue('childrenAttend'), 'updated' => $this->getTimeForForms(), 'updatedBy' => $this->getIdentityForForms());
             foreach ($insertdata as $key => $value) {
                 if (is_null($value) || $value == "") {
                     unset($insertdata[$key]);
                 }
             }
             $events = new Events();
             $where = array();
             $where[] = $events->getAdapter()->quoteInto('id = ?', $this->_getParam('id'));
             $events->update($insertdata, $where);
             $this->_flashMessenger->addMessage('You updated: <em>' . $form->getValue('eventTitle') . '</em> successfully.');
             $this->_redirect('/admin/events/');
         } else {
             $form->populate($formData);
         }
     } else {
         $id = (int) $this->_getParam('id', 0);
         if ($id > 0) {
             $events = new Events();
             $event = $events->fetchRow('id=' . (int) $id);
             $form->populate($event->toArray());
         }
     }
 }
 /**
  * Обновление записи
  *
  * @param array $values
  */
 protected function doUpdateObject($values)
 {
     // координаты объекта
     if ($values['gmap']) {
         $coords = explode(',', $values['gmap'], 2);
         if (count($coords) == 2) {
             $values['geo_lat'] = $coords[0];
             $values['geo_lng'] = $coords[1];
         }
     }
     parent::doUpdateObject($values);
 }
 /** Edit an event
  * @access public
  * @return void
  * @todo Add geocoding in model
  */
 public function editAction()
 {
     $form = new EventForm();
     $form->details->setLegend('Edit event');
     $form->submit->setLabel('Save event');
     $this->view->form = $form;
     if ($this->_request->isPost()) {
         if ($form->isValid($this->_request->getPost())) {
             $where = array();
             $where[] = $this->_events->getAdapter()->quoteInto('id = ?', $this->getParam('id'));
             $this->_events->update($form->getValues(), $where);
             $this->getFlash()->addMessage('You updated this events successfully.');
             $this->redirect('/admin/events/');
         } else {
             $form->populate($this->_request->getPost());
         }
     } else {
         $form->populate($this->_events->fetchRow('id=' . $this->getParam('id'))->toArray());
     }
 }
Example #8
0
 /**
  * Show the event form
  *
  * @return void
  */
 function showContent()
 {
     if (!empty($this->error)) {
         $this->element('p', 'error', $this->error);
     }
     $form = new EventForm($this);
     $form->show();
     return;
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return EventForm the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = EventForm::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 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;
 }
 /**
  * Запускаем отрисовку виджета
  *
  * @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));
     }
 }