/**
  * 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->aActivity !== null) {
             if (!$this->aActivity->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aActivity->getValidationFailures());
             }
         }
         if ($this->aFeature !== null) {
             if (!$this->aFeature->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aFeature->getValidationFailures());
             }
         }
         if (($retval = ActivityHasFeaturePeer::doValidate($this, $columns)) !== true) {
             $failureMap = array_merge($failureMap, $retval);
         }
         $this->alreadyInValidation = false;
     }
     return !empty($failureMap) ? $failureMap : true;
 }
 /**
  * A workflow for creating goals with activities.
  * @param integer $step workflow step
  * @param integer $goal goal id set in first step
  * @todo: Save everything in the last step.
  */
 public function actionWorkflow($step = 1, $goal = 0)
 {
     // First step: Set goal (description).
     if ($step == 1) {
         $model = empty($goal) ? new Goal() : ($model = $this->loadModel((int) $goal));
         // Associate goal with current user and set defaults.
         $model->userId = Yii::app()->user->id;
         $model->active = 0;
         // Uncomment the following line if AJAX validation is needed
         // $this->performAjaxValidation($model);
         if (isset($_POST['Goal'])) {
             $model->attributes = $_POST['Goal'];
             if ($model->save()) {
                 $this->redirect(array('workflow', 'step' => 2, 'goal' => $model->id));
             }
         }
         // Render view.
         $this->render('create', array('model' => $model));
     } elseif ($step == 2) {
         // Load goal created in first step.
         $goalModel = Goal::model()->findByPk($goal);
         $model = new Activity();
         // Associate goal with current user and goal created in step1.
         $model->userId = Yii::app()->user->id;
         $model->goalId = $goalModel->id;
         // Set default values.
         $model->day = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d") + 0, date("Y")));
         // Uncomment the following line if AJAX validation is needed
         // $this->performAjaxValidation($model);
         // @todo: Must make sure only one set of activities exist for a goal. Delete old ones first?
         if (isset($_POST['Activity'])) {
             $model->attributes = $_POST['Activity'];
             // Validate input.
             if ($model->validate()) {
                 // Create 10 models for the next 10 days and safe them.
                 for ($i = 0; $i < 10; $i++) {
                     $models[$i] = clone $model;
                     $models[$i]->day = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d") + $i, date("Y")));
                     if (!$models[$i]->save()) {
                         throw new CHttpException(409, 'There was problem creating the activities. Try again later!');
                     }
                 }
                 // Redirect if everything was fine.
                 $this->redirect(array('workflow', 'step' => 3, 'goal' => $goal));
             }
         }
         // Render view.
         $this->render('createActivity', array('model' => $model, 'goal' => $goalModel));
     } elseif ($step == 3) {
         $model = $this->loadModel((int) $goal);
         if (empty($model) or $model->userId != Yii::app()->user->id) {
             throw new CHttpException(400, 'You cannot proceed with this workflow!');
         }
         // Uncomment the following line if AJAX validation is needed
         // $this->performAjaxValidation($model);
         if (isset($_POST['Goal'])) {
             $model->attributes = $_POST['Goal'];
             if ($model->save()) {
                 $this->redirect(array('workflow', 'step' => 4, 'goal' => $model->id));
             }
         }
         // Render view.
         $this->render('createMentors', array('model' => $model));
     } elseif ($step == 4) {
         $model = $this->loadModel((int) $goal);
         if (empty($model) or $model->userId != Yii::app()->user->id) {
             throw new CHttpException(400, 'You cannot proceed with this workflow!');
         }
         // Render view.
         $this->render('finish', array('model' => $model));
     } elseif ($step == 5) {
         $model = $this->loadModel((int) $goal);
         if (empty($model) or $model->userId != Yii::app()->user->id) {
             throw new CHttpException(400, 'You cannot proceed with this workflow!');
         }
         // Set goal active.
         $model->active = 1;
         if ($model->save()) {
             $this->redirect(array('site/index', 'goal' => $model->id));
         } else {
             throw new CHttpException(409, 'There was problem creating the activities. Try again later!');
         }
     }
 }
Beispiel #3
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->aRoomprofile !== null) {
             if (!$this->aRoomprofile->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aRoomprofile->getValidationFailures());
             }
         }
         if ($this->aActivity !== null) {
             if (!$this->aActivity->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aActivity->getValidationFailures());
             }
         }
         if ($this->aReservationreason !== null) {
             if (!$this->aReservationreason->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aReservationreason->getValidationFailures());
             }
         }
         if ($this->aUsergroup !== null) {
             if (!$this->aUsergroup->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aUsergroup->getValidationFailures());
             }
         }
         if ($this->aCard !== null) {
             if (!$this->aCard->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aCard->getValidationFailures());
             }
         }
         if ($this->aUser !== null) {
             if (!$this->aUser->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aUser->getValidationFailures());
             }
         }
         if ($this->aReservationRelatedByReservationparentId !== null) {
             if (!$this->aReservationRelatedByReservationparentId->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aReservationRelatedByReservationparentId->getValidationFailures());
             }
         }
         if (($retval = ReservationPeer::doValidate($this, $columns)) !== true) {
             $failureMap = array_merge($failureMap, $retval);
         }
         if ($this->collReservationsRelatedByReservationparentId !== null) {
             foreach ($this->collReservationsRelatedByReservationparentId as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         if ($this->collReservationOtherMemberss !== null) {
             foreach ($this->collReservationOtherMemberss as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         $this->alreadyInValidation = false;
     }
     return !empty($failureMap) ? $failureMap : true;
 }