Beispiel #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Goal::find();
     $query->with('type')->with('priority')->with('status');
     if (!$this->isUsed()) {
         $query->innerJoinWith('priority')->orderBy(['priority.weight' => SORT_ASC, 'to_be_done_at' => SORT_ASC])->innerJoinWith('status')->where('status.closed=0');
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['params' => ['sort' => $this->sort]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     switch ((int) $this->status_id) {
         case 0:
             break;
         case Status::OPENED:
             $query->innerJoinWith('status')->where('status.closed=0');
             break;
         case Status::CLOSED:
             $query->innerJoinWith('status')->where('status.closed=1');
             break;
         default:
             $query->andFilterWhere(['status_id' => $this->status_id]);
             break;
     }
     $query->andFilterWhere(['id' => $this->id, 'priority_id' => $this->priority_id, 'type_id' => $this->type_id, 'created_at' => $this->created_at, 'to_be_done_at' => $this->to_be_done_at, 'updated_at' => $this->updated_at, 'done_at' => $this->done_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Beispiel #2
0
 /**
  * Returns first overdue goals
  * @param int $iTotalCount if provided total count will be returned to this value
  * @return Goal[]
  */
 public static function getGoalsOverdue(&$iTotalCount = 0)
 {
     $query = Goal::find()->innerJoinWith('status')->where('status.closed=0')->andWhere('to_be_done_at <= DATE(NOW())')->orderBy('goal.id')->limit(10);
     if (func_num_args()) {
         $iTotalCount = $query->count();
     }
     return $query->all();
 }
Beispiel #3
0
 public function overallScore()
 {
     $total = 0;
     $goals = Goal::find()->where(['KPA_ID' => $this->ID])->all();
     foreach ($goals as $goal) {
         $total += $goal->Weight * $goal->overallScore() / 100;
     }
     return $total;
 }
Beispiel #4
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($sid, $yr, $id)
 {
     $goal = Goal::find($id);
     $goal->delete();
     return Redirect::route('society.goals.index', $sid)->with('okmessage', 'goal has been deleted');
 }
Beispiel #5
0
 /**
  * Responds to GET::/user/goals/delete. Deletes the goal with the given ID
  * and redirects to the goals home page.
  *
  * @return Redirect to GET::/user/goals
  */
 public function getDelete($goalID)
 {
     $goal = \App\Models\Goal::find($goalID);
     if ($goal && $goal->user_id == \Auth::User()->id) {
         $goal->delete();
         \Session::flash('goal_delete', 'Goal Deleted');
     } else {
         \Session::flash('goal_delete_error', 'You are not authorized to delete this goal');
     }
     return redirect('/goals');
 }
 public function actionViewkpa($id)
 {
     $kpa = KPA::findOne($id);
     $goals = Goal::find()->where(['kpa_id' => $id])->all();
     return $this->render('viewkpa', ['kpa' => $kpa, 'goals' => $goals]);
 }