Esempio n. 1
0
 /**
  * Loads article information for the category (and sub-categories)
  * that the user selected in the slider and returns that to the calling
  * AJAX function.
  */
 public static function updateSliderAjax()
 {
     $input = JFactory::getApplication()->input;
     $categoryId = $input->get('data');
     // Prepare answer array.
     $result = array();
     $result['url'] = JURI::root();
     // -1 represents all categories - fetch all articles in that case.
     if ($categoryId == -1) {
         // Get article info from database.
         $categoryData = modNavSliderHelper::queryDatabase('#__content', 'title, images, alias, publish_up, id, introtext', 'state = 1', 0, 'publish_up DESC');
         // Also parse the images String.
         for ($j = 0; $j < count($categoryData); $j++) {
             $categoryData[$j] += array('image_fulltext' => modNavSliderHelper::parseImageString('image_fulltext', $categoryData[$j]['images']));
             $categoryData[$j] += array('image_intro' => modNavSliderHelper::parseImageString('image_intro', $categoryData[$j]['images']));
         }
         // Otherwise we have a category id.
     } else {
         // Get children categories.
         $ids = array();
         $ids[0] = $categoryId;
         $ids = modNavSliderHelper::getChildrenCategoryIds($ids[0], $ids);
         // Go through all IDs.
         // Concatenate IDs into select string.
         $select_ids = "catid = " . $ids[0];
         for ($i = 1; $i < count($ids); $i++) {
             $select_ids .= " OR catid = " . $ids[$i];
         }
         // Get article info from database.
         $categoryData = modNavSliderHelper::queryDatabase('#__content', 'title, images, alias, publish_up, id, introtext', 'state = 1 AND ' . $select_ids, 0, 'publish_up DESC');
         // Also parse the images String.
         for ($j = 0; $j < count($categoryData); $j++) {
             $categoryData[$j] += array('image_fulltext' => modNavSliderHelper::parseImageString('image_fulltext', $categoryData[$j]['images']));
             $categoryData[$j] += array('image_intro' => modNavSliderHelper::parseImageString('image_intro', $categoryData[$j]['images']));
         }
     }
     // Retrieve tags for articles.
     for ($i = 0; $i < count($categoryData); $i++) {
         $tags = new JHelperTags();
         $tags->getItemTags('com_content.article', $categoryData[$i]['id']);
         $itemTags = $tags->itemTags;
         // itemTags contains all info on the tags - filter out what we need.
         $strippedTags = array();
         for ($j = 0; $j < count($itemTags); $j++) {
             $strippedTags[] = array('title' => $itemTags[$j]->title, 'id' => $itemTags[$j]->id);
         }
         $categoryData[$i] += array('tags' => $strippedTags);
     }
     $result['articles'] = $categoryData;
     return json_encode($result);
 }