コード例 #1
0
ファイル: category.php プロジェクト: RangerWalt/ecci
 /**
  * Method to get data from database
  * @param int $display_subcat_page
  * @param int $display_back_button
  * @return array Data
  */
 function getData($display_subcat_page = 0, $display_back_button = 1, $display_categories_back_button = 1, $display_access_category = 1, $display_unpublished = 0)
 {
     $menu =& JSite::getMenu();
     $user =& JFactory::getUser();
     // SET BACK BUTTON TO CATEGORIES VIEW
     $items = $menu->getItems('link', 'index.php?option=com_phocagallery&view=categories');
     $itemId = 0;
     if (isset($items[0])) {
         $itemId = $items[0]->id;
     }
     $backLink = 'index.php?option=com_phocagallery&view=categories&Itemid=' . $itemId;
     // Lets load the content if it doesn't already exist
     if (empty($this->_data)) {
         $count = 0;
         // ----------------------------------------
         // Super folders
         // ----------------------------------------
         $parentcategory = $this->_getParentCategory();
         if ($display_back_button == 1) {
             if ($parentcategory) {
                 $this->_data[$count] = $parentcategory;
                 $item =& $this->_data[$count];
                 // USER RIGHT - ACCESS =======================================
                 // Should be the link to parentcategory displayed
                 $rightDisplay = PhocaGalleryHelper::getUserRight($parentcategory->params, 'accessuserid', $item->access, $user->get('aid', 0), $user->get('id', 0), $display_access_category);
                 // Display Key Icon (in case we want to display unaccessable categories in list view)
                 $rightDisplayKey = 1;
                 if ($display_access_category == 1) {
                     // we simulate that we want not to display unaccessable categories
                     // so we get rightDisplayKey = 0 then the key will be displayed
                     if (isset($parentcategory->params)) {
                         $rightDisplayKey = PhocaGalleryHelper::getUserRight($parentcategory->params, 'accessuserid', $item->access, $user->get('aid', 0), $user->get('id', 0), 0);
                     }
                 }
                 // ===========================================================
                 if ($rightDisplay > 0) {
                     $item->slug = $item->id . ':' . $item->alias;
                     $item->item_type = "parentfolder";
                     $file_thumbnail = PhocaGalleryHelperFront::displayBackFolder('medium', $rightDisplayKey);
                     $item->linkthumbnailpath = $file_thumbnail['rel'];
                     $count++;
                 }
             } else {
                 // Back button to categories list if it exists
                 if ($itemId > 0 && $display_categories_back_button == 1) {
                     $this->_data[$count] = new JObject();
                     $item =& $this->_data[$count];
                     $item->link = $backLink;
                     $item->title = JTEXT::_('Category List');
                     $item->item_type = "categorieslist";
                     $file_thumbnail = PhocaGalleryHelperFront::displayBackFolder('medium', 1);
                     $item->linkthumbnailpath = $file_thumbnail['rel'];
                     $count++;
                 }
             }
         }
         // ----------------------------------------
         // Sub folders
         // ----------------------------------------
         if ($display_subcat_page == 1) {
             $query = $this->_buildSubCategoriesQuery();
             $this->_subcategories = $this->_getList($query);
             $total = count($this->_subcategories);
             for ($i = 0; $i < $total; $i++) {
                 $this->_data[$count] = $this->_subcategories[$i];
                 $item =& $this->_data[$count];
                 // USER RIGHT - ACCESS =======================================
                 $rightDisplay = PhocaGalleryHelper::getUserRight($this->_subcategories[$i]->params, 'accessuserid', $item->access, $user->get('aid', 0), $user->get('id', 0), $display_access_category);
                 // Display Key Icon (in case we want to display unaccessable categories in list view)
                 $rightDisplayKey = 1;
                 if ($display_access_category == 1) {
                     // we simulate that we want not to display unaccessable categories
                     // so we get rightDisplayKey = 0 then the key will be displayed
                     if (isset($this->_subcategories[$i]->params)) {
                         $rightDisplayKey = PhocaGalleryHelper::getUserRight($this->_subcategories[$i]->params, 'accessuserid', $item->access, $user->get('aid', 0), $user->get('id', 0), 0);
                     }
                 }
                 // ===========================================================
                 if ($rightDisplay > 0) {
                     $item->slug = $item->id . ':' . $item->alias;
                     $item->item_type = "subfolder";
                     $random = $this->_getRandomImageRecursive($item->id);
                     $file_thumbnail = PhocaGalleryHelperFront::displayThumbOrFolder($random->filename, 'medium', $rightDisplayKey);
                     $item->linkthumbnailpath = $file_thumbnail['rel'];
                     $count++;
                 }
             }
         }
         // ----------------------------------------
         // Images
         // ----------------------------------------
         $query = $this->_buildQuery($display_unpublished);
         $images = $this->_getList($query, $this->getState('limitstart'), $this->getState('limit'));
         $parentcategory = $this->_getParentCategory();
         $total = count($images);
         for ($i = 0; $i < $total; $i++) {
             $this->_data[$count] = $images[$i];
             $item =& $this->_data[$count];
             $item->slug = $item->id . ':' . $item->alias;
             $item->item_type = "image";
             // Get file thumbnail or No Image
             $file_thumbnail = PhocaGalleryHelperFront::displayFileOrNoImage($item->filename, 'medium');
             $item->linkthumbnailpath = $file_thumbnail['rel'];
             if (isset($parentcategory->params)) {
                 $item->parentcategoryparams = $parentcategory->params;
             }
             $count++;
         }
     }
     return $this->_data;
 }