Esempio n. 1
0
 /**
  * This method is responsible for mapping the ZFDemo's authentication ids to forum module authorization ids.
  * Each module can maintain its own set of ids used for authorization,
  * thus allowing integration of diverse modules.
  */
 public static function authenticationId2authorizationId($authenticationId)
 {
     self::loadModels();
     // getByUsername returns null if lookup fails
     if (self::$_user = ZFDemoModel_Users::getByUsername($authenticationId['username'])) {
         self::$_username = self::$_user->username;
         self::$_authorizationId = self::$_user->user_id;
     }
 }
 /**
  * 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 = '******';
     // 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;
 }
 /**
  * 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;
 }
 /**
  * Process a submitted post.
  */
 public function submitFormAction()
 {
     // STAGE 3:  Choose, create, and optionally update models using business logic.
     $topicId = $this->getTopicId();
     require_once 'Zend/Filter/StripTags.php';
     $filter = new Zend_Filter_StripTags();
     // only permit digits using ctype_digit()
     $subject = $filter->filter($_POST['subject']);
     $body = $filter->filter($_POST['body']);
     ZFDemoModel_Posts::submit(ZFModule_Forum::getAuthorizationId(), $topicId, $subject, $body);
     // STAGE 4: Apply business logic to create a presentation model for the view.
     // STAGE 5: Choose view and submit presentation model to view.
     $this->setRedirectCode(303);
     // PRG pattern via http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
     $this->_redirect("/forum/index/index/topic/{$topicId}");
 }
Esempio n. 5
0
 /**
  * Returns the topics table as a presentation model (array of arrays containing
  * information about each topic, suitable for use by a view) by mirroring
  * the domain model into a presentation model.  The presentation model can be modified
  * to support the needs of a view, without mangling the raw, real underlying table data.
  * STAGE 4: Apply business logic to create a presentation model for the view.
  * @return array of ArrayObjects (containing topic info) indexed by topic id
  */
 public static function getPresentationModel()
 {
     if (self::$_presentationModel === null) {
         foreach (self::getDomainModel() as $row) {
             $row = new ArrayObject($row->toArray(), ArrayObject::ARRAY_AS_PROPS);
             $row->user = ZFDemoModel_Users::getById($row->user_id);
             self::$_presentationModel[$row->topic_id] = $row;
             /////////////////////////////
             // ==> SECTION: l10n <==
             // create a Locale object for the owner of this post (not the user of this request)
             $postLocale = new Zend_Locale($row->user->locale);
             $row->country = ZFModule_Forum::getCountry($postLocale->getRegion());
             $userLocale = ZFModule_Forum::getUserLocale();
             // locale of the user of this request
             $userLocale = Zend_Registry::get('userLocale');
             $offset = ZFModule_Forum::getTimeOffset();
             if ($row->modification_time != $row->creation_time) {
                 $row->modification_time = new Zend_Date($row->modification_time, $userLocale);
                 $row->modification_time->addTimestamp($offset);
                 // express date/time in user's local timezone
             } else {
                 $row->modification_time = '';
             }
             $row->creation_time = new Zend_Date($row->creation_time, $userLocale);
             $row->creation_time->addTimestamp($offset);
             // express date/time in user's local timezone
         }
     }
     return self::$_presentationModel;
 }
Esempio n. 6
0
 /**
  * Using a two-letter region code, return the name of the corresponding country,
  * if possible.  Not all region codes map to country names.
  * @param  string  $code  Two-letter country code.
  */
 public static function getCountry($code)
 {
     if (self::$_countries === null) {
         // list of country names in user's language
         self::$_countries = self::$_userLocale->getCountryTranslationList();
         // country code index of current user for array above
     }
     if (isset(self::$_countries[$code])) {
         return self::$_countries[$code];
     }
     return '';
 }
Esempio n. 7
0
 /**
  * Returns the posts of a topic as a presentation model (array of arrays containing
  * information about each post, suitable for use by a view) by mirroring the domain model
  * into a presentation model.  The presentation model can be modified to support
  * the needs of a view, without mangling the raw, real underlying table data.
  * STAGE 4: Apply business logic to create a presentation model for the view.
  * @return array of ArrayObject (post info)
  */
 public static function getPostsByTopicId($topicId)
 {
     if (!isset(self::$_presentationModel[$topicId])) {
         $posts = array();
         foreach (self::getDomainModel($topicId) as $row) {
             $row = new ArrayObject($row->toArray(), ArrayObject::ARRAY_AS_PROPS);
             $row->user = ZFDemoModel_Users::getById($row->user_id);
             $posts[] = $row;
             /////////////////////////////
             // ==> SECTION: l10n <==
             // create a Locale object for the owner of this post (not the user of this request)
             $postLocale = new Zend_Locale($row->user->locale);
             $row->country = ZFModule_Forum::getCountry($postLocale->getRegion());
             $userLocale = ZFModule_Forum::getUserLocale();
             // locale of the user of this request
             $offset = ZFModule_Forum::getTimeOffset();
             if ($row->modification_time != $row->creation_time) {
                 $row->modification_time = new Zend_Date($row->modification_time, $userLocale);
                 $row->modification_time->addTimestamp($offset);
                 // express date/time in user's local timezone
             } else {
                 $row->modification_time = '';
             }
             $row->creation_time = new Zend_Date($row->creation_time, $userLocale);
             $row->creation_time->addTimestamp($offset);
             // express date/time in user's local timezone
         }
         // cache result only for duration of this request
         self::$_presentationModel[$topicId] = $posts;
     }
     return self::$_presentationModel[$topicId];
 }