Ejemplo n.º 1
0
 /**
  * Loads a list of objects for the specicifies parameters,
  * returns an array of Object_Abstract elements.
  *
  * @return array
  */
 public function load()
 {
     $items = array();
     $itemsData = $this->db->fetchAll(sprintf("SELECT * FROM %s%s%s%s", Poll_Question_Resource::TABLE_NAME, $this->getCondition(), $this->getOrder(), $this->getOffsetLimit()), $this->model->getConditionVariables());
     foreach ($itemsData as $data) {
         $item = new Poll_Question();
         $item->setValues($data);
         $items[] = $item;
     }
     $this->model->setQuestions($items);
     return $items;
 }
Ejemplo n.º 2
0
 /**
  * Poll response and results.
  *
  * @todo cookie expiration settings
  */
 public function responseAction()
 {
     $question = (int) $this->_getParam('question');
     if (!isset($this->_session->poll[$question])) {
         throw new Zend_Controller_Action_Exception('Hacking attempt?');
     }
     try {
         $question = Poll_Question::getById($question);
     } catch (Exception $e) {
         throw new Zend_Controller_Action_Exception('Question not exists?');
     }
     $thanks = false;
     if ($this->_request->isPost()) {
         if (isset($_COOKIE['poll_' . $question->getId()])) {
             throw new Zend_Controller_Action_Exception('Question already voted');
         }
         $answers = $this->_request->getPost('answer');
         if (!is_array($answers) || empty($answers)) {
             throw new Zend_Controller_Action_Exception('No response data provided');
         }
         foreach ($question->getAnswers() as $answer) {
             if (in_array($answer->getId(), $answers)) {
                 $answer->responses++;
                 $answer->save();
                 if (!$question->getMultiple()) {
                     break;
                 }
             }
         }
         setcookie('poll_' . $question->getId(), 1, time() + 60 * 60 * 24, '/');
         $thanks = true;
     }
     $this->view->question = $question;
     $this->view->thanks = $thanks;
     $this->_helper->json(array('responses' => $this->view->render('frontend/responses.php')));
 }
Ejemplo n.º 3
0
 /**
  * Deletes object from database.
  *
  */
 public function delete()
 {
     $this->db->delete(self::TABLE_NAME, array('id = ?' => $this->model->getId()));
 }
Ejemplo n.º 4
0
<?php

if (Poll_Plugin::isInstalled() && Poll_Question::hasCurrent()) {
    ?>
    <div class="page-header">
        <h3><?php 
    echo $this->input('page-header');
    ?>
</h3>
    </div>
    <?php 
    echo $this->action('current', 'frontend', 'Poll', array('omitJquery' => false, 'omitJqueryUi' => false, 'omitStyles' => false));
}
Ejemplo n.º 5
0
 /**
  * @return Poll_Question
  * @todo cache with expiration == endDate
  */
 public static function getCurrent()
 {
     if (null === self::$_current) {
         $now = date('Y-m-d H:i:s');
         $list = new Poll_Question_List();
         $list->setCondition('isActive = 1 AND (' . '(startDate <= ? AND endDate >= ?) OR ' . '(startDate IS NULL AND endDate >= ?) OR ' . '(startDate <= ? AND endDate IS NULL) OR ' . '(startDate IS NULL AND endDate IS NULL)' . ')', array($now, $now, $now, $now));
         $list->setLimit(1);
         $list->setOrderKey('id');
         $list->setOrder('ASC');
         self::$_current = $list->current();
     }
     return self::$_current;
 }
Ejemplo n.º 6
0
 public function saveAction()
 {
     $question = Poll_Question::getById((int) $this->_getParam('id'));
     if (is_array($this->_request->getPost())) {
         $data = $this->_request->getPost();
         $question->updateAnswers(Zend_Json::decode($data['answers']));
         unset($data['answers']);
         foreach ($data as $key => $value) {
             $question->setValue($key, $value);
         }
     }
     try {
         $question->save();
         $this->_helper->json(array("success" => true));
     } catch (Exception $e) {
         Logger::log($e);
         $this->_helper->json(array("success" => false, "message" => $e->getMessage()));
     }
 }