Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
Public Member Functions | List of all members
PoolController Class Reference

Public Member Functions

 actionSubmit ()
 actionVoteResults ()
 actionReset ($id)
 actionDownloadCsv ($id)

Detailed Description

Definition at line 6 of file PoolController.php.

Member Function Documentation

PoolController::actionSubmit ( )

This action recieve user answers for pool question

Returns
void
Author
Me

Definition at line 15 of file PoolController.php.

References Answer\model().

{
if(!isset($_POST['question'], $_POST['answer'], $_POST['additionalFields'])) {
throw new CHttpException(400, 'Bad fields');
}
if(is_array($_POST['answer'])) {
$answers = Answer::model()->findAllByAttributes(array('question_id' => $_POST['question'], 'id' => $_POST['answer']));
if(empty($answers)){
throw new CHttpException(400);
}
foreach($answers as $answ)
{
$userAnswer = new UserAnswer();
$userAnswer->answer_id = $answ->id;
$userAnswer->user_id = $this->module->getUserId();
$userAnswer->additional = $_POST['additionalFields'];
if(!$userAnswer->save()) {
throw new Exception(print_r($userAnswer->getErrors(), true));
}
}
} else {
$answer = Answer::model()->findByAttributes(array('question_id' => $_POST['question'], 'id' => $_POST['answer']));
if(empty($answer)){
throw new CHttpException(400);
}
$userAnswer = new UserAnswer();
$userAnswer->answer_id = $answer->id;
$userAnswer->user_id = $this->module->getUserId();
$userAnswer->additional = $_POST['additionalFields'];
if(!$userAnswer->save()) {
throw new Exception(print_r($userAnswer->getErrors(), true));
}
}
$this->module->setUserVoted($_POST['question']);
if(isset($_POST['forwardTo'])) {
$this->redirect($_POST['forwardTo']);
}
}

The documentation for this class was generated from the following file: