コード例 #1
0
ファイル: PullRequest.php プロジェクト: bariew/sitown
 /**
  * Gets the last poll related to this pull request
  * @return Question
  */
 public function getPoll()
 {
     if (static::$_polls === null) {
         static::$_polls = Question::find()->where(['like', 'relation_id', get_class($this)])->indexBy('relation_id')->all();
     }
     return @static::$_polls[ModelHelper::getRelationId($this)];
 }
コード例 #2
0
ファイル: Question.php プロジェクト: bariew/sitown
 public static function modelEventHandler(Event $event)
 {
     /** @var ActiveRecord $model */
     $model = $event->sender;
     if (!static::$pollBlock) {
         return;
     }
     static::$pollBlock = false;
     // remove block for saving itself
     if ($question = static::find()->where(['relation_id' => ModelHelper::getRelationId($model), 'status' => static::STATUS_OPEN])->andWhere(['<>', 'relation_id', ''])->one()) {
         $message = Yii::t('modules/poll', "This {$model->formName()} is already involved in another poll.");
     } else {
         $question = new static(['title' => "(auto) " . $model->formName() . ' "' . ModelHelper::getRelationTitle($model) . '" ' . $event->name, 'description' => ModelHelper::attributeDifference($event), 'status' => static::STATUS_OPEN, 'type' => static::TYPE_DICHOTOMOUS, 'relation_id' => ModelHelper::getRelationId($model), 'event_object' => ['name' => $event->name, 'sender' => ['class' => $model::className(), 'attributes' => $model->attributes, 'dirtyAttributes' => isset($model->dirtyAttributes) ? $model->dirtyAttributes : []]]]);
         $question->save();
         $message = Yii::t('modules/poll', 'These changes will be applied after a successful poll.');
     }
     Yii::$app->session->setFlash('warning', $message);
     Yii::$app->controller->redirect(['/poll/question/view', 'id' => $question->id]);
     Yii::$app->end();
 }