示例#1
0
 /**
  * Save the new survey
  * @param Array $post
  * @return Array
  */
 public function save($post)
 {
     $model = new \Api\Model\Survey($post);
     //hydrate from post
     $model->setExpiresDate($post['expiresDate']);
     $model = $this->insert($model);
     if (empty($model->getId())) {
         return array('result' => false, 'id' => 0);
     }
     $surveyId = $model->getId();
     //now add a page
     $model = new \Api\Model\Page();
     $model->setName("Page 1")->setSortOrder(1)->setSurveyId($surveyId);
     $result = $this->getServiceLocator()->get("Api\\Service\\Page")->insert($model);
     return array('result' => true, 'id' => $surveyId);
 }
 /**
  * The add action
  * @return \Zend\View\Model\JsonModel
  */
 public function addAction()
 {
     if (!\Api\Service\Encoder\Page::validateParameters($this->_request->getParams())) {
         $this->getResponse()->setStatusCode(400);
         return new \Zend\View\Model\JsonModel(array("result" => "false", "error" => "Incorrect parameters"));
     } else {
         $model = new \Api\Model\Page();
         $model->setName($this->params()->fromPost("name"))->setSortOrder($this->params()->fromPost("sortOrder"));
         $model = $this->getServiceLocator()->get("Api\\Service\\Page")->insert($model);
         if ($model instanceof \Api\Model\Page) {
             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" => "Add failed"));
         }
     }
 }