/**
  * Generate the module
  */
 protected function compile()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     $intActive = null;
     $articles = array();
     $intCount = 1;
     while ($this->objArticles->next()) {
         /** @var \ArticleModel $objArticle */
         $objArticle = $this->objArticles->current();
         $strAlias = $objArticle->alias != '' && !\Config::get('disableAlias') ? $objArticle->alias : $objArticle->id;
         // Active article
         if (\Input::get('articles') == $strAlias) {
             $articles[] = array('isActive' => true, 'href' => $this->generateFrontendUrl($objPage->row(), '/articles/' . $strAlias), 'title' => specialchars($objArticle->title, true), 'link' => $intCount);
             $intActive = $intCount - 1;
         } else {
             $articles[] = array('isActive' => false, 'href' => $this->generateFrontendUrl($objPage->row(), '/articles/' . $strAlias), 'title' => specialchars($objArticle->title, true), 'link' => $intCount);
         }
         ++$intCount;
     }
     $this->Template->articles = $articles;
     $total = count($articles);
     // Link to first element
     if ($intActive > 1) {
         $this->Template->first = array('href' => $articles[0]['href'], 'title' => $articles[0]['title'], 'link' => $GLOBALS['TL_LANG']['MSC']['first']);
     }
     $key = $intActive - 1;
     // Link to previous element
     if ($intCount > 1 && $key >= 0) {
         $this->Template->previous = array('href' => $articles[$key]['href'], 'title' => $articles[$key]['title'], 'link' => $GLOBALS['TL_LANG']['MSC']['previous']);
     }
     $key = $intActive + 1;
     // Link to next element
     if ($intCount > 1 && $key < $total) {
         $this->Template->next = array('href' => $articles[$key]['href'], 'title' => $articles[$key]['title'], 'link' => $GLOBALS['TL_LANG']['MSC']['next']);
     }
     $key = $total - 1;
     // Link to last element
     if ($intCount > 1 && $intActive < $key - 1) {
         $this->Template->last = array('href' => $articles[$key]['href'], 'title' => $articles[$key]['title'], 'link' => $GLOBALS['TL_LANG']['MSC']['last']);
     }
 }
 /**
  * Add a model to a collection
  *
  * @param \Model                 $objModel
  * @param \Model\Collection|null $objCollection
  *
  * @return \Model\Collection|null
  */
 public static function addModelToCollection(\Model $objModel, \Model\Collection $objCollection = null)
 {
     $arrRegistered = array();
     if ($objCollection !== null) {
         while ($objCollection->next()) {
             if ($objCollection->getTable() !== $objModel->getTable) {
                 return $objCollection;
             }
             $intId = $objCollection->{$objModel::getPk()};
             $arrRegistered[$intId] = $objCollection->current();
         }
     }
     $arrRegistered[$objModel->{$objModel::getPk()}] = $objModel;
     return static::createCollection(array_filter(array_values($arrRegistered)), $objModel->getTable());
 }
 public static function parseCredits(\Model\Collection $objModels, array $arrPids = array(), $objModule)
 {
     $arrCredits = array();
     while ($objModels->next()) {
         if (($strReturn = static::parseCredit($objModels->current(), $arrPids, $objModule)) === null) {
             continue;
         }
         $arrCredits[] = $strReturn;
     }
     $arrCredits = static::sortCredits($arrCredits, $objModule->creditsSortBy);
     $arrCredits = static::groupCredits($arrCredits, $objModule->creditsGroupBy);
     $arrCredits = array_map(function ($value) use(&$arrCredit) {
         return $value['output'];
     }, $arrCredits);
     return $arrCredits;
 }
Example #4
0
 /**
  * Parse one or more items and return them as array
  *
  * @param \Model\Collection $objArticles
  * @param boolean           $blnAddArchive
  *
  * @return array
  */
 protected function parseArticles($objArticles, $blnAddArchive = false)
 {
     $limit = $objArticles->count();
     if ($limit < 1) {
         return array();
     }
     $count = 0;
     $arrArticles = array();
     while ($objArticles->next()) {
         /** @var \NewsModel $objArticle */
         $objArticle = $objArticles->current();
         $arrArticles[] = $this->parseArticle($objArticle, $blnAddArchive, (++$count == 1 ? ' first' : '') . ($count == $limit ? ' last' : '') . ($count % 2 == 0 ? ' odd' : ' even'), $count);
     }
     return $arrArticles;
 }
 protected static function indexFiles(\Model\Collection $objFiles)
 {
     $blnCheck = true;
     while ($objFiles->next()) {
         $return = static::indexFile($objFiles->current());
         $blnCheck = !$blnCheck ?: $return;
     }
     return $blnCheck;
 }