Exemplo n.º 1
0
 public function getCommentsCount()
 {
     return $this->hasMany(IssueComment::className(), ['issue_id' => 'id'])->count();
 }
Exemplo n.º 2
0
 public function actionView($id)
 {
     $model = $this->loadModel('app\\models\\Issue', $id);
     $this->view->params['appSettings'] = ['app_name' => $model->project->title];
     if (!\Yii::$app->user->can('viewProject', ['project' => $model->project]) || \Yii::$app->user->isGuest) {
         throw new ForbiddenHttpException('Access denied');
     }
     if (\Yii::$app->request->post('hasEditable') && !\Yii::$app->user->isGuest) {
         $post = \Yii::$app->request->post('Issue');
         if (isset($post['status_id'])) {
             $model->status_id = $post['status_id'];
             $output = StatusEnum::i()->getMap()[$post['status_id']];
             $this->sendMessage($model, ['subject' => \Yii::t('app', 'Issue Status Changed'), 'view' => 'changeStatus']);
         }
         if (isset($post['priority_id'])) {
             $model->priority_id = (int) $post['priority_id'];
             $output = PriorityEnum::i()->getMap()[$post['priority_id']];
         }
         if (isset($post['tracker_id'])) {
             $model->tracker_id = (int) $post['tracker_id'];
             $output = TrackerEnum::i()->getMap()[$post['tracker_id']];
         }
         if (isset($post['assignee_id'])) {
             if ($post['assignee_id']) {
                 $model->assignee_id = (int) $post['assignee_id'];
                 $output = \app\models\Project::getAssigneeOptions($model->project_id)[$post['assignee_id']];
                 $this->sendMessage($model);
             } else {
                 $model->assignee_id = null;
                 $output = '<i>(' . \Yii::t('app', 'not set') . ')</i>';
             }
         }
         if (isset($post['readiness_id'])) {
             $model->readiness_id = (int) $post['readiness_id'];
             $output = Issue::getReadinessOptions()[$post['readiness_id']];
         }
         if (isset($post['deadline'])) {
             $model->deadline = $post['deadline'];
             $output = $post['deadline'];
         }
         if ($model->save()) {
             $out = Json::encode(['output' => $output, 'message' => '']);
             echo $out;
             return;
         }
     }
     if ($post = \Yii::$app->request->post('IssueComment')) {
         $comment = new IssueComment();
         $comment->text = $post['text'];
         $comment->issue_id = $id;
         if ($comment->save()) {
             \Yii::$app->session->setFlash('success', \Yii::t('app', 'Comment successfully added.'));
         }
     }
     return $this->render('view', ['model' => $model]);
 }