Contao\ArticleModel::findPublishedByPidAndColumn PHP Method

findPublishedByPidAndColumn() public static method

Find all published articles by their parent ID and column
public static findPublishedByPidAndColumn ( 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
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 findPublishedByPidAndColumn($intPid, $strColumn, array $arrOptions = array())
    {
        $t = static::$strTable;
        $arrColumns = array("{$t}.pid=? AND {$t}.inColumn=?");
        $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

Esempio n. 1
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var PageModel $objPage */
     global $objPage;
     if (!strlen($this->inColumn)) {
         $this->inColumn = 'main';
     }
     $intCount = 0;
     $articles = array();
     $id = $objPage->id;
     $this->Template->request = \Environment::get('request');
     // Show the articles of a different page
     if ($this->defineRoot && $this->rootPage > 0) {
         if (($objTarget = $this->objModel->getRelated('rootPage')) !== null) {
             $id = $objTarget->id;
             $this->Template->request = $this->generateFrontendUrl($objTarget->row());
         }
     }
     // Get published articles
     $objArticles = \ArticleModel::findPublishedByPidAndColumn($id, $this->inColumn);
     if ($objArticles === null) {
         return;
     }
     while ($objArticles->next()) {
         // Skip first article
         if (++$intCount <= intval($this->skipFirst)) {
             continue;
         }
         $cssID = deserialize($objArticles->cssID, true);
         $articles[] = array('link' => $objArticles->title, 'title' => specialchars($objArticles->title), 'id' => $cssID[0] ?: 'article-' . $objArticles->id, 'articleId' => $objArticles->id);
     }
     $this->Template->articles = $articles;
 }
All Usage Examples Of Contao\ArticleModel::findPublishedByPidAndColumn