Beispiel #1
0
 public function newAction()
 {
     if ($this->view->identity === null) {
         throw new Www_Exception_Auth();
     }
     if (!array_key_exists('applicationid', $_GET)) {
         $this->_redirect($this->view->url(array('id' => $this->view->identity->id), 'user'));
     }
     $applicationId = (int) $_GET['applicationid'];
     $applicationDb = new Shared_Db_Table_Application();
     $application = $applicationDb->fetchRow(array('id = ?' => $applicationId));
     if ($application === null) {
         throw new Www_Exception_NotFound();
     }
     $this->view->application = $application;
     // form
     $form = new Www_Form_TemplateNew($application->id);
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($_POST)) {
             $values = (object) $form->getValues();
             $templateModel = new Shared_Model_Template();
             $templateModel->create($application->id, $values->name, $values->body, $values->privacy, $values->web_hooks);
             $this->_redirect($this->view->url(array('id' => $application->id), 'application'));
         }
     }
     $this->view->form = $form;
 }
Beispiel #2
0
 public function registerAction()
 {
     if (!$this->getRequest()->isPost()) {
         throw new Api_Exception(Api_Result::ERROR_REQUEST_METHOD);
     }
     $rawPost = file_get_contents('php://input');
     $doc = new DOMDocument();
     $result = @$doc->loadXML($rawPost);
     if ($result === false) {
         throw new Api_Exception(Api_Result::ERROR_XML_PARSE);
     }
     $xpath = new DOMXPath($doc);
     // get version
     $query = '/template[@version]';
     $nodes = $xpath->query($query);
     if (sizeof($nodes) !== 1) {
         throw new Api_Exception(Api_Result::ERROR_XML_INVALID);
     }
     $version = $nodes->item(0)->getAttribute('version');
     $config = Zend_Registry::get('config');
     if ($version != $config->api->version) {
         throw new Api_Exception(Api_Result::ERROR_API_VERSION);
     }
     // get application ID
     $query = '/template/applicationId';
     $nodes = $xpath->query($query);
     if (sizeof($nodes) !== 1) {
         throw new Api_Exception(Api_Result::ERROR_XML_INVALID);
     }
     $node = $nodes->item(0);
     $applicationId = (int) $node->nodeValue;
     $applicationDb = new Shared_Db_Table_Application();
     $application = $applicationDb->fetchRow(array('id = ?' => $applicationId));
     if ($application === null) {
         throw new Api_Exception(Api_Result::ERROR_APPLICATION_NOT_FOUND);
     }
     // get template name
     $query = '/template/name';
     $nodes = $xpath->query($query);
     if (sizeof($nodes) !== 1) {
         throw new Api_Exception(Api_Result::ERROR_XML_INVALID);
     }
     $node = $nodes->item(0);
     $templateName = $node->nodeValue;
     // get template body
     $query = '/template/body';
     $nodes = $xpath->query($query);
     if (sizeof($nodes) !== 1) {
         throw new Api_Exception(Api_Result::ERROR_XML_INVALID);
     }
     $node = $nodes->item(0);
     $templateBody = $node->nodeValue;
     // get template privacy
     $query = '/template/privacy';
     $nodes = $xpath->query($query);
     if (sizeof($nodes) !== 1) {
         throw new Api_Exception(Api_Result::ERROR_XML_INVALID);
     }
     $node = $nodes->item(0);
     $templatePrivacy = $node->nodeValue;
     // get web hooks
     $query = '/template/webHooks';
     $nodes = $xpath->query($query);
     if (sizeof($nodes) !== 1) {
         throw new Api_Exception(Api_Result::ERROR_XML_INVALID);
     }
     $node = $nodes->item(0);
     $templateWebhooks = $node->nodeValue;
     // create the template
     $templateModel = new Shared_Model_Template();
     try {
         $templateId = $templateModel->create($applicationId, $templateName, $templateBody, $templatePrivacy, $templateWebhooks);
     } catch (Exception $e) {
         throw new Api_Exception(Api_Result::ERROR_DATABASE);
     }
     $this->getResponse()->setBody(Api_Result::xml(Api_Result::SUCCESS, $templateId));
     $this->getResponse()->sendResponse();
     die;
 }