/** * create project * @param array $settings * @return boolean */ public function createProject($settings) { //currently only for persons create project if ($this->model != 'd2person.PprsPerson') { return false; } //validate user roles with setting roles if (isset($settings['user_roles'])) { $user_roles = Authassignment::model()->getUserRoles(Yii::app()->user->id); $a = array_intersect($user_roles, $settings['user_roles']); if (empty($a)) { return false; } } $model = PprsPerson::model()->findByPk($this->model_id); //create project $ttsk = new TtskTask(); $ttsk->ttsk_pprs_id = $this->model_id; $ttsk->ttsk_name = 'New attachment to ' . $model->itemLabel; $ttsk->ttsk_description = ''; $ttsk->ttsk_tstt_id = $settings['new_project_status']; //not started try { if (!$ttsk->save()) { return false; } } catch (Exception $e) { return false; } //create task $tcmn = new TcmnCommunication(); $tcmn->tcmn_ttsk_id = $ttsk->ttsk_id; $tcmn->tcmn_task = 'Validate attachment:' . PHP_EOL; $tcmn->tcmn_task .= $this->file_name . ' ' . $this->add_datetime; $tcmn->tcmn_tcst_id = $settings['task_init_status']; $tcmn->tcmn_datetime = new CDbExpression('ADDDATE(NOW(),' . $settings['task_due_in_days'] . ' )'); try { if (!$tcmn->save()) { return false; } } catch (Exception $e) { return false; } return true; }
public function actionCreate() { $ajax = Yii::app()->request->getParam('ajax'); $model = new TcmnCommunication('form_scenario'); //$model->scenario = $this->scenario; $this->performAjaxValidation($model, 'tcmn-communication-form'); if (isset($_POST['TcmnCommunication'])) { $model->attributes = $_POST['TcmnCommunication']; try { if ($model->save()) { if ($ajax) { //echo 'saved'; Yii::app()->end(); } if (isset($_GET['returnUrl'])) { $this->redirect($_GET['returnUrl']); } else { $this->redirect(array('view', 'tcmn_id' => $model->tcmn_id)); } } } catch (Exception $e) { $model->addError('tcmn_id', $e->getMessage()); } } elseif (isset($_GET['TcmnCommunication'])) { $model->attributes = $_GET['TcmnCommunication']; } if ($ajax) { $ttsk_id = Yii::app()->request->getPost('tcmn_ttsk_id'); if (!empty($ttsk_id)) { $model->tcmn_ttsk_id = Yii::app()->request->getPost('tcmn_ttsk_id'); } $ttsk_model = TtskTask::model()->findByPk($model->tcmn_ttsk_id); $cs = Yii::app()->clientScript; $cs->reset(); $cs->scriptMap = array('jquery.js' => false, 'jquery.min.js' => false); echo $this->renderPartial('_form', array('model' => $model, 'ttsk_model' => $ttsk_model), true, true); } else { $this->render('_form', array('model' => $model)); } }
public function loadModel($id) { $m = TtskTask::model(); // apply scope, if available $scopes = $m->scopes(); if (isset($scopes[$this->scope])) { $m->{$this->scope}(); } $model = $m->findByPk($id); if ($model === null) { throw new CHttpException(404, Yii::t('D2tasksModule.crud', 'The requested page does not exist.')); } return $model; }