Backend\Modules\Pages\Engine\Model::getBlocks PHP Method

getBlocks() public static method

Get blocks for a certain page/revision
public static getBlocks ( integer $id, integer $revisionId = null, string $language = null ) : array
$id integer The id of the page.
$revisionId integer The revision to grab.
$language string The language to use.
return array
    public static function getBlocks($id, $revisionId = null, $language = null)
    {
        // fetch revision if not specified
        if ($revisionId === null) {
            $revisionId = self::getLatestRevision($id, $language);
        }
        // redefine
        $id = (int) $id;
        $revisionId = (int) $revisionId;
        $language = $language === null ? BL::getWorkingLanguage() : (string) $language;
        // get page (active version)
        return (array) BackendModel::getContainer()->get('database')->getRecords('SELECT b.*, UNIX_TIMESTAMP(b.created_on) AS created_on, UNIX_TIMESTAMP(b.edited_on) AS edited_on
             FROM pages_blocks AS b
             INNER JOIN pages AS i ON b.revision_id = i.revision_id
                WHERE i.id = ? AND i.revision_id = ? AND i.language = ?
                ORDER BY b.sequence ASC', array($id, $revisionId, $language));
    }

Usage Example

Example #1
0
 /**
  * Load the record
  */
 private function loadData()
 {
     // get record
     $this->id = $this->getParameter('id', 'int');
     $this->isGod = BackendAuthentication::getUser()->isGod();
     // check if something went wrong
     if ($this->id === null || !BackendPagesModel::exists($this->id)) {
         $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing');
     }
     // get the record
     $this->record = BackendPagesModel::get($this->id);
     // load blocks
     $this->blocksContent = BackendPagesModel::getBlocks($this->id, $this->record['revision_id']);
     // is there a revision specified?
     $revisionToLoad = $this->getParameter('revision', 'int');
     // if this is a valid revision
     if ($revisionToLoad !== null) {
         // overwrite the current record
         $this->record = (array) BackendPagesModel::get($this->id, $revisionToLoad);
         // load blocks
         $this->blocksContent = BackendPagesModel::getBlocks($this->id, $revisionToLoad);
         // show warning
         $this->tpl->assign('appendRevision', true);
     }
     // is there a revision specified?
     $draftToLoad = $this->getParameter('draft', 'int');
     // if this is a valid revision
     if ($draftToLoad !== null) {
         // overwrite the current record
         $this->record = (array) BackendPagesModel::get($this->id, $draftToLoad);
         // load blocks
         $this->blocksContent = BackendPagesModel::getBlocks($this->id, $draftToLoad);
         // show warning
         $this->tpl->assign('appendRevision', true);
     }
     // reset some vars
     $this->record['full_url'] = BackendPagesModel::getFullURL($this->record['id']);
     $this->record['is_hidden'] = $this->record['hidden'] == 'Y';
 }