Exemplo n.º 1
0
 function getRandomImageRecursive($categoryid, $categoryImageOrdering = '', $extImage = 0, $extImageSize = 1)
 {
     $db =& JFactory::getDBO();
     $user = JFactory::getUser();
     $image = new stdClass();
     // We need to get a list of all subcategories in the given category
     if ($categoryImageOrdering['column'] == '') {
         $ordering = $orderingRandomCat = ' ORDER BY RAND()';
     } else {
         // This is special case where we change category to image
         $ordering = ' ORDER BY a.' . $categoryImageOrdering['column'] . ' ' . $categoryImageOrdering['sort'];
         $orderingRandomCat = ' ORDER BY c.ordering';
         //TODO - can be changed to category_ordering parameter
     }
     $query = 'SELECT a.id, a.filename, a.exts, a.extm, a.extw, a.exth, a.extid, c.accessuserid as cataccessuserid, c.access as cataccess' . ' FROM #__phocagallery AS a' . ' LEFT JOIN #__phocagallery_categories AS c ON a.catid = c.id' . ' WHERE a.catid = ' . (int) $categoryid . ' AND a.published = 1' . ' AND a.approved = 1' . $ordering . ' LIMIT 0,1';
     $db->setQuery($query);
     $images = $db->loadObjectList();
     // Test the user rights to display random image as category image
     $rightDisplay = 1;
     //default is set to 1 (all users can see the category)
     if (isset($images[0]->cataccessuserid) && isset($images[0]->cataccess)) {
         $rightDisplay = PhocaGalleryAccess::getUserRight('accessuserid', $images[0]->cataccessuserid, $images[0]->cataccess, $user->getAuthorisedViewLevels(), $user->get('id', 0), 0);
     }
     if ($rightDisplay == 0) {
         $images = 0;
     }
     if (count($images) == 0) {
         $image->exts = '';
         $image->extm = '';
         $image->exth = '';
         $image->extw = '';
         $image->filename = '';
         // TODO, if we find no image in subcategory we look at its subcategory (subcategory of subcategory)
         // no to look if there is some subcategory on the same level
         $subCategories = PhocaGalleryImageFront::getRandomCategory($categoryid, $ordering);
         foreach ($subCategories as $subCategory) {
             $image = PhocaGalleryImageFront::getRandomImageRecursive($subCategory->id, $categoryImageOrdering, $extImage, $extImageSize);
             // external image - e.g. Picasa
             if ($extImage == 1) {
                 if ($extImageSize == 2) {
                     if (isset($image->extm) && $image->extm != '') {
                         break;
                     }
                 } else {
                     if (isset($image->exts) && $image->exts != '') {
                         break;
                     }
                 }
             } else {
                 if (isset($image->filename) && $image->filename != '') {
                     break;
                 }
             }
         }
     } else {
         $image = $images[0];
     }
     if ($extImage == 1) {
         return $image;
     } else {
         if (isset($image->filename)) {
             return $image->filename;
         } else {
             return $image;
         }
     }
 }