Frontend\Modules\Blog\Engine\Model::getRevision PHP Method

getRevision() public static method

Get a revision for an item
public static getRevision ( string $url, integer $revision ) : array
$url string The URL for the item to get.
$revision integer The revisionID.
return array
    public static function getRevision($url, $revision)
    {
        $return = (array) FrontendModel::getContainer()->get('database')->getRecord('SELECT i.id, i.revision_id, i.language, i.title, i.introduction, i.text, i.image,
             c.title AS category_title, m2.url AS category_url,
             UNIX_TIMESTAMP(i.publish_on) AS publish_on, i.user_id,
             i.allow_comments,
             m.keywords AS meta_keywords, m.keywords_overwrite AS meta_keywords_overwrite,
             m.description AS meta_description, m.description_overwrite AS meta_description_overwrite,
             m.title AS meta_title, m.title_overwrite AS meta_title_overwrite,
             m.url,
             m.data AS meta_data
             FROM blog_posts AS i
             INNER JOIN blog_categories AS c ON i.category_id = c.id
             INNER JOIN meta AS m ON i.meta_id = m.id
             INNER JOIN meta AS m2 ON c.meta_id = m2.id
             WHERE i.language = ? AND i.revision_id = ? AND m.url = ?
             LIMIT 1', array(LANGUAGE, (int) $revision, (string) $url));
        // unserialize
        if (isset($return['meta_data'])) {
            $return['meta_data'] = @unserialize($return['meta_data']);
        }
        // image?
        if (isset($return['image'])) {
            $folders = FrontendModel::getThumbnailFolders(FRONTEND_FILES_PATH . '/Blog/Images', true);
            foreach ($folders as $folder) {
                $return['image_' . $folder['dirname']] = $folder['url'] . '/' . $folder['dirname'] . '/' . $return['image'];
            }
        }
        // return
        return $return;
    }

Usage Example

Example #1
0
 /**
  * Load the data, don't forget to validate the incoming data
  */
 private function getData()
 {
     // validate incoming parameters
     if ($this->URL->getParameter(1) === null) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // load revision
     if ($this->URL->getParameter('revision', 'int') != 0) {
         // get data
         $this->record = FrontendBlogModel::getRevision($this->URL->getParameter(1), $this->URL->getParameter('revision', 'int'));
         // add no-index, so the draft won't get accidentally indexed
         $this->header->addMetaData(array('name' => 'robots', 'content' => 'noindex, nofollow'), true);
     } else {
         // get by URL
         $this->record = FrontendBlogModel::get($this->URL->getParameter(1));
     }
     // anything found?
     if (empty($this->record)) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // get comments
     $this->comments = FrontendBlogModel::getComments($this->record['id']);
     // get tags
     $this->record['tags'] = FrontendTagsModel::getForItem('Blog', $this->record['id']);
     // get settings
     $this->settings = $this->get('fork.settings')->getForModule('Blog');
     // overwrite URLs
     $this->record['category_full_url'] = FrontendNavigation::getURLForBlock('Blog', 'Category') . '/' . $this->record['category_url'];
     $this->record['full_url'] = FrontendNavigation::getURLForBlock('Blog', 'Detail') . '/' . $this->record['url'];
     $this->record['allow_comments'] = $this->record['allow_comments'] == 'Y';
     $this->record['comments_count'] = count($this->comments);
     // reset allow comments
     if (!$this->settings['allow_comments']) {
         $this->record['allow_comments'] = false;
     }
 }