Frontend\Core\Engine\Navigation::getFirstChildId PHP Method

getFirstChildId() public static method

Get the first child for a given parent
public static getFirstChildId ( integer $pageId ) : integer
$pageId integer The pageID wherefore we should retrieve the first child.
return integer
    public static function getFirstChildId($pageId)
    {
        $pageId = (int) $pageId;
        // init var
        $navigation = self::getNavigation();
        // loop depths
        foreach ($navigation as $parent) {
            // no available, skip this element
            if (!isset($parent[$pageId])) {
                continue;
            }
            // get keys
            $keys = array_keys($parent[$pageId]);
            // get first item
            if (isset($keys[0])) {
                return $keys[0];
            }
        }
        // fallback
        return false;
    }

Usage Example

Beispiel #1
0
 /**
  * Get page content
  */
 protected function getPageContent()
 {
     // load revision
     if ($this->URL->getParameter('page_revision', 'int') != 0) {
         // get data
         $this->record = Model::getPageRevision($this->URL->getParameter('page_revision', 'int'));
         // add no-index to meta-custom, so the draft won't get accidentally indexed
         $this->header->addMetaData(array('name' => 'robots', 'content' => 'noindex, nofollow'), true);
     } else {
         // get page record
         $this->record = (array) Model::getPage($this->pageId);
     }
     // empty record (pageId doesn't exists, hope this line is never used)
     if (empty($this->record) && $this->pageId != 404) {
         \SpoonHTTP::redirect(Navigation::getURL(404), 404);
     }
     // init var
     $redirect = true;
     // loop blocks, if all are empty we should redirect to the first child
     foreach ($this->record['positions'] as $blocks) {
         // loop blocks in position
         foreach ($blocks as $block) {
             // HTML provided?
             if ($block['html'] != '') {
                 $redirect = false;
             }
             // an decent extra provided?
             if ($block['extra_type'] == 'block') {
                 $redirect = false;
             }
             // a widget provided
             if ($block['extra_type'] == 'widget') {
                 $redirect = false;
             }
         }
     }
     // should we redirect?
     if ($redirect) {
         // get first child
         $firstChildId = Navigation::getFirstChildId($this->record['id']);
         // validate the child
         if ($firstChildId !== false) {
             // build URL
             $URL = Navigation::getURL($firstChildId);
             // redirect
             \SpoonHTTP::redirect($URL, 301);
         }
     }
 }
All Usage Examples Of Frontend\Core\Engine\Navigation::getFirstChildId