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->aTaskRelatedByTaskId !== null) {
             if (!$this->aTaskRelatedByTaskId->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aTaskRelatedByTaskId->getValidationFailures());
             }
         }
         if ($this->aTaskRelatedByOverrideTaskId !== null) {
             if (!$this->aTaskRelatedByOverrideTaskId->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aTaskRelatedByOverrideTaskId->getValidationFailures());
             }
         }
         if ($this->aUser !== null) {
             if (!$this->aUser->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aUser->getValidationFailures());
             }
         }
         if (($retval = OverrideTaskPeer::doValidate($this, $columns)) !== true) {
             $failureMap = array_merge($failureMap, $retval);
         }
         $this->alreadyInValidation = false;
     }
     return !empty($failureMap) ? $failureMap : true;
 }
Esempio n. 2
0
 public static function store()
 {
     parent::check_logged_in();
     // POST-pyynnön muuttujat sijaitsevat $_POST nimisessä assosiaatiolistassa
     $params = $_POST;
     // Alustetaan uusi task-luokan olion käyttäjän syöttämillä arvoilla
     /*$task = new task(array(
       'name' => $params['name'],
       'description' => $params['description'],
       'publisher' => $params['publisher'],
       'published' => $params['published']
       ));*/
     $params['user_id'] = parent::get_user_logged_in()->id;
     $task = new Task($params);
     $errors = $task->validate();
     if (!$errors) {
         // Kutsutaan alustamamme olion save metodia, joka tallentaa olion tietokantaan
         $task->save();
         // Ohjataan käyttäjä lisäyksen jälkeen pelin esittelysivulle
         //Redirect::to('/task/' . $task->id, array('message' => 'Task has been added!'));
         Redirect::to('/task', array('message' => 'Task has been added!'));
     } else {
         View::make('task/new.html', array('errors' => $errors, 'attributes' => $params, 'title' => 'new task'));
     }
 }
Esempio n. 3
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $task = new Task();
     $task->unguard();
     $task->fill(Input::only(['name', 'user_id', 'description', 'status']));
     $task->deadline = new DateTime(Input::get('deadline'));
     if ($task->validate()) {
         $task->save();
     } else {
         return View::make('tasks.edit', ['task' => $task])->withErrors($task->validator());
     }
     return Redirect::to(route('tasks.index'))->with('message', ['content' => 'Taak met succes aangemaakt!', 'class' => 'success']);
 }
 public function actionIndex()
 {
     $models = array();
     if (!empty($_POST['Task'])) {
         foreach ($_POST['Task'] as $taskData) {
             $model = new Task();
             $model->setAttributes($taskData);
             if ($model->validate()) {
                 $models[] = $model;
             }
         }
     }
     if (!empty($models)) {
         // We've received some models and validated them.
         // If you want to save the data you can do it here.
     } else {
         $models[] = new Task();
     }
     $this->render('index', array('models' => $models));
 }
Esempio n. 5
0
 // Delete list by ID
 Route::delete('lists/{id}', function ($id) {
     $list = TaskList::findByOwnerAndId(Auth::user(), $id);
     $list->delete();
     return Response::make(null, 204);
 })->where('id', '\\d+');
 // Get tasks for list
 Route::get('lists/{id}/tasks', function ($id) {
     $list = TaskList::findByOwnerAndId(Auth::user(), $id);
     return Response::json($list->tasks->toArray());
 })->where('id', '\\d+');
 // Create task
 Route::post('lists/{id}/tasks', function ($id) {
     $list = TaskList::findByOwnerAndId(Auth::user(), $id);
     $task = new Task(Input::get());
     $task->validate();
     $task->list_id = $id;
     if (!$task->save()) {
         App::abort(500, 'Task was not saved');
     }
     return Response::json($task->toArray(), 201);
 })->where('id', '\\d+');
 // Get task by ID
 Route::get('lists/{list_id}/tasks/{id}', function ($list_id, $id) {
     $list = TaskList::findByOwnerAndId(Auth::user(), $list_id);
     $task = $list->tasks()->find($id);
     if (!$task) {
         App::abort(404);
     }
     return Response::json($task->toArray());
 })->where('list_id', '\\d+')->where('id', '\\d+');
Esempio n. 6
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'show' page.
  */
 public function actionCreate()
 {
     $model = new Task($this->action->id);
     if (isset($_POST['Task'])) {
         // collect user input data
         $model->attributes = $_POST['Task'];
         if (!isset($_POST['Task']['companyId'])) {
             // set company based on the project
             if ($model->projectId >= 1) {
                 $criteria = new CDbCriteria();
                 $criteria->order = "`t`.`companyPriority` ASC, `t`.`id` ASC";
                 if (($company2Project = Company2Project::model()->findByAttributes(array('projectId' => $model->projectId), $criteria)) !== null) {
                     $model->companyId = $company2Project->companyId;
                 } else {
                     $model->companyId = 0;
                 }
             } else {
                 $model->companyId = 0;
             }
         }
         if ($model->projectId >= 1) {
             // set project's hourly rate
             if (($project = Project::model()->findByPk($model->projectId)) !== null) {
                 $model->hourlyRate = $project->hourlyRate;
             }
         }
         // validate with the current action as scenario and save without validation
         if (($validated = $model->validate()) !== false && ($saved = $model->save(false)) !== false) {
             if (isset($_POST['User2Task'])) {
                 // assigned consultants
                 $model->allConsultant2Task = array(0 => new User2Task('create'));
                 $model->allConsultant2Task[0]->taskId = $model->id;
                 foreach ($model->allConsultant2Task as $user2Task) {
                     $user2Task->attributes = $_POST['User2Task'];
                     $user2Task->save();
                 }
             }
             if ($model->projectId >= 1) {
                 // new relation between task and manager
                 $criteria = new CDbCriteria();
                 $criteria->order = "`t`.`userPriority` ASC, `t`.`id` ASC";
                 if (($user2Project = User2Project::model()->findByAttributes(array('projectId' => $model->projectId, 'role' => User2Project::MANAGER), $criteria)) !== null) {
                     $user2Task = new User2Task('create');
                     $user2Task->userId = $user2Project->userId;
                     $user2Task->taskId = $model->id;
                     $user2Task->role = User2Task::MANAGER;
                     $user2Task->save();
                 }
             }
             // set success message
             MUserFlash::setTopSuccess(Yii::t('hint', 'The new "{title}" task record has been successfully created.', array('{title}' => MHtml::wrapInTag($model->title, 'strong'))));
             // go to the 'show' page
             $this->redirect(array('show', 'id' => $model->id));
         }
     } else {
         // pre-assigned attributes (default values for a new record)
         $model->dueDate = MDate::formatToDb(time() + 14 * 86400, 'date');
         $model->openDate = MDate::formatToDb(time(), 'date');
         $model->priority = Task::PRIORITY_MEDIUM;
         $model->status = Task::NOT_STARTED;
         if (Yii::app()->user->checkAccess(User::MANAGER) || Yii::app()->user->checkAccess(User::ADMINISTRATOR)) {
             $model->isConfirmed = Task::IS_CONFIRMED;
         }
         if (isset($_GET['projectId'])) {
             // project is known
             $model->projectId = $_GET['projectId'];
         }
     }
     if (!isset($model->allConsultant2Task[0])) {
         // new associated consultant
         $model->allConsultant2Task = array(0 => new User2Task('create'));
         $model->allConsultant2Task[0]->taskId = $model->id;
         $model->allConsultant2Task[0]->role = User2Task::CONSULTANT;
     }
     $this->render($this->action->id, array('model' => $model));
 }