public static
getRandomImageRecursive
(mixed $categoryid, mixed $categoryImageOrdering = '', mixed $extImage = 0, mixed $extImageSize = 1)
/*
* RANDOM IMAGE OR IMAGE ORDERED BY PARAM - CATEGORIES VIEW, CATEGORY VIEW
* $extImage - for example Picasa image
* $extImageSize - 1 - small, 2 - medium, 3 - large
* Is called random but the ordering can be set
*/
public static function getRandomImageRecursive($categoryid, $categoryImageOrdering = '', $extImage = 0, $extImageSize = 1)
{
$db = Factory::getDBO();
$user = Factory::getUser();
$image = new stdClass();
if (!is_array($categoryImageOrdering) && is_numeric($categoryImageOrdering)) {
$categoryImageOrdering = PhocaGalleryOrdering::getOrderingString($categoryImageOrdering);
}
// 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';
//TO DO - 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 = array();
}
if (!isset($images) || empty($images)) {
$image->exts = '';
$image->extm = '';
$image->exth = '';
$image->extw = '';
$image->filename = '';
// TO DO, 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;
}
}
}