public function init() { parent::init(); if (!$this->id) { $this->id = PollRecord::getMainPollId(); } if ($this->id) { $this->_poll = PollRecord::find()->activeStatus()->andWhere(['id' => $this->id])->andWhere('IFNULL(end_date, \'9999-99-99\')>=:actual_date')->params([':actual_date' => \Yii::$app->formatter->asDate(time(), 'y-MM-dd')])->one(); if ($this->_poll) { $this->setChartOptions(); } } }
/** * Creates data provider instance with search query applied * @param $params * @return ActiveDataProvider */ public function search($params) { /** @var ActiveQuery $query */ $query = PollRecord::find(); if (!isset($params['sort'])) { $query->orderBy(['updated_at' => SORT_DESC]); } $session = Yii::$app->session; if (!$session['language_id']) { $session['language_id'] = LanguageRecord::getMainLanguageId(); } $query->andWhere(['language_id' => $session['language_id']]); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['active' => $this->active, 'main' => $this->main]); $query->andFilterWhere(['like', 'question', $this->question]); $query->andFilterWhere(['like', 'DATE_FORMAT(end_date,\'%d.%m.%Y\')', $this->end_date]); return $dataProvider; }
/** * Returns poll items for CKEditor poll plugin * @return \yii\console\Response|Response */ public function actionPollItems() { $session = Yii::$app->session; if (!$session['language_id']) { $session['language_id'] = LanguageRecord::getMainLanguageId(); } $items = ArrayHelper::map(PollRecord::find()->andWhere(['language_id' => $session['language_id']])->orderBy(['updated_at' => SORT_DESC])->all(), 'question', 'id'); $response = Yii::$app->response; $response->format = Response::FORMAT_JSON; $response->data = $items; return $response; }
/** * Deletes Poll * @throws \Exception */ public function deletePoll() { /** @var $poll PollRecord */ if ($poll = PollRecord::findOne($this->item_id)) { $poll->delete(); } }