/** * Add event task in database * @param $params * @return bool */ public static function addTask($params, $options = []) { $task = new Task(['scenario' => 'event']); $task->load(['Task' => $params]); $task->type = Task::TYPE_EVENT; $task->initiator = \Yii::$app->user->id; if (!empty($options)) { $task->setOptions($options); } return $task->validate() && $task->save(); }
/** * Creates a new Task model. * If creation is successful, the browser will be redirected to the 'index' page. * @return string|\yii\web\Response */ public function actionCreate() { $model = new Task(['scenario' => 'repeat']); $model->initiator = Yii::$app->user->id; $model->type = Task::TYPE_REPEAT; if ($model->load($_POST) && $model->save()) { Yii::$app->session->setFlash('success', Yii::t('app', 'Record has been saved')); $returnUrl = Yii::$app->request->get('returnUrl', ['background/manage/index']); switch (Yii::$app->request->post('action', 'save')) { case 'next': return $this->redirect(['/background/manage/create', 'returnUrl' => $returnUrl]); case 'back': return $this->redirect($returnUrl); default: return $this->redirect(Url::toRoute(['/background/manage/update', 'id' => $model->id, 'returnUrl' => $returnUrl])); } } else { return $this->render('create', ['model' => $model]); } }