/** * 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; }
/** * 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]; }