public function register($templateId, $tokens) { $eventDb = new Shared_Db_Table_Event(); $tokenDb = new Shared_Db_Table_Token(); try { $eventDb->getAdapter()->beginTransaction(); $eventId = $eventDb->insert(array('template_id' => (int) $templateId, 'created' => new Zend_Db_Expr('NOW()'))); foreach ($tokens as $key => $value) { $tokenDb->insert(array('event_id' => (int) $eventId, 'name' => $key, 'value' => $value, 'created' => new Zend_Db_Expr('NOW()'))); } $eventDb->getAdapter()->commit(); } catch (Exception $e) { $eventDb->getAdapter()->rollBack(); throw $e; } return $eventId; }
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; }