findPublishedByPid() public static method

Find published pages by their PID
public static findPublishedByPid ( integer $intPid, array $arrOptions = [] ) : Collection | PageModel[] | PageModel | null
$intPid integer The parent ID
$arrOptions array An optional options array
return Contao\Model\Collection | PageModel[] | PageModel | null A collection of models or null if there are no pages
Beispiel #1
0
 /**
  * Get all searchable pages and return them as array
  *
  * @param integer $pid
  * @param string  $domain
  * @param boolean $blnIsSitemap
  *
  * @return array
  */
 public static function findSearchablePages($pid = 0, $domain = '', $blnIsSitemap = false)
 {
     $objPages = \PageModel::findPublishedByPid($pid, array('ignoreFePreview' => true));
     if ($objPages === null) {
         return array();
     }
     $arrPages = array();
     // Recursively walk through all subpages
     foreach ($objPages as $objPage) {
         if ($objPage->type == 'regular') {
             // Searchable and not protected
             if ((!$objPage->noSearch || $blnIsSitemap) && (!$objPage->protected || \Config::get('indexProtected') && (!$blnIsSitemap || $objPage->sitemap == 'map_always')) && (!$blnIsSitemap || $objPage->sitemap != 'map_never')) {
                 $arrPages[] = $objPage->getAbsoluteUrl();
                 // Get articles with teaser
                 if (($objArticles = \ArticleModel::findPublishedWithTeaserByPid($objPage->id, array('ignoreFePreview' => true))) !== null) {
                     foreach ($objArticles as $objArticle) {
                         $arrPages[] = $objPage->getAbsoluteUrl('/articles/' . ($objArticle->alias ?: $objArticle->id));
                     }
                 }
             }
         }
         // Get subpages
         if ((!$objPage->protected || \Config::get('indexProtected')) && ($arrSubpages = static::findSearchablePages($objPage->id, $domain, $blnIsSitemap))) {
             $arrPages = array_merge($arrPages, $arrSubpages);
         }
     }
     return $arrPages;
 }