/**
  * 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)
 {
     $model = $this->loadModel($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Activity'])) {
         $model->attributes = $_POST['Activity'];
         // Make sure the userid was not manipulated. We only allow users to update
         // their own goals.
         if ($model->userId != Yii::app()->user->id) {
             throw new CHttpException(404, 'You can only update your own activities.');
         }
         // Save the model.
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('update', array('model' => $model, 'goals' => Goal::model()->findAllByAttributes(array('userId' => $model->userId))));
 }
 /**
  * This is the default 'index' action that is invoked
  * when an action is not explicitly requested by users.
  */
 public function actionIndex()
 {
     // Render 'index' view for guest users.
     if (Yii::app()->user->isGuest) {
         $this->render('index');
     } else {
         // Find an active goal for the current user.
         // @todo Currently assuming there is only one which the model logic does not enforce!
         // @todo I don't like the cleanup implementation!
         $models = Goal::model()->findAllByAttributes(array('active' => 1, 'userId' => Yii::app()->user->id));
         foreach ($models as $model) {
             $model->cleanUp();
         }
         $model = Goal::model()->findByAttributes(array('active' => 1, 'userId' => Yii::app()->user->id));
         // Redirect to current goal if exist.
         if ($model) {
             $this->redirect(array('goal/report', 'id' => $model->id));
         } else {
             $this->redirect(array('goal/workflow'));
         }
     }
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Goal::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }