Пример #1
0
 /**
  * @inheritdoc
  */
 public function disableContentContainer(ContentContainerActiveRecord $container)
 {
     parent::disableContentContainer($container);
     foreach (Poll::find()->contentContainer($container)->all() as $poll) {
         $poll->delete();
     }
 }
 public function setupFilters()
 {
     $this->activeQuery->andWhere(['content.object_model' => Poll::className()]);
     if (in_array('polls_notAnswered', $this->filters) || in_array('polls_mine', $this->filters)) {
         $this->activeQuery->leftJoin('poll', 'content.object_id=poll.id AND content.object_model=:pollClass', [':pollClass' => Poll::className()]);
         if (in_array('polls_notAnswered', $this->filters)) {
             $this->activeQuery->leftJoin('poll_answer_user', 'poll.id=poll_answer_user.poll_id AND poll_answer_user.created_by=:userId', [':userId' => Yii::$app->user->id]);
             $this->activeQuery->andWhere(['is', 'poll_answer_user.id', new \yii\db\Expression('NULL')]);
         }
     }
 }
Пример #3
0
 /**
  * Create installer sample data
  * 
  * @param \yii\base\Event $event
  */
 public static function onSampleDataInstall($event)
 {
     $space = Space::find()->where(['id' => 1])->one();
     // activate module at space
     if (!$space->isModuleEnabled("polls")) {
         $space->enableModule("polls");
     }
     // Switch Identity
     $user = User::find()->where(['id' => 1])->one();
     Yii::$app->user->switchIdentity($user);
     $poll = new Poll();
     $poll->question = Yii::t('PollsModule.events', "Right now, we are in the planning stages for our next meetup and we would like to know from you, where you would like to go?");
     $poll->answersText = Yii::t('PollsModule.events', "To Daniel\nClub A Steakhouse\nPisillo Italian Panini\n");
     $poll->content->container = $space;
     $poll->allow_multiple = Yii::$app->request->post('allowMultiple', 0);
     $poll->save();
     // load users
     $user2 = User::find()->where(['id' => 2])->one();
     $user3 = User::find()->where(['id' => 3])->one();
     // Switch Identity
     Yii::$app->user->switchIdentity($user2);
     // vote
     $poll->vote([2]);
     $comment = new \humhub\modules\comment\models\Comment();
     $comment->message = Yii::t('PollsModule.events', "Why don't we go to Bemelmans Bar?");
     $comment->object_model = $poll->className();
     $comment->object_id = $poll->getPrimaryKey();
     $comment->save();
     // Switch Identity
     Yii::$app->user->switchIdentity($user3);
     // vote
     $poll->vote([3]);
     $comment = new \humhub\modules\comment\models\Comment();
     $comment->message = Yii::t('PollsModule.events', "Again? ;Weary;");
     $comment->object_model = $poll->className();
     $comment->object_id = $poll->getPrimaryKey();
     $comment->save();
     // Switch Identity
     Yii::$app->user->switchIdentity($user);
 }
 /**
  * Returns a given poll by given request parameter.
  *
  * This method also validates access rights of the requested poll object.
  */
 private function getPollByParameter()
 {
     $pollId = (int) Yii::$app->request->get('pollId');
     $poll = Poll::find()->contentContainer($this->contentContainer)->readable()->where(['poll.id' => $pollId])->one();
     if ($poll == null) {
         throw new HttpException(401, Yii::t('PollsModule.controllers_PollController', 'Could not load poll!'));
     }
     if (!$poll->content->canRead()) {
         throw new HttpException(401, Yii::t('PollsModule.controllers_PollController', 'You have insufficient permissions to perform that operation!'));
     }
     return $poll;
 }
 public function getPoll()
 {
     return $this->hasOne(Poll::className(), ['id' => 'poll_id']);
 }