Exemplo n.º 1
0
 /**
  * STAGE 3: Choose, create, and optionally update models using business logic.
  * STAGE 4: Apply business logic to create a presentation model for the view.
  */
 protected function displayStage3_4()
 {
     // ZFDemoModel_Topics provides static methods that auto-instantiate and manage the model
     $this->view->topics = ZFDemoModel_Topics::getPresentationModel();
     $this->view->user = 'anonymous';
     // Controller = 'index', Action = 'index', param name = 'topic'
     $this->view->topicUrl = 'index/index/topic';
     $this->view->hide = false;
 }
Exemplo n.º 2
0
 /**
  * STAGE 3:  Choose, create, and optionally update models using business logic.
  * STAGE 4.  Apply business logic to create a presentation model for the view.
  */
 protected function displayStage3_4()
 {
     // the posts and topics models auto-instantiate themselves, as needed (STAGE 3)
     $this->view->posts = ZFDemoModel_Posts::getPostsByTopicId($this->topicId);
     $this->view->topicId = $this->topicId;
     // the posts and topics models auto-instantiate themselves, as needed (STAGE 3)
     $topic = ZFDemoModel_Topics::getPresentationModelByTopicId($this->topicId);
     $this->view->topicName = $topic->topic_name;
     $this->view->hide = false;
 }
Exemplo n.º 3
0
 /**
  * STAGE 3: Choose, create, and optionally update models using business logic.
  * STAGE 4: Apply business logic to create a presentation model for the view.
  */
 protected function displayStage3_4()
 {
     // ZFDemoModel_Topics provides static methods that auto-instantiate and manage the model
     $this->view->topics = ZFDemoModel_Topics::getPresentationModel();
     $this->view->user = 'anonymous';
     // Controller = 'index', Action = 'index', param name = 'topic'
     $this->view->topicUrl = 'index/index/topic';
     $this->view->hide = false;
     /////////////////////////////
     // ==> SECTION: acl <==
     $role = ZFModule_Forum::getRole();
     // another form of access control (whether or not to show hidden posts)
     $this->view->hide = $role === 'moderator' || $role === 'admin' ? false : true;
 }
Exemplo n.º 4
0
 /**
  * STAGE 3:  Choose, create, and optionally update models using business logic.
  * STAGE 4.  Apply business logic to create a presentation model for the view.
  */
 protected function displayStage3_4()
 {
     // the posts and topics models auto-instantiate themselves, as needed (STAGE 3)
     $this->view->posts = ZFDemoModel_Posts::getPostsByTopicId($this->topicId);
     $this->view->topicId = $this->topicId;
     // the posts and topics models auto-instantiate themselves, as needed (STAGE 3)
     $topic = ZFDemoModel_Topics::getPresentationModelByTopicId($this->topicId);
     $this->view->topicName = $topic->topic_name;
     $this->view->hide = false;
     /////////////////////////////
     // ==> SECTION: acl <==
     $role = ZFModule_Forum::getRole();
     // another form of access control (whether or not to show hidden posts)
     $this->view->hide = $role === 'moderator' || $role === 'admin' ? false : true;
 }
Exemplo n.º 5
0
 /**
  * STAGE 3: Choose, create, and optionally update models using business logic.
  * STAGE 4: Apply business logic to create a presentation model for the view.
  */
 public function editAction()
 {
     $config = Zend_Registry::get('config');
     // application-wide configuration ini
     if ($config->db->modelSet === 'pdo') {
         $this->renderToSegment('body', 'addedInSectionDb');
         // initiate STAGE 6 in the view template
     }
     /////////////////////////////
     // ==> SECTION: db <==
     // ZFDemoModel_Topics provides static methods that auto-instantiate and manage the model
     $topics = ZFDemoModel_Topics::getDomainModel();
     $deletedRows = array();
     // list of deleted topics indexed by topic id
     $visible = array();
     // visibility settings indexed by topic id
     $changedRows = array();
     // list of altered topic rows
     ZFDemo_Log::log(_('INFO BEGIN editAction()'));
     try {
         // iterate over the form variable, queing actions for each change requested
         foreach ($_POST as $var => $val) {
             if (!strncmp($var, 'delete', 6)) {
                 $id = intval(substr($var, 6));
                 if (isset($topics[$id])) {
                     $deletedRows[$id] = $topics[$id];
                     ZFDemo_Log::log(_('INFO deleting topic id #%1$d', $id));
                 }
             } elseif (!strncmp($var, 'visible', 7)) {
                 $id = intval(substr($var, 7));
                 if (isset($topics[$id])) {
                     $visible[$id] = 1;
                     // ask Zend_Db_Table_Row to delete itself
                 }
             }
         }
         // for every topic, make sure visibility setting matches the selections submitted via the form
         foreach ($topics as $id => $row) {
             if (!isset($deletedRows[$id])) {
                 // don't update a row that will be deleted
                 if (!isset($visible[$id])) {
                     // the checkbox for visibility of this topic was not checked
                     $visible[$id] = 0;
                     // web interface defaults to checking visible topics, so unchecked means not visible
                 }
                 if ($row->is_visible != $visible[$id]) {
                     ZFDemo_Log::log(_('INFO topic id %1$d visibility set to %2$d', $id, $visible[$id]));
                     $row->is_visible = $visible[$id];
                     $changedRows[$id] = $row;
                     // add this row to the list of changed rows
                 }
             }
         }
         // now commit changes to DB
         $registry = Zend_Registry::getInstance();
         if (!$registry['config']->db->transactions) {
             // note: query aggregation would help performance (reader excercise)
             foreach ($deletedRows as $row) {
                 $row->delete();
                 // now do all the deletes at once
             }
             foreach ($changedRows as $row) {
                 $row->save();
                 // now synchronize all the modified rows with the table
             }
         } else {
             // table type supports transactions
             $db = $registry['db'];
             $db->beginTransaction();
             try {
                 // note: query aggregation would help performance (reader excercise)
                 foreach ($deletedRows as $row) {
                     $row->delete();
                     // now do all the deletes at once
                 }
                 foreach ($changedRows as $row) {
                     $row->save();
                     // now synchronize all the modified rows with the table
                 }
                 $db->commit();
             } catch (Exception $exception) {
                 $db->rollBack();
                 // re-throw the exception
                 throw $exception;
                 // allow normal processing by the preDispatch() of the plugin in bootstrap.php
             }
         }
     } catch (Exception $exception) {
         ZFDemo_Log::log(_('ERROR END editAction() - failed'));
         throw $exception;
         // resume normal processing of the exception
     }
     ZFDemo_Log::log(_('NOTICE END editAction() - succeeded'));
     // Controller = 'index', Action = 'index'
     $this->setRedirectCode(303);
     // PRG pattern via http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
     $this->_redirect('forum/admin_topics');
 }