/** * Handle Ajax call for display of poll edit form */ public function actionEditPoll() { $json = array(); if (isset(\Yii::$app->request->post()['poll_id'])) { $poll = BbiiPoll::find(\Yii::$app->request->post()['poll_id']); $choices = array(); $models = BbiiChoice::find()->findAll('poll_id = ' . $poll->id); foreach ($models as $model) { $choices[$model->id] = $model->choice; } $json['html'] = $this->render('editPoll', array('poll' => $poll, 'choices' => $choices), true); $json['success'] = 'yes'; } else { $json['success'] = 'no'; } echo json_encode($json); \Yii::$app->end(); }
public function actionView() { $json = array(); if (isset(\Yii::$app->request->post()['id'])) { $model = BbiiPost::find(\Yii::$app->request->post()['id']); if ($model !== null) { $poll = BBiiPoll::find()->findByAttributes(array('post_id' => $model->id)); $choices = array(); if ($poll !== null) { $chs = BbiiChoice::find()->findAllByAttributes(array('poll_id' => $poll->id)); foreach ($chs as $choice) { $choices[] = $choice->choice; } } $json['success'] = 'yes'; $json['html'] = $this->render('_view', array('model' => $model, 'poll' => $poll, 'choices' => $choices), true); } else { $json['success'] = 'no'; $json['message'] = Yii::t('BbiiModule.bbii', 'Post not found.'); } } else { $json['success'] = 'no'; $json['message'] = Yii::t('BbiiModule.bbii', 'Post not found.'); } echo json_encode($json); \Yii::$app->end(); }