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

get() public static method

Get the data for a record
public static get ( integer $id, integer $revisionId = null, string $language = null ) : mixed
$id integer The Id of the page to fetch.
$revisionId integer
$language string The language to use while fetching the page.
return mixed False if the record can't be found, otherwise an array with all data.
    public static function get($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')->getRecord('SELECT i.*, UNIX_TIMESTAMP(i.publish_on) AS publish_on, UNIX_TIMESTAMP(i.created_on) AS created_on,
                UNIX_TIMESTAMP(i.edited_on) AS edited_on,
             IF(COUNT(e.id) > 0, "Y", "N") AS has_extra,
             GROUP_CONCAT(b.extra_id) AS extra_ids
             FROM pages AS i
             LEFT OUTER JOIN pages_blocks AS b ON b.revision_id = i.revision_id AND b.extra_id IS NOT NULL
             LEFT OUTER JOIN modules_extras AS e ON e.id = b.extra_id AND e.type = ?
             WHERE i.id = ? AND i.revision_id = ? AND i.language = ?
             GROUP BY i.revision_id', array('block', $id, $revisionId, $language));
        // no page?
        if (empty($return)) {
            return false;
        }
        // can't be deleted
        if (in_array($return['id'], array(1, 404))) {
            $return['allow_delete'] = 'N';
        }
        // can't be moved
        if (in_array($return['id'], array(1, 404))) {
            $return['allow_move'] = 'N';
        }
        // can't have children
        if (in_array($return['id'], array(404))) {
            $return['allow_move'] = 'N';
        }
        // convert into bools for use in template engine
        $return['move_allowed'] = (bool) ($return['allow_move'] == 'Y');
        $return['children_allowed'] = (bool) ($return['allow_children'] == 'Y');
        $return['edit_allowed'] = (bool) ($return['allow_edit'] == 'Y');
        $return['delete_allowed'] = (bool) ($return['allow_delete'] == 'Y');
        // unserialize data
        if ($return['data'] !== null) {
            $return['data'] = unserialize($return['data']);
        }
        // return
        return $return;
    }

Usage Example

Example #1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // call parent
     parent::execute();
     // get parameters
     $id = \SpoonFilter::getPostValue('id', null, 0, 'int');
     // validate
     if ($id === 0) {
         $this->output(self::BAD_REQUEST, null, 'no id provided');
     } else {
         // get page
         $page = BackendPagesModel::get($id);
         // output
         $this->output(self::OK, $page);
     }
 }
All Usage Examples Of Backend\Modules\Pages\Engine\Model::get