コード例 #1
0
ファイル: Resource.php プロジェクト: pimcore-extensions/poll
 /**
  * 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 id FROM %s%s%s%s", Poll_Answer_Resource::TABLE_NAME, $this->getCondition(), $this->getOrder(), $this->getOffsetLimit()), $this->model->getConditionVariables());
     foreach ($itemsData as $data) {
         $items[] = Poll_Answer::getById($data["id"]);
     }
     $this->model->setAnswers($items);
     return $items;
 }
コード例 #2
0
ファイル: Resource.php プロジェクト: pimcore-extensions/poll
 /**
  * Deletes object from database.
  *
  */
 public function delete()
 {
     $this->db->delete(self::TABLE_NAME, array('id = ?' => $this->model->getId()));
 }
コード例 #3
0
ファイル: Question.php プロジェクト: pimcore-extensions/poll
 /**
  * Update answers from array.
  *
  * Method changes only state of the object you must
  * call save() if you want to push changes to database.
  *
  * @param array $answers
  * @return Poll_Question
  */
 public function updateAnswers(array $answers)
 {
     $update = array();
     $new = array();
     foreach ($answers as $answer) {
         if (isset($answer['id'])) {
             unset($answer['responses']);
             $update[$answer['id']] = $answer;
         } else {
             $new[] = $answer;
         }
     }
     foreach ($this->getAnswers() as $answer) {
         $id = $answer->getId();
         if (!isset($update[$id])) {
             $this->_answersToDelete[] = $id;
         } else {
             $answer->setValues($update[$id]);
         }
     }
     foreach ($new as $data) {
         $answer = new Poll_Answer();
         $answer->setValues($data);
         $answer->setQuestionId($this->getId());
         $this->getAnswers()->append($answer);
     }
     return $this;
 }