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
 /**
  * Lists all Log models.
  * @return mixed
  * @throws UserException
  */
 public function actionIndex()
 {
     $goalId = (int) Yii::$app->request->get('goal_id', 0);
     if (!$goalId) {
         throw new UserException('Goal id is not provided');
     }
     $goal = Goal::findOne($goalId);
     if (!$goal) {
         throw new UserException("Goal [{$goalId}] not found");
     }
     $searchModel = new LogSearch(['goal_id' => $goalId]);
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('index', ['goal' => $goal, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
Beispiel #5
0
 /**
  * Creates a new Task model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  * @throws UserException
  */
 public function actionCreate()
 {
     $goalId = (int) Yii::$app->request->get('goal_id', 0);
     if (!$goalId) {
         throw new UserException('Goal id is not provided');
     }
     $goal = Goal::findOne($goalId);
     if (!$goal) {
         throw new UserException("Goal [{$goalId}] not found");
     }
     $model = new Task(['goal_id' => $goalId]);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(Yii::$app->request->post('referrer') ?: $model->goal->urlTaskList());
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Beispiel #6
0
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     $oLog = new Log();
     $oLog->message = $this->log_message;
     $oLog->goal_id = $this->id;
     $aChanged = [];
     foreach ($changedAttributes as $sName => $sVal) {
         $mNewVal = $this->getAttribute($sName);
         if (is_int($sVal)) {
             $mNewVal = (int) $mNewVal;
         }
         if ($sVal != $this->getAttribute($sName)) {
             $aChanged[$sName] = [$sVal, $mNewVal];
         }
     }
     if (isset($aChanged['updated_at'])) {
         unset($aChanged['updated_at']);
     }
     $oLog->data = json_encode($aChanged);
     $oLog->save();
 }
Beispiel #7
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 #8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getGoal()
 {
     return $this->hasOne(Goal::className(), ['id' => 'goal_id']);
 }
Beispiel #9
0
<?php

use app\models\Goal;
use app\modules\settings\models\Priority;
use app\modules\settings\models\Status;
use app\modules\settings\models\Type;
use yii\helpers\Html;
/**
 * @var \app\models\Log $log
 */
$goalModel = new Goal();
$notFound = '{not found}';
?>

<strong title="<?php 
echo Yii::$app->formatter->asDatetime($log->created_at);
?>
"><?php 
echo Yii::$app->formatter->asRelativeTime($log->created_at);
?>
</strong>
<br />

<?php 
$data = json_decode($log->data, true);
$rows = [];
if ($data) {
    foreach ($data as $fieldName => $fieldData) {
        if ($goalModel->hasAttribute($fieldName)) {
            $fieldLabel = $goalModel->getAttributeLabel($fieldName);
            switch ($fieldName) {
Beispiel #10
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');
 }
Beispiel #11
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getGoals()
 {
     return $this->hasMany(Goal::className(), ['type_id' => 'id']);
 }
Beispiel #12
0
 public function vision($society)
 {
     $data['soc'] = $society;
     $data['society'] = Society::where('society', '=', $society)->first();
     $data['goals'] = Goal::where('society_id', '=', $data['society']->id)->where('goalyear', '=', date("Y"))->get();
     $others = Goal::with('society')->where('society_id', '<>', $data['society']->id)->where('goalyear', '=', date("Y"))->get();
     $data['others'] = array();
     foreach ($others as $other) {
         $data['others'][$other->society->society][] = $other->goal;
     }
     return view('societies.vision', $data);
 }
 public function actionDeletegoal($goal_id, $kpa_id)
 {
     $goal = Goal::findOne($goal_id);
     //@todo: make sure to check for a valid object/model
     if (isset($goal)) {
         $goal->delete($goal_id);
     }
     Yii::$app->response->redirect(array('/site/viewkpa', 'id' => $kpa_id));
 }
Beispiel #14
0
 /**
  * Finds the Goal model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $alias
  * @return Goal the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($alias)
 {
     if (($model = Goal::findOne(['alias' => $alias])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }