/** * The read action * @return \Zend\View\Model\JsonModel */ public function readAction() { $id = $this->params()->fromPost('surveyId', null); if (!is_null($id)) { //filter by specific id $results = $this->getServiceLocator()->get("Api\\Service\\Survey")->fetchAll(array('id' => $id)); } else { $results = $this->getServiceLocator()->get("Api\\Service\\Survey")->fetchAll(); } return new \Zend\View\Model\JsonModel(array("result" => "true", "error" => "", "collection" => \Api\Service\Encoder\Survey::toJson($results))); }
/** * The update action * @return \Zend\View\Model\JsonModel */ public function updateAction() { if (!\Api\Service\Encoder\Survey::validateParameters($this->_request->getParams())) { $this->getResponse()->setStatusCode(400); return new \Zend\View\Model\JsonModel(array("result" => "false", "error" => "Incorrect parameters")); } else { $model = $this->getServiceLocator()->get("Api\\Service\\Tag")->fetchById($id); $model->setQuestionText($this->params()->fromPost("questionText"))->setRenderId($this->params()->fromPost("renderId")); $model = $this->getServiceLocator()->get("Api\\Service\\Tag")->update($model); if ($model instanceof \Api\Model\Tag) { return new \Zend\View\Model\JsonModel(array("result" => "true", "error" => "", "model" => $model->toArray())); } else { $this->getResponse()->setStatusCode(417); return new \Zend\View\Model\JsonModel(array("result" => "false", "error" => "Update failed")); } } }