Contao\ArticleModel::findPublishedWithTeaserByPid PHP Method

findPublishedWithTeaserByPid() public static method

Find all published articles with teaser by their parent ID
public static findPublishedWithTeaserByPid ( integer $intPid, array $arrOptions = [] ) : Collection | ArticleModel[] | ArticleModel | null
$intPid integer The page ID
$arrOptions array An optional options array
return Contao\Model\Collection | ArticleModel[] | ArticleModel | null A collection of models or null if there are no articles in the given column
    public static function findPublishedWithTeaserByPid($intPid, array $arrOptions = array())
    {
        $t = static::$strTable;
        $arrColumns = array("{$t}.pid=? AND {$t}.showTeaser=1");
        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'] = "{$t}.sorting";
        }
        return static::findBy($arrColumns, $intPid, $arrOptions);
    }

Usage Example

Esempio n. 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;
 }