示例#1
0
 public function viewAction()
 {
     if ($this->view->identity === null) {
         throw new Www_Exception_Auth();
     }
     $id = $this->_getParam('id');
     $templateDb = new Shared_Db_Table_Template();
     $template = $templateDb->fetchRow(array('id = ?' => $id));
     if ($template === null) {
         throw new Www_Exception_NotFound();
     }
     $application = $template->findParentRow('Shared_Db_Table_Application');
     if ($application->user_id != $this->view->identity->id) {
         throw new Www_Exception_Access();
     }
     $this->view->application = $application;
     $this->view->template = $template;
     $form = new Www_Form_TemplateEdit($template->id);
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($_POST)) {
             $values = (object) $form->getValues();
             $templateModel = new Shared_Model_Template();
             $templateModel->update($template->id, $values->privacy, $values->web_hooks);
             $this->_redirect($this->view->url(array('id' => $template->id), 'template'));
         }
     } else {
         $form->populate(array('privacy' => $template->privacy, 'web_hooks' => $template->web_hooks));
     }
     $this->view->form = $form;
 }
示例#2
0
 public function viewAction()
 {
     if ($this->view->identity === null) {
         throw new Www_Exception_Auth();
     }
     $id = $this->_getParam('id');
     $applicationDb = new Shared_Db_Table_Application();
     $application = $applicationDb->fetchRow(array('id = ?' => $id));
     if ($application === null) {
         throw new Www_Exception_NotFound();
     }
     if ($application->user_id != $this->view->identity->id) {
         throw new Www_Exception_Access();
     }
     $this->view->application = $application;
     // get templates
     $templateDb = new Shared_Db_Table_Template();
     $this->view->templates = $templateDb->fetchAll(array('application_id = ?' => $application->id), 'created DESC');
     // get events
     $eventDb = new Shared_Db_Table_Event();
     $select = $eventDb->select()->from('event')->joinLeft('template', 'event.template_id = template.id', array())->where('template.application_id = ?', $application->id)->order('event.created DESC');
     $this->view->events = $eventDb->fetchAll($select);
     // form
     $form = new Www_Form_ApplicationEdit($application->id);
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($_POST)) {
             $values = (object) $form->getValues();
             $applicationModel = new Shared_Model_Application();
             $applicationModel->update($application->id, $values->privacy);
             $this->_redirect($this->view->url(array('id' => $application->id), 'application'));
         }
     } else {
         $form->populate(array('privacy' => $application->privacy));
     }
     $this->view->form = $form;
 }
示例#3
0
 public function update($templateId, $privacy = 'public', $webhooks = 'yes')
 {
     $templateDb = new Shared_Db_Table_Template();
     try {
         $templateDb->getAdapter()->beginTransaction();
         $templateDb->update(array('privacy' => (string) $privacy, 'web_hooks' => (string) $webhooks), $templateDb->getAdapter()->quoteInto('id = ?', $templateId));
         $templateDb->getAdapter()->commit();
     } catch (Exception $e) {
         $templateDb->getAdapter()->rollBack();
         throw $e;
     }
     return $this;
 }
示例#4
0
 public function submitAction()
 {
     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 = '/event[@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 template ID
     $query = '/event/templateId';
     $nodes = $xpath->query($query);
     if (sizeof($nodes) !== 1) {
         throw new Api_Exception(Api_Result::ERROR_XML_INVALID);
     }
     $node = $nodes->item(0);
     $templateId = (int) $node->nodeValue;
     $templateDb = new Shared_Db_Table_Template();
     $template = $templateDb->fetchRow(array('id = ?' => $templateId));
     if ($template === null) {
         throw new Api_Exception(Api_Result::ERROR_TEMPLATE_NOT_FOUND);
     }
     // get tokens
     $query = '/event/tokens/token';
     $nodes = $xpath->query($query);
     $tokens = array();
     foreach ($nodes as $node) {
         $query = 'name';
         $nameNode = $xpath->query($query, $node);
         if (sizeof($nameNode) !== 1) {
             throw new Api_Exception(Api_Result::ERROR_XML_INVALID);
         }
         $name = $nameNode->item(0)->nodeValue;
         $query = 'value';
         $valueNode = $xpath->query($query, $node);
         if (sizeof($valueNode) !== 1) {
             throw new Api_Exception(Api_Result::ERROR_XML_INVALID);
         }
         $value = $valueNode->item(0)->nodeValue;
         $tokens[$name] = $value;
     }
     // create the event
     try {
         $eventModel = new Shared_Model_Event();
         $eventId = $eventModel->register($templateId, $tokens);
     } catch (Exception $e) {
         throw new Api_Exception(Api_Result::ERROR_DATABASE);
     }
     $this->getResponse()->setBody(Api_Result::xml(Api_Result::SUCCESS));
     $this->getResponse()->sendResponse();
     die;
 }