Esempio n. 1
0
 /**
  * This function performs the validation work for complex object models.
  *
  * In addition to checking the current object, all related objects will
  * also be validated.  If all pass then <code>true</code> is returned; otherwise
  * an aggreagated array of ValidationFailed objects will be returned.
  *
  * @param      array $columns Array of column names to validate.
  * @return     mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
  */
 protected function doValidate($columns = null)
 {
     if (!$this->alreadyInValidation) {
         $this->alreadyInValidation = true;
         $retval = null;
         $failureMap = array();
         // We call the validate method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aEvent !== null) {
             if (!$this->aEvent->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aEvent->getValidationFailures());
             }
         }
         if ($this->aWing !== null) {
             if (!$this->aWing->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aWing->getValidationFailures());
             }
         }
         if (($retval = EventWingsPeer::doValidate($this, $columns)) !== true) {
             $failureMap = array_merge($failureMap, $retval);
         }
         $this->alreadyInValidation = false;
     }
     return !empty($failureMap) ? $failureMap : true;
 }
Esempio n. 2
0
 protected function createOrUpdate(Event $model)
 {
     if (isset($_POST['Event'])) {
         $model->scenario = 'backend';
         $model->attributes = $_POST['Event'];
         $categories = EventCategory::model()->findAllByPk($_POST['Event']['categories']);
         $links = array();
         if (!$model->isNewRecord) {
             EventLink::model()->deleteAllByAttributes(array('eventId' => $model->id));
         }
         if (isset($_POST['EventLink'])) {
             foreach ($_POST['EventLink'] as $i => $info) {
                 $link = new EventLink();
                 $link->attributes = $info;
                 if (strlen($link->url) > 0) {
                     $links[] = $link;
                 }
             }
         }
         $model->categories = $categories;
         $model->links = $links;
         $model->validate();
         if ($model->save()) {
             if ($pictureSmall = CUploadedFile::getInstance($model, 'pictureSmall')) {
                 $model->pictureSmall = $pictureSmall;
             }
             if ($pictureBig = CUploadedFile::getInstance($model, 'pictureBig')) {
                 $model->pictureBig = $pictureBig;
             }
             $model->setTags($_POST['Event']['tagsString'])->save();
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
 }
Esempio n. 3
0
 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));
 }
Esempio n. 4
0
 function create($aData)
 {
     if (!isset($aData['EVN_UID']) || $aData['EVN_UID'] == '') {
         $aData['EVN_UID'] = G::generateUniqueID();
     }
     $oConnection = Propel::getConnection(EventPeer::DATABASE_NAME);
     try {
         $oEvent = new Event();
         $oEvent->setEvnUid($aData['EVN_UID']);
         $oEvent->setProUid($aData['PRO_UID']);
         if (isset($aData['EVN_RELATED_TO'])) {
             $oEvent->setEvnRelatedTo($aData['EVN_RELATED_TO']);
             if ($aData['EVN_RELATED_TO'] == 'SINGLE') {
                 if (isset($aData['TAS_UID'])) {
                     $oEvent->setTasUid($aData['TAS_UID']);
                 }
                 $oEvent->setEvnTasUidTo('');
                 $oEvent->setEvnTasUidFrom('');
             } else {
                 $oEvent->setTasUid('');
                 if (isset($aData['EVN_TAS_UID_TO'])) {
                     $oEvent->setEvnTasUidTo($aData['EVN_TAS_UID_TO']);
                 }
                 if (isset($aData['EVN_TAS_UID_FROM'])) {
                     $oEvent->setEvnTasUidFrom($aData['EVN_TAS_UID_FROM']);
                 }
             }
         }
         if (isset($aData['EVN_POSX'])) {
             $oEvent->setEvnPosx($aData['EVN_POSX']);
         }
         if (isset($aData['EVN_POSY'])) {
             $oEvent->setEvnPosy($aData['EVN_POSY']);
         }
         if (isset($aData['EVN_TYPE'])) {
             $oEvent->setEvnType($aData['EVN_TYPE']);
         }
         if (isset($aData['EVN_TAS_ESTIMATED_DURATION'])) {
             $oEvent->setEvnTasEstimatedDuration($aData['EVN_TAS_ESTIMATED_DURATION']);
         }
         if (isset($aData['EVN_WHEN_OCCURS'])) {
             $oEvent->setEvnWhenOccurs($aData['EVN_WHEN_OCCURS']);
         }
         if (isset($aData['EVN_ACTION'])) {
             $oEvent->setEvnAction($aData['EVN_ACTION']);
         }
         if (isset($aData['EVN_CONDITIONS'])) {
             $oEvent->setEvnConditions($aData['EVN_CONDITIONS']);
         }
         if (isset($aData['EVN_STATUS'])) {
             $oEvent->setEvnStatus($aData['EVN_STATUS']);
         }
         if (isset($aData['EVN_WHEN'])) {
             $oEvent->setEvnWhen($aData['EVN_WHEN']);
         }
         $oEvent->setEvnMaxAttempts(3);
         //start the transaction
         $oConnection->begin();
         if (isset($aData['EVN_TYPE'])) {
             if ($aData['EVN_TYPE'] === 'bpmnEventEmptyEnd') {
                 unset($aData['TRI_UID']);
             }
         }
         if (isset($aData['TRI_UID'])) {
             $oTrigger = new Triggers();
             if (trim($aData['TRI_UID']) === "" || !$oTrigger->TriggerExists($aData['TRI_UID'])) {
                 //create an empty trigger
                 $aTrigger = array();
                 $aTrigger['PRO_UID'] = $aData['PRO_UID'];
                 $aTrigger['TRI_TITLE'] = 'For event: ' . $aData['EVN_DESCRIPTION'];
                 $aTrigger['TRI_DESCRIPTION'] = 'Autogenerated ' . $aTrigger['TRI_TITLE'];
                 $aTrigger['TRI_WEBBOT'] = '// ' . $aTrigger['TRI_DESCRIPTION'];
                 $oTrigger->create($aTrigger);
             } else {
                 $oTrigger = TriggersPeer::retrieveByPk($aData['TRI_UID']);
             }
             $oEvent->setTriUid($oTrigger->getTriUid());
             $parameters = new StdClass();
             $parameters->hash = md5($oTrigger->getTriWebbot());
             if (isset($aData['EVN_ACTION_PARAMETERS']->SUBJECT)) {
                 $parameters->SUBJECT = $aData['EVN_ACTION_PARAMETERS']->SUBJECT;
                 $parameters->TO = $aData['EVN_ACTION_PARAMETERS']->TO;
                 $parameters->CC = $aData['EVN_ACTION_PARAMETERS']->CC;
                 $parameters->BCC = $aData['EVN_ACTION_PARAMETERS']->BCC;
                 $parameters->TEMPLATE = $aData['EVN_ACTION_PARAMETERS']->TEMPLATE;
             }
             $oEvent->setEvnActionParameters(serialize($parameters));
         }
         if ($oEvent->validate()) {
             $iResult = $oEvent->save();
             if (isset($aData['EVN_DESCRIPTION'])) {
                 $oEvent->setEvnDescription($aData['EVN_DESCRIPTION']);
             }
             $oConnection->commit();
             return $aData['EVN_UID'];
         } else {
             $sMessage = '';
             $aValidationFailures = $oEvent->getValidationFailures();
             foreach ($aValidationFailures as $oValidationFailure) {
                 $sMessage .= $oValidationFailure->getMessage() . '<br />';
             }
             throw new Exception('The row Event cannot be created!<br />' . $sMessage);
         }
     } catch (Exception $oError) {
         $oConnection->rollback();
         throw $oError;
     }
 }
 public function actionIndex()
 {
     $personForm = new PersonForm();
     $eventForm = new EventForm();
     $person = null;
     $event = null;
     $tplData = array('personForm' => $personForm, 'eventForm' => $eventForm);
     if (($personFormData = Yii::app()->getRequest()->getPost('PersonForm')) !== null) {
         $personForm->setAttributes($personFormData);
         //var_dump($personForm);
         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($person->validate())
                             {
                $calculator = new Calculator($person);
                // Запуск расчета
                $calculator->run();
                
                $this->calculator = $calculator;
                //var_dump($calculator->chart);
                //$tplData['calculator'] = $calculator; 
                             }
                             else
                             {
                $personForm->addErrors($person->getErrors());
                             }
             * 
             */
         }
     }
     if (($eventFormData = Yii::app()->getRequest()->getPost('EventForm')) !== null) {
         $eventForm->setAttributes($eventFormData);
         if ($eventForm->date != '' || $eventForm->city_id != '' || $eventForm->hour != '' || $eventForm->minute != '') {
             //var_dump($personForm);
             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();
         $this->calculator = $calculator;
         //var_dump($calculator->chart);
         //$tplData['calculator'] = $calculator;
     } else {
         if ($person !== null) {
             $personForm->addErrors($person->getErrors());
         }
         if ($event !== null) {
             $eventForm->addErrors($event->getErrors());
         }
     }
     // Вывод в шаблон
     $this->render('index', $tplData);
 }
Esempio n. 6
0
 public function actionValidate()
 {
     $this->layout = "test";
     $e = new Event();
     $e->validate("eventFormRDF");
 }
Esempio n. 7
0
 /**
  * Запускаем отрисовку виджета
  *
  * @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));
     }
 }
 }
 if (isset($_POST["max_attendance"])) {
     $max_attendance = htmlspecialchars($_POST["max_attendance"]);
 }
 // set up event object
 $event = new Event();
 $event->setTitle($title);
 $event->setDate($date);
 $event->setStartTime($start_time);
 $event->setEndTime($end_time);
 $event->setLocation($location);
 $event->setDescription($description);
 $event->setMaxAttendance($max_attendance);
 $event->setCreatorUserId($_SESSION['uid']);
 $failure_messages = array();
 if (!$event->validate()) {
     foreach ($event->getValidationFailures() as $failure) {
         $message = '<p><strong>Error in ' . $failure->getPropertyPath() . ' field!</strong> ' . $failure->getMessage() . '</p>';
         array_push($failure_messages, $message);
         // clear out the bad data
         $_POST[$failure->getPropertyPath()] = '';
     }
     unset($message);
 } else {
     // validate date fields
     //$now = new DateTime('now');
     $st = DateTime::createFromFormat("m/d/Y H:i A", $date . " " . $start_time);
     $et = DateTime::createFromFormat("m/d/Y H:i A", $date . " " . $end_time);
     /*
             if($now > $st) {
                 array_push($failure_messages, "<p><strong>Error:</strong> You cannot create an event that has already started</p>");