public function actionOrder() { $result = new stdClass(); $post = $this->getRequestBody(); if ($post === null) { $result->status = "request is empty"; } else { //$order = json_decode($post); $pollId = null; foreach ($post as $item) { $question = Question::findById($item->id); $question->weight = $item->weight; $pollId = $question->poll->id; } Variant::flush(); $poll = Poll::findById($pollId); $result->status = 'ok'; $result->data = $poll->formStdObject()->questions; } echo json_encode($result); exit; }
public function actionStat($id) { $poll = Poll::findById($id); // update statistic for all variants foreach ($poll->questions as $question) { foreach ($question->variants as $variant) { $variant->updateStat(); } } $pollObj = $poll->formStdObject(); $html = Application::getTemplateEngine()->render('poll/stat.html', array('poll' => $pollObj, 'indexUrl' => $this->url('poll.index'), 'showUrl' => $this->url('poll.show', array('id' => $poll->id)))); echo $html; }