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

getFirstChildId() public static method

Get the first child for a given parent
public static getFirstChildId ( integer $pageId ) : mixed
$pageId integer The Id of the page to get the first child for.
return mixed
    public static function getFirstChildId($pageId)
    {
        // redefine
        $pageId = (int) $pageId;
        // get child
        $childId = (int) BackendModel::getContainer()->get('database')->getVar('SELECT i.id
             FROM pages AS i
             WHERE i.parent_id = ? AND i.status = ? AND i.language = ?
             ORDER BY i.sequence ASC
             LIMIT 1', array($pageId, 'active', BL::getWorkingLanguage()));
        // return
        if ($childId != 0) {
            return $childId;
        }
        // fallback
        return false;
    }

Usage Example

Example #1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendPagesModel::exists($this->id)) {
         // call parent, this will probably add some general CSS/JS or other required files
         parent::execute();
         // init var
         $success = false;
         // cannot have children
         if (BackendPagesModel::getFirstChildId($this->id) !== false) {
             $this->redirect(BackendModel::createURLForAction('Edit') . '&error=non-existing');
         }
         $revisionId = $this->getParameter('revision_id', 'int');
         if ($revisionId == 0) {
             $revisionId = null;
         }
         // get page (we need the title)
         $page = BackendPagesModel::get($this->id, $revisionId);
         // valid page?
         if (!empty($page)) {
             // delete the page
             $success = BackendPagesModel::delete($this->id, null, $revisionId);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id));
             // delete search indexes
             BackendSearchModel::removeIndex($this->getModule(), $this->id);
             // build cache
             BackendPagesModel::buildCache(BL::getWorkingLanguage());
         }
         // page is deleted, so redirect to the overview
         if ($success) {
             $this->redirect(BackendModel::createURLForAction('Index') . '&id=' . $page['parent_id'] . '&report=deleted&var=' . rawurlencode($page['title']));
         } else {
             $this->redirect(BackendModel::createURLForAction('Edit') . '&error=non-existing');
         }
     } else {
         $this->redirect(BackendModel::createURLForAction('Edit') . '&error=non-existing');
     }
 }
All Usage Examples Of Backend\Modules\Pages\Engine\Model::getFirstChildId