Contao\PageModel::findPublishedRegularWithoutGuestsByIds PHP Method

findPublishedRegularWithoutGuestsByIds() public static method

Find all published regular pages by their IDs and exclude pages only visible for guests
public static findPublishedRegularWithoutGuestsByIds ( integer $arrIds, array $arrOptions = [] ) : Collection | PageModel[] | PageModel | null
$arrIds integer An array of page IDs
$arrOptions array An optional options array
return Contao\Model\Collection | PageModel[] | PageModel | null A collection of models or null if there are no pages
    public static function findPublishedRegularWithoutGuestsByIds($arrIds, array $arrOptions = array())
    {
        if (!is_array($arrIds) || empty($arrIds)) {
            return null;
        }
        $t = static::$strTable;
        $arrColumns = array("{$t}.id IN(" . implode(',', array_map('intval', $arrIds)) . ") AND {$t}.type!='root' AND {$t}.type!='error_403' AND {$t}.type!='error_404'");
        if (FE_USER_LOGGED_IN) {
            $arrColumns[] = "{$t}.guests=''";
        }
        if (isset($arrOptions['ignoreFePreview']) || !BE_USER_LOGGED_IN) {
            $time = \Date::floorToMinute();
            $arrColumns[] = "({$t}.start='' OR {$t}.start<='{$time}') AND ({$t}.stop='' OR {$t}.stop>'" . ($time + 60) . "') AND {$t}.published='1'";
        }
        if (!isset($arrOptions['order'])) {
            $arrOptions['order'] = \Database::getInstance()->findInSet("{$t}.id", $arrIds);
        }
        return static::findBy($arrColumns, null, $arrOptions);
    }

Usage Example

Example #1
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     // Get all active pages
     $objPages = \PageModel::findPublishedRegularWithoutGuestsByIds($this->pages);
     // Return if there are no pages
     if ($objPages === null) {
         return;
     }
     $arrPages = array();
     // Sort the array keys according to the given order
     if ($this->orderPages != '') {
         $tmp = deserialize($this->orderPages);
         if (!empty($tmp) && is_array($tmp)) {
             $arrPages = array_map(function () {
             }, array_flip($tmp));
         }
     }
     // Add the items to the pre-sorted array
     while ($objPages->next()) {
         /** @var PageModel $objModel */
         $objModel = $objPages->current();
         $arrPages[$objPages->id] = $objModel->loadDetails()->row();
         // see #3765
     }
     $items = array();
     foreach ($arrPages as $arrPage) {
         $arrPage['title'] = strip_insert_tags($arrPage['title']);
         $arrPage['pageTitle'] = strip_insert_tags($arrPage['pageTitle']);
         // Get href
         switch ($arrPage['type']) {
             case 'redirect':
                 $href = $arrPage['url'];
                 break;
             case 'forward':
                 if (($objNext = \PageModel::findPublishedById($arrPage['jumpTo'])) !== null) {
                     $strForceLang = null;
                     $objNext->loadDetails();
                     // Check the target page language (see #4706)
                     if (\Config::get('addLanguageToUrl')) {
                         $strForceLang = $objNext->language;
                     }
                     $href = $this->generateFrontendUrl($objNext->row(), null, $strForceLang, true);
                     break;
                 }
                 // DO NOT ADD A break; STATEMENT
             // DO NOT ADD A break; STATEMENT
             default:
                 $href = $this->generateFrontendUrl($arrPage, null, $arrPage['rootLanguage'], true);
                 break;
         }
         $items[] = array('href' => $href, 'title' => specialchars($arrPage['pageTitle'] ?: $arrPage['title']), 'link' => $arrPage['title']);
     }
     $this->Template->items = $items;
     $this->Template->formId = 'tl_quicklink_' . $this->id;
     $this->Template->request = ampersand(\Environment::get('request'), true);
     $this->Template->title = $this->customLabel ?: $GLOBALS['TL_LANG']['MSC']['quicklink'];
     $this->Template->button = specialchars($GLOBALS['TL_LANG']['MSC']['go']);
 }
All Usage Examples Of Contao\PageModel::findPublishedRegularWithoutGuestsByIds