public function actionCreateEvent() { $transaction = Yii::app()->db->beginTransaction(); try { $dU = new DateTimeHelper(); $e = new Event(); $e->title = $_POST['title']; $e->body = $_POST['body']; $dt = $dU->getDateTimeFromUI($_POST['end']); $e->end = $dt->getTimestamp(); $dt = $dU->getDateTimeFromUI($_POST['start']); $e->start = $dt->getTimestamp(); $e->user_id = Yii::app()->user->id; if (!$e->save()) { $transaction->commit(); Response::ok(CJSON::encode(array("result" => "error", "message" => CJSON::encode($e->getErrors())))); } else { Response::ok(CJSON::encode(array("result" => "success", "message" => $e->id))); } } catch (Exception $exc) { $transaction->rollback(); Yii::log($exc->getMessage(), DBLog::LOG_LEVEL_ERROR); Response::error(CJSON::encode(array("result" => "error", "message" => Yii::app()->params["httpErrorCode500Message"]))); } }
/** * Retrieves a list of models based on the current search/filter conditions. * * Typical usecase: * - Initialize the model fields with values from filter form. * - Execute this method to get CActiveDataProvider instance which will filter * models according to data in model fields. * - Pass data provider to CGridView, CListView or any similar widget. * * @return CActiveDataProvider the data provider that can return the models * based on the search/filter conditions. */ public function search() { // @todo Please modify the following code to remove attributes that should not be searched. $criteria = new CDbCriteria(); if (isset($_GET["Audit"])) { $dH = new DateTimeHelper(); $dtFrom = $dH->getDateTimeFromUI($_GET["Audit"]["dateTimeFrom"]); $dtTo = $dH->getDateTimeFromUI($_GET["Audit"]["dateTimeTo"]); if ($desde !== false) { $criteria->addCondition('date_time >= ' . $dtFrom->getTimestamp()); } else { $criteria->addCondition('date_time >= ' . $dH->getDefaultStartRangeFilter("")->getTimestamp()); } if ($hasta !== false) { $criteria->addCondition('date_time <= ' . $dtTo->getTimestamp()); } else { $criteria->addCondition('date_time <= ' . $dH->getDefaultEndRangeFilter("audit")->getTimestamp()); } } $criteria->compare('object', $this->object, true); $criteria->compare('operation', $this->operation, true); $criteria->compare('description', $this->description, true); $criteria->compare('user', $this->user, true); return new CActiveDataProvider($this, array('criteria' => $criteria)); }