Contao\ArticleModel::findPublishedWithTeaserByPidAndColumn PHP Метод

findPublishedWithTeaserByPidAndColumn() публичный статический Метод

Find all published articles with teaser by their parent ID and column
public static findPublishedWithTeaserByPidAndColumn ( integer $intPid, string $strColumn, array $arrOptions = [] ) : Collection | ArticleModel[] | ArticleModel | null
$intPid integer The page ID
$strColumn string The column name
$arrOptions array An optional options array
Результат Contao\Model\Collection | ArticleModel[] | ArticleModel | null A collection of models or null if there are no articles in the given column
    public static function findPublishedWithTeaserByPidAndColumn($intPid, $strColumn, array $arrOptions = array())
    {
        $t = static::$strTable;
        $arrColumns = array("{$t}.pid=? AND {$t}.inColumn=? AND {$t}.showTeaser=1");
        $arrValues = array($intPid, $strColumn);
        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, $arrValues, $arrOptions);
    }

Usage Example

Пример #1
0
 /**
  * Do not display the module if there are no articles
  *
  * @return string
  */
 public function generate()
 {
     if (TL_MODE == 'BE') {
         /** @var BackendTemplate|object $objTemplate */
         $objTemplate = new \BackendTemplate('be_wildcard');
         $objTemplate->wildcard = '### ' . Utf8::strtoupper($GLOBALS['TL_LANG']['FMD']['articlenav'][0]) . ' ###';
         $objTemplate->title = $this->headline;
         $objTemplate->id = $this->id;
         $objTemplate->link = $this->name;
         $objTemplate->href = 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' . $this->id;
         return $objTemplate->parse();
     }
     /** @var PageModel $objPage */
     global $objPage;
     $this->objArticles = \ArticleModel::findPublishedWithTeaserByPidAndColumn($objPage->id, $this->strColumn);
     // Return if there are no articles
     if ($this->objArticles === null) {
         return '';
     }
     // Redirect to the first article if no article is selected
     if (!\Input::get('articles')) {
         if (!$this->loadFirst) {
             return '';
         }
         /** @var ArticleModel $objArticle */
         $objArticle = $this->objArticles->current();
         $strAlias = $objArticle->alias ?: $objArticle->id;
         $this->redirect($this->generateFrontendUrl($objPage->row(), '/articles/' . $strAlias));
     }
     return parent::generate();
 }