Example #1
0
if ($recaptchaResult === false) {
    $responseObj->setSuccess(false);
    $responseObj->setError(array('RECAPTCHA_ERROR' => 'reCAPTCHA did not validate.'));
} else {
    // entry object
    $entryObj = new App_Entry(array('email' => $_REQUEST['email'], 'first' => $_REQUEST['first'], 'last' => $_REQUEST['last'], 'optin' => $_REQUEST['optin']));
    $entryResult = $entryObj->insertElseUpdate();
    // error?
    if ($entryResult === false) {
        $responseObj->setSuccess(false);
        $responseObj->setError($entryObj->getErrorObj()->getThrownErrorsWithDescriptions());
    } else {
        // save vote
        // vote object
        $voteObj = new App_Vote(array('fkEntryId' => $entryObj->getId(), 'fkGroupId' => $_REQUEST['group']));
        $voteResult = $voteObj->insert();
        if ($voteResult === false) {
            // error?
            $responseObj->setSuccess(false);
            $responseObj->setError($voteObj->getErrorObj()->getThrownErrorsWithDescriptions());
        } else {
            // everything worked
            $groupObj = new App_Group();
            $groupObj->fetchById($voteObj->getFkGroupId());
            $responseObj->setSuccess(true);
            $responseObj->setContent(array("entry" => $entryObj->__toArray(), "vote" => $voteObj->__toArray(), "group" => $groupObj->__toArray()));
        }
    }
}
header('content-type: application/json');
echo $responseObj;
Example #2
0
 /**
  * Validate fkGroupId
  * @return boolean
  */
 public function validateFkGroupId()
 {
     $groupObj = new App_Group(array('id' => $this->getFkGroupId()));
     $result = $groupObj->fetchById();
     if ($result === false) {
         // not found
         $this->getErrorObj()->setError('VOTE_GROUP_NOEXIST');
         return false;
     } else {
         return true;
     }
 }