Back to PhocaGalleryImageFront class

Method getCategoryImages

public static
getCategoryImages
(mixed $categoryid, mixed $categoryImageOrdering = '')

Method getCategoryImages - Source code

public static function getCategoryImages($categoryid, $categoryImageOrdering = '')
{
    $db = Factory::getDBO();
    $user = Factory::getUser();
    $image = '';
    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 = ' ORDER BY RAND()';
    } else {
        // This is special case where we change category to image
        $ordering = ' ORDER BY a.' . $categoryImageOrdering['column'] . ' ' . $categoryImageOrdering['sort'];
    }
    $query = 'SELECT a.id, a.filename, a.exts, a.extm, a.extw, a.exth, a.extid, a.title, a.description, a.metadesc, 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,5';
    $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();
        $images[0] = new StdClass();
        $images[0]->notaccess = 1;
    }
    return $images;
}