public function beforeSave($event) { $tmp_event_id = 0; $is_change = false; $role = User::model()->getUserRole(); if (!$this->owner->isNewRecord && $role != 'Manager' && $role != 'Admin') { $tmp_event_id = time(); foreach ($this->old_attributes as $key => $value) { if ($key == 'max_exec_date') { $old_value = Yii::app()->dateFormatter->format($this->owner->dateTimeOutcomeFormat, strtotime($value)); $new_value = Yii::app()->dateFormatter->format($this->owner->dateTimeOutcomeFormat, strtotime($this->owner->max_exec_date)); if ($old_value === $new_value) { continue; } } else { $old_value = $value; $new_value = $this->owner->{$key}; } if ($old_value != $new_value) { $is_change = true; $moderate = new Moderate(); $moderate->event_id = $tmp_event_id; $moderate->class_name = get_class($this->owner); $moderate->id_record = $this->owner->primaryKey; $moderate->attribute = $key; $moderate->old_value = $old_value; $moderate->new_value = $new_value; $moderate->save(false); } } if ($is_change) { Yii::import('application.modules.project.components.EventHelper'); switch (get_class($this->owner)) { case 'Profile': $event_id = EventHelper::updateProfile(); break; case 'Zakaz': $event_id = EventHelper::editOrder($this->owner->primaryKey); break; } Moderate::model()->updateAll(['event_id' => $event_id], 'event_id=:event_id', [':event_id' => $tmp_event_id]); } $this->owner->attributes = $this->old_attributes; } }
public function beforeSave($event) { $tmp_event_id = 0; $is_change = false; $role = User::model()->getUserRole(); if (!$this->owner->isNewRecord && $role != 'Manager' && $role != 'Admin') { $tmp_event_id = time(); foreach ($this->old_attributes as $key => $value) { if ($key == 'max_exec_date') { $old_value = Yii::app()->dateFormatter->format($this->owner->dateTimeOutcomeFormat, strtotime($value)); $new_value = Yii::app()->dateFormatter->format($this->owner->dateTimeOutcomeFormat, strtotime($this->owner->max_exec_date)); if ($old_value === $new_value) { continue; } } else { $old_value = $value; $new_value = $this->owner->{$key}; } if ($old_value != $new_value && !(User::model()->isCorrector() && $key == 'technicalspec') && $key != 'executor_event' && $key != 'customer_event') { $is_change = true; $moderate = new Moderate(); $moderate->event_id = $tmp_event_id; $moderate->class_name = get_class($this->owner); $moderate->id_record = $this->owner->primaryKey; $moderate->attribute = $key; $moderate->old_value = $old_value; $moderate->new_value = $new_value; $moderate->save(false); } } if ($is_change) { Yii::import('application.modules.project.components.EventHelper'); switch (get_class($this->owner)) { case 'Profile': $event_id = EventHelper::updateProfile(); break; case 'Zakaz': $event_id = EventHelper::editOrder($this->owner->primaryKey); break; } Moderate::model()->updateAll(['event_id' => $event_id], 'event_id=:event_id', [':event_id' => $tmp_event_id]); } if (User::model()->isCorrector() && $this->owner->attributes['technicalspec'] != $this->old_attributes['technicalspec']) { $this->old_attributes['technicalspec'] = $this->owner->attributes['technicalspec']; } $this->old_attributes['executor_event'] = $this->owner->attributes['executor_event']; $this->old_attributes['customer_event'] = $this->owner->attributes['customer_event']; $this->owner->attributes = $this->old_attributes; } else { if (!$this->owner->isNewRecord && get_class($this->owner) == 'Zakaz') { $authorInformedUpdated = false; foreach ($this->old_attributes as $key => $value) { $old_value = $value; $new_value = $this->owner->{$key}; if ($old_value != $new_value && $key != 'executor_event' && $key != 'customer_event') { $is_change = true; } if ($old_value != $new_value && $key == 'author_informed') { $authorInformedUpdated = true; } } if ($authorInformedUpdated) { if ($this->owner->executor_event) { $events = explode(",", $this->owner->executor_event); if (!in_array(3, $events)) { $events[] = 3; $this->owner->executor_event = implode(",", $events); } } else { $this->owner->executor_event = 3; } } elseif ($is_change) { if ($this->owner->executor_event) { $events = explode(",", $this->owner->executor_event); if (!in_array(1, $events)) { $events[] = 1; $this->owner->executor_event = implode(",", $events); } } else { $this->owner->executor_event = 1; } } } } }
/** * 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) { if (Yii::app()->request->isAjaxRequest) { $data = Yii::app()->request->getRestParams(); $field = str_replace('Zakaz_', '', $data['elid']); if (is_array($data)) { $model = $this->loadModel($data['id']); echo json_encode($model->{$field} = $data['data']); echo json_encode($model->save()); Yii::app()->end(); } $this->renderPartial('_order_list_update'); Yii::app()->end(); } $role = User::model()->getUserRole(); $view = 'update'; $isModified = false; Yii::app()->session['project_id'] = $id; $model = $this->loadModel($id); if (Yii::app()->request->getParam('close') == 'yes') { $model->old_status = $model->status; $model->status = 5; $model->save(false); $this->redirect(array('update', 'id' => $model->id)); } elseif (Yii::app()->request->getParam('open') == 'yes') { $model->status = $model->old_status; $model->save(false); $this->redirect(array('update', 'id' => $model->id)); } // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Zakaz'])) { $model->attributes = $_POST['Zakaz']; if (isset($_POST['Zakaz']['dbdate'])) { $model->dbdate = $_POST['Zakaz']['dbdate']; } if (Campaign::getId()) { $projectFields = $model->getFields(); if ($projectFields) { foreach ($projectFields as $field) { if ($field->field_type == "TIMESTAMP") { // ---------------------------------------------------- $tmp = $field->varname; if (isset($_POST['Zakaz'][$tmp])) { $model->{$tmp} = $_POST['Zakaz'][$tmp]; $model->timestampInput($field); } } } } } if ($model->save()) { if ($role != 'Manager' && $role != 'Admin') { EventHelper::editOrder($model->id); $view = 'orderInModerate'; } else { $this->redirect(array('update', 'id' => $model->id)); } } } $this->render($view, array('model' => $model, 'message' => $model->projectStatus->status, 'isModified' => $isModified)); }