Example #1
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     $objFaq = \FaqModel::findPublishedByPids($this->faq_categories);
     if ($objFaq === null) {
         $this->Template->faq = array();
         return;
     }
     $arrFaq = array_fill_keys($this->faq_categories, array());
     // Add FAQs
     while ($objFaq->next()) {
         $arrTemp = $objFaq->row();
         $arrTemp['title'] = \StringUtil::specialchars($objFaq->question, true);
         $arrTemp['href'] = $this->generateFaqLink($objFaq);
         /** @var FaqCategoryModel $objPid */
         $objPid = $objFaq->getRelated('pid');
         $arrFaq[$objFaq->pid]['items'][] = $arrTemp;
         $arrFaq[$objFaq->pid]['headline'] = $objPid->headline;
         $arrFaq[$objFaq->pid]['title'] = $objPid->title;
     }
     $arrFaq = array_values(array_filter($arrFaq));
     $cat_count = 0;
     $cat_limit = count($arrFaq);
     // Add classes
     foreach ($arrFaq as $k => $v) {
         $count = 0;
         $limit = count($v['items']);
         for ($i = 0; $i < $limit; $i++) {
             $arrFaq[$k]['items'][$i]['class'] = trim((++$count == 1 ? ' first' : '') . ($count >= $limit ? ' last' : '') . ($count % 2 == 0 ? ' odd' : ' even'));
         }
         $arrFaq[$k]['class'] = trim((++$cat_count == 1 ? ' first' : '') . ($cat_count >= $cat_limit ? ' last' : '') . ($cat_count % 2 == 0 ? ' odd' : ' even'));
     }
     $this->Template->faq = $arrFaq;
 }
Example #2
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     $objFaq = \FaqModel::findPublishedByPids($this->faq_categories);
     if ($objFaq === null) {
         $this->Template->faq = array();
         return;
     }
     /** @var PageModel $objPage */
     global $objPage;
     $arrFaqs = array_fill_keys($this->faq_categories, array());
     // Add FAQs
     while ($objFaq->next()) {
         /** @var FaqModel $objFaq */
         $objTemp = (object) $objFaq->row();
         // Clean the RTE output
         $objTemp->answer = \StringUtil::toHtml5($objFaq->answer);
         $objTemp->answer = \StringUtil::encodeEmail($objTemp->answer);
         $objTemp->addImage = false;
         // Add an image
         if ($objFaq->addImage && $objFaq->singleSRC != '') {
             $objModel = \FilesModel::findByUuid($objFaq->singleSRC);
             if ($objModel !== null && is_file(TL_ROOT . '/' . $objModel->path)) {
                 // Do not override the field now that we have a model registry (see #6303)
                 $arrFaq = $objFaq->row();
                 $arrFaq['singleSRC'] = $objModel->path;
                 $strLightboxId = 'lightbox[' . substr(md5('mod_faqpage_' . $objFaq->id), 0, 6) . ']';
                 // see #5810
                 $this->addImageToTemplate($objTemp, $arrFaq, null, $strLightboxId);
             }
         }
         $objTemp->enclosure = array();
         // Add enclosure
         if ($objFaq->addEnclosure) {
             $this->addEnclosuresToTemplate($objTemp, $objFaq->row());
         }
         /** @var UserModel $objAuthor */
         $objAuthor = $objFaq->getRelated('author');
         $objTemp->info = sprintf($GLOBALS['TL_LANG']['MSC']['faqCreatedBy'], \Date::parse($objPage->dateFormat, $objFaq->tstamp), $objAuthor->name);
         /** @var FaqCategoryModel $objPid */
         $objPid = $objFaq->getRelated('pid');
         // Order by PID
         $arrFaqs[$objFaq->pid]['items'][] = $objTemp;
         $arrFaqs[$objFaq->pid]['headline'] = $objPid->headline;
         $arrFaqs[$objFaq->pid]['title'] = $objPid->title;
     }
     $arrFaqs = array_values(array_filter($arrFaqs));
     $limit_i = count($arrFaqs) - 1;
     // Add classes first, last, even and odd
     for ($i = 0; $i <= $limit_i; $i++) {
         $class = ($i == 0 ? 'first ' : '') . ($i == $limit_i ? 'last ' : '') . ($i % 2 == 0 ? 'even' : 'odd');
         $arrFaqs[$i]['class'] = trim($class);
         $limit_j = count($arrFaqs[$i]['items']) - 1;
         for ($j = 0; $j <= $limit_j; $j++) {
             $class = ($j == 0 ? 'first ' : '') . ($j == $limit_j ? 'last ' : '') . ($j % 2 == 0 ? 'even' : 'odd');
             $arrFaqs[$i]['items'][$j]->class = trim($class);
         }
     }
     $this->Template->faq = $arrFaqs;
     $this->Template->request = \Environment::get('indexFreeRequest');
     $this->Template->topLink = $GLOBALS['TL_LANG']['MSC']['backToTop'];
 }