/modules/lhgallery/image.php
PHP | 1211 lines | 865 code | 331 blank | 15 comment | 95 complexity | a4e7ba1a867318ca3434be0af0593d41 MD5 | raw file
Possible License(s): GPL-3.0, BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- <?php
- $Image = false;
- $cache = CSCacheAPC::getMem();
- // Display mode - album, lastupload
- $mode = isset($Params['user_parameters_unordered']['mode']) ? $Params['user_parameters_unordered']['mode'] : 'album';
- $Params['user_parameters_unordered']['color'] = filter_var((array)$Params['user_parameters_unordered']['color'],FILTER_VALIDATE_INT,FILTER_REQUIRE_ARRAY);
- $Params['user_parameters_unordered']['ncolor'] = filter_var((array)$Params['user_parameters_unordered']['ncolor'],FILTER_VALIDATE_INT,FILTER_REQUIRE_ARRAY);
- // Filters
- $resolutions = erConfigClassLhConfig::getInstance()->getSetting( 'site', 'resolutions' );
- $resolution = isset($Params['user_parameters_unordered']['resolution']) && key_exists($Params['user_parameters_unordered']['resolution'],$resolutions) ? $Params['user_parameters_unordered']['resolution'] : '';
- $appendResolutionMode = $resolution != '' ? '/(resolution)/'.$resolution : '';
- $modeMatch = $Params['user_parameters_unordered']['match'] == 'all' ? 'all' : '';
- $appendMatchMode = $modeMatch == 'all' ? '/(match)/all' : '';
- $albumMatch = is_numeric($Params['user_parameters_unordered']['album']) ? (int)$Params['user_parameters_unordered']['album'] : '';
- $appendAlbumMode = $albumMatch != '' ? '/(album)/'.$albumMatch : '';
- $filterArray = array();
- $appendMysqlIndex = array();
- if ($resolution != ''){
- $filterArray['pwidth'] = $resolutions[$resolution]['width'];
- $filterArray['pheight'] = $resolutions[$resolution]['height'];
- $appendMysqlIndex[] = 'res';
- }
- $filterArray['approved'] = 1;
- if ( is_numeric($albumMatch) ) {
- $filterArray['album_id'] = $albumMatch;
- }
- $currentUser = erLhcoreClassUser::instance();
- // Append cache key, depends on preview modes
- $appendCacheKey = '';
- // Lets cache the world :D
- if ($mode == 'album') {
-
- // Avoids loading persistent object classes etc
- if (($albumID = $cache->getCacheVersion('album_id_by_pid'.(int)$Params['user_parameters']['image_id'])) === false){
- try {
- $Image = erLhcoreClassGallery::getSession()->load( 'erLhcoreClassModelGalleryImage', (int)$Params['user_parameters']['image_id'] );
- } catch (Exception $e){
- erLhcoreClassModule::redirect('/');
- exit;
- }
-
- if ($Image->approved == 0){
- erLhcoreClassModule::redirect('/');
- exit;
- }
-
- $albumID = $Image->aid;
- $cache->store('album_id_by_pid'.(int)$Params['user_parameters']['image_id'],$albumID);
- }
-
- $sortModes = array(
- 'new' => 'pid DESC',
- 'newasc' => 'pid ASC',
- 'popular' => 'hits DESC, pid DESC',
- 'popularasc' => 'hits ASC, pid ASC',
- 'lasthits' => 'mtime DESC, pid DESC',
- 'lasthitsasc' => 'mtime ASC, pid ASC',
- 'lastcommented' => 'comtime DESC, pid DESC',
- 'lastcommentedasc' => 'comtime ASC, pid ASC',
- 'toprated' => 'pic_rating DESC, votes DESC, pid DESC',
- 'topratedasc' => 'pic_rating ASC, votes ASC, pid ASC',
- 'lastrated' => 'rtime DESC, pid DESC',
- 'lastratedasc' => 'rtime ASC, pid ASC'
- );
-
- $modeSort = isset($Params['user_parameters_unordered']['sort']) && key_exists($Params['user_parameters_unordered']['sort'],$sortModes) ? $Params['user_parameters_unordered']['sort'] : 'new';
- $modeSQL = $sortModes[$modeSort];
-
- switch ($modeSort) {
- case 'new':
- $appendCacheKey = 'album_image_'.$cache->getCacheVersion('album_'.$albumID).'_album_id_'.$albumID;
- break;
-
- case 'newasc':
- $appendCacheKey = 'album_image_newasc_'.$cache->getCacheVersion('album_'.$albumID).'_album_id_'.$albumID;
- break;
-
- case 'popular':
- $appendCacheKey = 'album_image_'.$cache->getCacheVersion('album_'.$albumID).'_popular_'.$cache->getCacheVersion('most_popular_version',time(),1500).'_album_id_'.$albumID;
- break;
-
- case 'popularasc':
- $appendCacheKey = 'album_image_'.$cache->getCacheVersion('album_'.$albumID).'_popularasc_'.$cache->getCacheVersion('most_popular_version',time(),1500).'_album_id_'.$albumID;
- break;
-
- case 'lasthits':
- $appendCacheKey = 'album_image_'.$cache->getCacheVersion('album_'.$albumID).'_lasthits_'.$cache->getCacheVersion('last_hits_version',time(),600).'_album_id_'.$albumID;
- break;
-
- case 'lasthitsasc':
- $appendCacheKey = 'album_image_'.$cache->getCacheVersion('album_'.$albumID).'_lasthitsasc_'.$cache->getCacheVersion('last_hits_version',time(),600).'_album_id_'.$albumID;
- break;
-
- case 'lastcommented':
- $appendCacheKey = 'album_image_'.$cache->getCacheVersion('last_commented_'.$albumID).'_lastcommented_'.$cache->getCacheVersion('album_'.$albumID).'_album_id_'.$albumID;
- break;
-
- case 'lastcommentedasc':
- $appendCacheKey = 'album_image_'.$cache->getCacheVersion('last_commented_'.$albumID).'_lastcommentedasc_'.$cache->getCacheVersion('album_'.$albumID).'_album_id_'.$albumID;
- break;
-
- case 'toprated':
- $appendCacheKey = 'album_image_'.$cache->getCacheVersion('top_rated_'.$albumID).'_toprated_'.$cache->getCacheVersion('album_'.$albumID).'_album_id_'.$albumID;
- break;
-
- case 'topratedasc':
- $appendCacheKey = 'album_image_'.$cache->getCacheVersion('top_rated_'.$albumID).'_topratedasc_'.$cache->getCacheVersion('album_'.$albumID).'_album_id_'.$albumID;
- break;
-
- case 'lastrated':
- $appendCacheKey = 'album_image_'.$cache->getCacheVersion('last_rated_'.$albumID).'_lastrated_'.$cache->getCacheVersion('album_'.$albumID).'_album_id_'.$albumID;
- break;
-
- case 'lastratedasc':
- $appendCacheKey = 'album_image_'.$cache->getCacheVersion('last_rated_'.$albumID).'_lastratedasc_'.$cache->getCacheVersion('album_'.$albumID).'_album_id_'.$albumID;
- break;
-
- default:
- break;
- }
-
- } elseif ($mode == 'search') {
- $sortModes = array(
- 'new' => '@id DESC',
- 'newasc' => '@id ASC',
- 'popular' => 'hits DESC, @id DESC',
- 'popularasc' => 'hits ASC, @id ASC',
- 'lasthits' => 'mtime DESC, @id DESC',
- 'lasthitsasc' => 'mtime ASC, @id ASC',
- 'lastcommented' => 'comtime DESC, @id DESC',
- 'lastcommentedasc' => 'comtime ASC, @id ASC',
- 'lastrated' => 'rtime DESC, @id DESC',
- 'lastratedasc' => 'rtime ASC, @id ASC',
- 'toprated' => 'pic_rating DESC, votes DESC, @id DESC',
- 'topratedasc' => 'pic_rating ASC, votes ASC, @id ASC',
- 'relevance' => '@relevance DESC, @id DESC',
- 'relevanceasc' => '@relevance ASC, @id ASC'
- );
-
- // Because sphinx view already includes this filter
- unset($filterArray['approved']);
-
- $filterColor = array();
- $nfilterColor = array();
- // Color filter in search mode
- $appendColorMode = '';
-
- $Params['user_parameters_unordered']['color'] = (array)$Params['user_parameters_unordered']['color'];
- $pallete_id = $Params['user_parameters_unordered']['color'];
- sort($pallete_id);
-
- $Params['user_parameters_unordered']['ncolor'] = (array)$Params['user_parameters_unordered']['ncolor'];
- $npallete_id = $Params['user_parameters_unordered']['ncolor'];
- sort($npallete_id);
-
- $pallete_items_number = count($pallete_id);
- if ($pallete_items_number > 0) {
- if ($pallete_items_number > erConfigClassLhConfig::getInstance()->getSetting( 'color_search', 'maximum_filters')) {
- $pallete_id = array_slice($pallete_id,0,erConfigClassLhConfig::getInstance()->getSetting( 'color_search', 'maximum_filters'));
- $pallete_items_number = erConfigClassLhConfig::getInstance()->getSetting( 'color_search', 'maximum_filters');
- }
- $filterColor = $pallete_id;
- $appendColorMode = '/(color)/'.implode('/',$pallete_id);
- }
-
- $npallete_items_number = count($npallete_id);
- if ($npallete_items_number > 0) {
- if ($npallete_items_number > erConfigClassLhConfig::getInstance()->getSetting( 'color_search', 'maximum_filters')) {
- $npallete_id = array_slice($npallete_id,0,erConfigClassLhConfig::getInstance()->getSetting( 'color_search', 'maximum_filters'));
- $npallete_items_number = erConfigClassLhConfig::getInstance()->getSetting( 'color_search', 'maximum_filters');
- }
- $nfilterColor = $npallete_id;
- $appendColorMode .= '/(ncolor)/'.implode('/',$npallete_id);
- }
-
-
- $modeSort = isset($Params['user_parameters_unordered']['sort']) && key_exists($Params['user_parameters_unordered']['sort'],$sortModes) ? $Params['user_parameters_unordered']['sort'] : 'relevance';
- $modeSQL = $sortModes[$modeSort];
- $keywordDecoded = trim(strip_tags(str_replace('+',' ',urldecode($Params['user_parameters_unordered']['keyword']))));
-
-
- switch ($modeSort) {
- case 'new':
- $appendCacheKey = 'album_searc_image_'.$keywordDecoded;
- break;
-
- case 'newasc':
- $appendCacheKey = 'album_searc_image_newasc_'.$keywordDecoded;
- break;
-
- case 'popular':
- $appendCacheKey = 'album_searc_image_popular_'.$keywordDecoded;
- break;
-
- case 'popularasc':
- $appendCacheKey = 'album_searc_image_popularasc_'.$keywordDecoded;
- break;
-
- case 'lasthits':
- $appendCacheKey = 'album_searc_image_lasthits_'.$keywordDecoded;
- break;
-
- case 'lasthitsasc':
- $appendCacheKey = 'album_searc_image_lasthitsasc_'.$keywordDecoded;
- break;
-
- case 'lastcommented':
- $appendCacheKey = 'album_searc_image_lastcommented_'.$keywordDecoded;
- break;
-
- case 'lastcommentedasc':
- $appendCacheKey = 'album_searc_image_lastcommentedasc_'.$keywordDecoded;
- break;
-
- case 'toprated':
- $appendCacheKey = 'album_searc_image_toprated_'.$keywordDecoded;
- break;
-
- case 'topratedasc':
- $appendCacheKey = 'album_searc_image_topratedasc_'.$keywordDecoded;
- break;
-
- case 'lastrated':
- $appendCacheKey = 'album_searc_image_lastrated_'.$keywordDecoded;
- break;
-
- case 'lastratedasc':
- $appendCacheKey = 'album_searc_image_lastratedasc_'.$keywordDecoded;
- break;
-
- default:
- break;
- }
-
- $appendCacheKey .= '_sphinx_cache_version_'.$cache->getCacheVersion('sphinx_cache_version').'_color_'.erLhcoreClassGallery::multi_implode('_pldid_',$filterColor).'_ncolor_'.erLhcoreClassGallery::multi_implode('_npldid_',$nfilterColor).'_match_mode_'.$modeMatch;
-
- } elseif ($mode == 'myfavorites') {
-
- $favouriteSession = erLhcoreClassModelGalleryMyfavoritesSession::getInstance();
- $appendCacheKey = '_my_favorites_version_'.$cache->getCacheVersion('favorite_'.$favouriteSession->id).'_session_id_'.$favouriteSession->id;
-
- } elseif ($mode == 'popularrecent') {
-
- $appendCacheKey = 'popularrecent_mode_image_ajax_pid_'.$cache->getCacheVersion('popularrecent_version',time(),600);
-
- } elseif ($mode == 'ratedrecent') {
-
- $appendCacheKey = 'ratedrecent_mode_image_ajax_pid_version_'.$cache->getCacheVersion('ratedrecent_version');
-
- } elseif ($mode == 'lastuploads') {
-
- $appendCacheKey = 'lastuploads_mode_image_ajax_pid_version_'.$cache->getCacheVersion('last_uploads');
-
- } elseif ($mode == 'lasthits') {
-
- $appendCacheKey = 'lasthits_mode_image_ajax_pid_version_'.$cache->getCacheVersion('last_hits_version',time(),600);
-
- } elseif ($mode == 'popular') {
-
- $appendCacheKey = 'popular_mode_image_ajax_pid_version_'.$cache->getCacheVersion('most_popular_version',time(),1500);
-
- } elseif ($mode == 'lastcommented') {
-
- $appendCacheKey = 'lastcommented_mode_image_ajax_pid_version_'.$cache->getCacheVersion('last_commented');
-
- } elseif ($mode == 'lastrated') {
-
- $appendCacheKey = 'lastrated_mode_image_ajax_pid_version_'.$cache->getCacheVersion('last_rated');
-
- } elseif ($mode == 'toprated') {
-
- $appendCacheKey = 'toprated_mode_image_ajax_pid_version_'.$cache->getCacheVersion('top_rated');
-
- } elseif ($mode == 'color') {
- $Params['user_parameters_unordered']['color'] = (array)$Params['user_parameters_unordered']['color'];
- $Params['user_parameters_unordered']['ncolor'] = (array)$Params['user_parameters_unordered']['ncolor'];
- sort($Params['user_parameters_unordered']['color']);
- sort($Params['user_parameters_unordered']['ncolor']);
-
-
- $appendCacheKey = 'color_mode_image_ajax_pid_version_'.$cache->getCacheVersion('color_images').'_'.erLhcoreClassGallery::multi_implode(',',$Params['user_parameters_unordered']['color']);
- $appendCacheKey .= 'ncolor_mode_image_ajax_pid_version_'.$cache->getCacheVersion('color_images').'_'.erLhcoreClassGallery::multi_implode(',',$Params['user_parameters_unordered']['ncolor']);
- }
- // Will be refactored in the future.
- if ($currentUser->isLogged()) {
- $appendCacheKey .= 'user_id_'.$currentUser->getUserID();
- }
- // Global image cache key
- $cacheKeyImageView = md5('image_window_'.(int)$Params['user_parameters']['image_id'].'_filter_'.erLhcoreClassGallery::multi_implode(',',$filterArray).'_siteaccess_'.erLhcoreClassSystem::instance()->SiteAccess.$appendCacheKey).'_comment_version_'.$cache->getCacheVersion('last_commented_image_version_'.(int)$Params['user_parameters']['image_id']).'_album_version_'.$cache->getCacheVersion('album_version');
- if (($Result = $cache->restore($cacheKeyImageView)) === false)
- {
- $tpl = erLhcoreClassTemplate::getInstance( 'lhgallery/image.tpl.php');
- if (!($Image instanceof erLhcoreClassModelGalleryImage)){
- try {
- $Image = erLhcoreClassGallery::getSession()->load( 'erLhcoreClassModelGalleryImage', (int)$Params['user_parameters']['image_id'] );
- } catch (Exception $e){
- erLhcoreClassModule::redirect('/');
- exit;
- }
-
- if ($Image->approved == 0){
- erLhcoreClassModule::redirect('/');
- exit;
- }
-
- }
- // Define ignore fields for lists
- $ignore_fields = array('filesize','total_filesize','ctime','owner_id','pic_rating','votes','caption','keywords','pic_raw_ip','approved','mtime','comtime','anaglyph','rtime');
- $CommentData = new erLhcoreClassModelGalleryComment();
- $needSave = false;
- if ($currentUser->isLogged()) {
- $CommentData->msg_author = $currentUser->getUserData(true)->username;
- } else {
- $CommentData->msg_author = erTranslationClassLhTranslation::getInstance()->getTranslation('gallery/image','Guest_');
- }
- if ($mode == 'album')
- {
-
- // Index hint for mysql
- $useIndexHint = array(
- 'new' => 'pid_6',
- 'newasc' => 'pid_6',
-
- 'popular' => 'pid_7',
- 'popularasc' => 'pid_7',
-
- 'lasthits' => 'pid_8',
- 'lasthitsasc' => 'pid_8',
-
- 'lastcommented' => 'pid_10',
- 'lastcommentedasc' => 'pid_10',
-
- 'toprated' => 'pid_9',
- 'topratedasc' => 'pid_9',
-
- 'lastrated' => 'a_rated_gen',
- 'lastratedasc' => 'a_rated_gen',
-
- //Hint if resolution filter is used
- 'new_res' => 'aid',
- 'newasc_res' => 'aid',
-
- 'popular_res' => 'pid_11',
- 'popularasc_res' => 'pid_11',
-
- 'lasthits_res' => 'aid_2',
- 'lasthitsasc_res' => 'aid_2',
-
- 'lastcommented_res' => 'aid_4',
- 'lastcommentedasc_res' => 'aid_4',
-
- 'toprated_res' => 'aid_3',
- 'topratedasc_res' => 'aid_3',
-
-
- 'lastrated_res' => 'a_rated_gen_res',
- 'lastratedasc_res' => 'a_rated_gen_res',
-
- );
-
- $modeIndex = $modeSort;
- if (count($appendMysqlIndex) > 0) {
- $modeIndex .= '_'.implode('_',$appendMysqlIndex);
- }
-
- if ($modeSort == 'new') {
- $imagesLeft = erLhcoreClassModelGalleryImage::getImages(array('ignore_fields' => $ignore_fields, 'smart_select' => true,'use_index' => $useIndexHint[$modeIndex],'disable_sql_cache' => true,'limit' => 5,'sort' => 'pid ASC','filter' => array('aid' => $Image->aid)+(array)$filterArray,'filtergt' => array('pid' => $Image->pid)));
- $page = ceil((erLhcoreClassModelGalleryImage::getImageCount(array('use_index' => $useIndexHint[$modeIndex],'disable_sql_cache' => true, 'filter' => array('aid' => $Image->aid)+(array)$filterArray,'filtergt' => array('pid' => $Image->pid)))+1)/20);
- $imagesRight = erLhcoreClassModelGalleryImage::getImages(array('ignore_fields' => $ignore_fields, 'smart_select' => true,'use_index' => $useIndexHint[$modeIndex],'disable_sql_cache' => true,'limit' => 5,'filter' => array('aid' => $Image->aid)+(array)$filterArray,'filterlt' => array('pid' => $Image->pid)));
- } elseif ($modeSort == 'newasc') {
- $imagesLeft = erLhcoreClassModelGalleryImage::getImages(array('ignore_fields' => $ignore_fields, 'smart_select' => true,'use_index' => $useIndexHint[$modeIndex],'disable_sql_cache' => true,'limit' => 5,'sort' => 'pid DESC','filter' => array('aid' => $Image->aid)+(array)$filterArray,'filterlt' => array('pid' => $Image->pid)));
- $page = ceil((erLhcoreClassModelGalleryImage::getImageCount(array('use_index' => $useIndexHint[$modeIndex],'disable_sql_cache' => true,'filter' => array('aid' => $Image->aid)+(array)$filterArray,'filterlt' => array('pid' => $Image->pid)))+1)/20);
- $imagesRight = erLhcoreClassModelGalleryImage::getImages(array('ignore_fields' => $ignore_fields, 'smart_select' => true,'use_index' => $useIndexHint[$modeIndex],'disable_sql_cache' => true,'sort' => 'pid ASC','limit' => 5,'filter' => array('aid' => $Image->aid)+(array)$filterArray,'filtergt' => array('pid' => $Image->pid)));
- } elseif ($modeSort == 'popular') {
-
- $db = ezcDbInstance::get();
- $session = erLhcoreClassGallery::getSession();
- $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
-
- $q2 = $q->subSelect();
- $q2->select( 'pid' )->from( 'lh_gallery_images' );
-
- $filterSQLArray = array();
- $countSQLArray = array();
- $countSQL = '';
- $filterSQLString = '';
-
- foreach ($filterArray as $field => $filterValue){
- $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
- $countSQLArray[] = "lh_gallery_images.{$field} = :$field";
- }
-
- $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
- $countSQL = ' AND '.implode(' AND ',$countSQLArray);
-
-
- $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->gt( 'hits', $q2->bindValue( $Image->hits ) ). ' OR '.$q2->expr->eq( 'hits', $q2->bindValue( $Image->hits ) ).' AND '.$q2->expr->gt( 'pid', $q2->bindValue( $Image->pid ) ).')' )
- ->orderBy('hits ASC, pid ASC')
- ->limit( 5 );
-
- $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
-
- $imagesLeft = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
-
- $stmt = $db->prepare('SELECT count(pid) FROM lh_gallery_images WHERE (hits > :hits OR hits = :hits AND pid > :pid) AND aid = :aid '.$countSQL.' LIMIT 1');
- $stmt->bindValue( ':hits',$Image->hits);
- $stmt->bindValue( ':pid',$Image->pid);
- $stmt->bindValue( ':aid',$Image->aid);
-
- foreach ($filterArray as $field => $filterValue){
- $stmt->bindValue( ':'.$field,$filterValue);
- }
-
- $stmt->execute();
- $photos = $stmt->fetchColumn();
-
- $page = ceil(($photos+1)/20);
-
- $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
- $q2 = $q->subSelect();
- $q2->select( 'pid' )->from( 'lh_gallery_images' );
-
- $filterSQLArray = array();
- foreach ($filterArray as $field => $filterValue){
- $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
- }
- $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
-
- $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->lt( 'hits', $q2->bindValue( $Image->hits ) ). ' OR '.$q2->expr->eq( 'hits', $q2->bindValue( $Image->hits ) ).' AND '.$q2->expr->lt( 'pid', $q2->bindValue( $Image->pid ) ).')' )
- ->orderBy('hits DESC, pid DESC')
- ->limit( 5 );
-
- $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
-
- $imagesRight = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
-
- } elseif ($modeSort == 'popularasc') {
-
- $db = ezcDbInstance::get();
- $session = erLhcoreClassGallery::getSession();
- $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
-
- $q2 = $q->subSelect();
- $q2->select( 'pid' )->from( 'lh_gallery_images' );
-
- $filterSQLArray = array();
- $countSQLArray = array();
- $countSQL = '';
- $filterSQLString = '';
-
- foreach ($filterArray as $field => $filterValue){
- $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
- $countSQLArray[] = "lh_gallery_images.{$field} = :$field";
- }
-
- $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
- $countSQL = ' AND '.implode(' AND ',$countSQLArray);
-
- $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->lt( 'hits', $q2->bindValue( $Image->hits ) ). ' OR '.$q2->expr->eq( 'hits', $q2->bindValue( $Image->hits ) ).' AND '.$q2->expr->lt( 'pid', $q2->bindValue( $Image->pid ) ) .')')
- ->orderBy('hits DESC, pid DESC')
- ->limit( 5 );
-
- $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
-
- $imagesLeft = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
-
- $stmt = $db->prepare('SELECT count(pid) FROM lh_gallery_images WHERE (hits < :hits OR hits = :hits AND pid < :pid) AND aid = :aid '.$countSQL.' LIMIT 1');
- $stmt->bindValue( ':hits',$Image->hits);
- $stmt->bindValue( ':pid',$Image->pid);
- $stmt->bindValue( ':aid',$Image->aid);
-
- foreach ($filterArray as $field => $filterValue){
- $stmt->bindValue( ':'.$field,$filterValue);
- }
-
- $stmt->execute();
- $photos = $stmt->fetchColumn();
- $page = ceil(($photos+1)/20);
-
- $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
-
- $q2 = $q->subSelect();
- $q2->select( 'pid' )->from( 'lh_gallery_images' );
-
- $filterSQLArray = array();
- foreach ($filterArray as $field => $filterValue){
- $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
- }
- $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
-
- $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->gt( 'hits', $q2->bindValue( $Image->hits ) ). ' OR '.$q2->expr->eq( 'hits', $q2->bindValue( $Image->hits ) ).' AND '.$q2->expr->gt( 'pid', $q2->bindValue( $Image->pid ) ).')' )
- ->orderBy('hits ASC, pid ASC')
- ->limit( 5 );
-
- $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
-
- $imagesRight = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
-
- } elseif ($modeSort == 'lasthits') {
-
-
- $db = ezcDbInstance::get();
- $session = erLhcoreClassGallery::getSession();
- $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
-
- $q2 = $q->subSelect();
- $q2->select( 'pid' )->from( 'lh_gallery_images' );
-
- $filterSQLArray = array();
- $countSQLArray = array();
- $countSQL = '';
- $filterSQLString = '';
-
- foreach ($filterArray as $field => $filterValue){
- $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
- $countSQLArray[] = "lh_gallery_images.{$field} = :$field";
- }
-
- $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
- $countSQL = ' AND '.implode(' AND ',$countSQLArray);
-
- $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->gt( 'mtime', $q2->bindValue( $Image->mtime ) ). ' OR '.$q2->expr->eq( 'mtime', $q2->bindValue( $Image->mtime ) ).' AND '.$q2->expr->gt( 'pid', $q2->bindValue( $Image->pid ) ).')' )
- ->orderBy('mtime ASC, pid ASC')
- ->limit( 5 );
-
- $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
-
- $imagesLeft = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
-
- $stmt = $db->prepare('SELECT count(pid) FROM lh_gallery_images WHERE (mtime > :mtime OR mtime = :mtime AND pid > :pid) AND aid = :aid '.$countSQL.' LIMIT 1');
- $stmt->bindValue( ':mtime',$Image->mtime);
- $stmt->bindValue( ':pid',$Image->pid);
- $stmt->bindValue( ':aid',$Image->aid);
-
- foreach ($filterArray as $field => $filterValue){
- $stmt->bindValue( ':'.$field,$filterValue);
- }
-
- $stmt->execute();
- $photos = $stmt->fetchColumn();
- $page = ceil(($photos+1)/20);
-
- $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
- $q2 = $q->subSelect();
- $q2->select( 'pid' )->from( 'lh_gallery_images' );
-
- $filterSQLArray = array();
- foreach ($filterArray as $field => $filterValue){
- $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
- }
- $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
-
- $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->lt( 'mtime', $q2->bindValue( $Image->mtime ) ). ' OR '.$q2->expr->eq( 'mtime', $q2->bindValue( $Image->mtime ) ).' AND '.$q2->expr->lt( 'pid', $q2->bindValue( $Image->pid ) ) .')')
- ->orderBy('mtime DESC, pid DESC')
- ->limit( 5 );
-
- $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
-
- $imagesRight = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
-
- } elseif ($modeSort == 'lasthitsasc') {
-
-
- $db = ezcDbInstance::get();
- $session = erLhcoreClassGallery::getSession();
- $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
-
- $q2 = $q->subSelect();
- $q2->select( 'pid' )->from( 'lh_gallery_images' );
-
- $filterSQLArray = array();
- $countSQLArray = array();
- $countSQL = '';
- $filterSQLString = '';
-
- foreach ($filterArray as $field => $filterValue){
- $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
- $countSQLArray[] = "lh_gallery_images.{$field} = :$field";
- }
-
- $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
- $countSQL = ' AND '.implode(' AND ',$countSQLArray);
-
- $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ( '.$q2->expr->lt( 'mtime', $q2->bindValue( $Image->mtime ) ). ' OR '.$q2->expr->eq( 'mtime', $q2->bindValue( $Image->mtime ) ).' AND '.$q2->expr->lt( 'pid', $q2->bindValue( $Image->pid ) ).')' )
- ->orderBy('mtime DESC, pid DESC')
- ->limit( 5 );
-
- $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
-
- $imagesLeft = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
-
- $stmt = $db->prepare('SELECT count(pid) FROM lh_gallery_images WHERE (mtime < :mtime OR mtime = :mtime AND pid < :pid) AND aid = :aid '.$countSQL.' LIMIT 1');
- $stmt->bindValue( ':mtime',$Image->mtime);
- $stmt->bindValue( ':pid',$Image->pid);
- $stmt->bindValue( ':aid',$Image->aid);
-
- foreach ($filterArray as $field => $filterValue){
- $stmt->bindValue( ':'.$field,$filterValue);
- }
-
- $stmt->execute();
- $photos = $stmt->fetchColumn();
- $page = ceil(($photos+1)/20);
-
- $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
-
- $q2 = $q->subSelect();
- $q2->select( 'pid' )->from( 'lh_gallery_images' );
-
- $filterSQLArray = array();
- foreach ($filterArray as $field => $filterValue){
- $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
- }
- $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
-
- $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->gt( 'mtime', $q2->bindValue( $Image->mtime ) ). ' OR '.$q2->expr->eq( 'mtime', $q2->bindValue( $Image->mtime ) ).' AND '.$q2->expr->gt( 'pid', $q2->bindValue( $Image->pid ) ) .')')
- ->orderBy('mtime ASC, pid ASC')
- ->limit( 5 );
-
- $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
-
- $imagesRight = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
-
- } elseif ($modeSort == 'lastcommented') {
-
- $db = ezcDbInstance::get();
- $session = erLhcoreClassGallery::getSession();
- $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
-
- $q2 = $q->subSelect();
- $q2->select( 'pid' )->from( 'lh_gallery_images' );
-
- $filterSQLArray = array();
- $countSQLArray = array();
- $countSQL = '';
- $filterSQLString = '';
-
- foreach ($filterArray as $field => $filterValue){
- $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
- $countSQLArray[] = "lh_gallery_images.{$field} = :$field";
- }
-
- $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
- $countSQL = ' AND '.implode(' AND ',$countSQLArray);
-
- $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->gt( 'comtime', $q2->bindValue( $Image->comtime ) ). ' OR '.$q2->expr->eq( 'comtime', $q2->bindValue( $Image->comtime ) ).' AND '.$q2->expr->gt( 'pid', $q2->bindValue( $Image->pid ) ) .')')
- ->orderBy('comtime ASC, pid ASC')
- ->limit( 5 );
-
- $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
-
- $imagesLeft = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
-
- $stmt = $db->prepare('SELECT count(pid) FROM lh_gallery_images WHERE (comtime > :comtime OR comtime = :comtime AND pid > :pid) AND aid = :aid '.$countSQL.' LIMIT 1');
- $stmt->bindValue( ':comtime',$Image->comtime);
- $stmt->bindValue( ':pid',$Image->pid);
- $stmt->bindValue( ':aid',$Image->aid);
-
- foreach ($filterArray as $field => $filterValue){
- $stmt->bindValue( ':'.$field,$filterValue);
- }
-
- $stmt->execute();
- $photos = $stmt->fetchColumn();
- $page = ceil(($photos+1)/20);
-
- $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
-
- $q2 = $q->subSelect();
- $q2->select( 'pid' )->from( 'lh_gallery_images' );
-
- $filterSQLArray = array();
- foreach ($filterArray as $field => $filterValue){
- $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
- }
- $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
-
- $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->lt( 'comtime', $q2->bindValue( $Image->comtime ) ). ' OR '.$q2->expr->eq( 'comtime', $q2->bindValue( $Image->comtime ) ).' AND '.$q2->expr->lt( 'pid', $q2->bindValue( $Image->pid ) ) .')')
- ->orderBy('comtime DESC, pid DESC')
- ->limit( 5 );
-
- $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
-
- $imagesRight = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
-
-
- } elseif ($modeSort == 'lastcommentedasc') {
-
- $db = ezcDbInstance::get();
- $session = erLhcoreClassGallery::getSession();
- $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
- $q2 = $q->subSelect();
- $q2->select( 'pid' )->from( 'lh_gallery_images' );
-
- $filterSQLArray = array();
- $countSQLArray = array();
- $countSQL = '';
- $filterSQLString = '';
-
- foreach ($filterArray as $field => $filterValue){
- $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
- $countSQLArray[] = "lh_gallery_images.{$field} = :$field";
- }
-
- $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
- $countSQL = ' AND '.implode(' AND ',$countSQLArray);
-
- $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->lt( 'comtime', $q2->bindValue( $Image->comtime ) ). ' OR '.$q2->expr->eq( 'comtime', $q2->bindValue( $Image->comtime ) ).' AND '.$q2->expr->lt( 'pid', $q2->bindValue( $Image->pid ) ).')' )
- ->orderBy('comtime DESC, pid DESC')
- ->limit( 5 );
- $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
- $imagesLeft = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
-
- $stmt = $db->prepare('SELECT count(pid) FROM lh_gallery_images WHERE (comtime < :comtime OR comtime = :comtime AND pid < :pid) AND aid = :aid '.$countSQL.' LIMIT 1');
- $stmt->bindValue( ':comtime',$Image->comtime);
- $stmt->bindValue( ':pid',$Image->pid);
- $stmt->bindValue( ':aid',$Image->aid);
-
- foreach ($filterArray as $field => $filterValue){
- $stmt->bindValue( ':'.$field,$filterValue);
- }
-
- $stmt->execute();
- $photos = $stmt->fetchColumn();
- $page = ceil(($photos+1)/20);
-
- $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
- $q2 = $q->subSelect();
- $q2->select( 'pid' )->from( 'lh_gallery_images' );
-
- $filterSQLArray = array();
- foreach ($filterArray as $field => $filterValue){
- $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
- }
- $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
-
- $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->gt( 'comtime', $q2->bindValue( $Image->comtime ) ). ' OR '.$q2->expr->eq( 'comtime', $q2->bindValue( $Image->comtime ) ).' AND '.$q2->expr->gt( 'pid', $q2->bindValue( $Image->pid ) ) .')')
- ->orderBy('comtime ASC, pid ASC')
- ->limit( 5 );
- $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
- $imagesRight = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
-
-
- } elseif ($modeSort == 'lastrated') {
-
- $db = ezcDbInstance::get();
- $session = erLhcoreClassGallery::getSession();
- $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
- $q2 = $q->subSelect();
- $q2->select( 'pid' )->from( 'lh_gallery_images' );
-
- $filterSQLArray = array();
- $countSQLArray = array();
- $countSQL = '';
- $filterSQLString = '';
-
- foreach ($filterArray as $field => $filterValue){
- $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
- $countSQLArray[] = "lh_gallery_images.{$field} = :$field";
- }
-
- $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
- $countSQL = ' AND '.implode(' AND ',$countSQLArray);
-
- $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->gt( 'rtime', $q2->bindValue( $Image->rtime ) ). ' OR '.$q2->expr->eq( 'rtime', $q2->bindValue( $Image->rtime ) ).' AND '.$q2->expr->gt( 'pid', $q2->bindValue( $Image->pid ) ) .')')
- ->orderBy('rtime ASC, pid ASC')
- ->limit( 5 );
-
- $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
-
- $imagesLeft = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
-
- $stmt = $db->prepare('SELECT count(pid) FROM lh_gallery_images WHERE (rtime > :rtime OR rtime = :rtime AND pid > :pid) AND aid = :aid '.$countSQL.' LIMIT 1');
- $stmt->bindValue( ':rtime',$Image->rtime);
- $stmt->bindValue( ':pid',$Image->pid);
- $stmt->bindValue( ':aid',$Image->aid);
-
- foreach ($filterArray as $field => $filterValue){
- $stmt->bindValue( ':'.$field,$filterValue);
- }
-
- $stmt->execute();
- $photos = $stmt->fetchColumn();
- $page = ceil(($photos+1)/20);
-
- $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
- $q2 = $q->subSelect();
- $q2->select( 'pid' )->from( 'lh_gallery_images' );
-
- $filterSQLArray = array();
- foreach ($filterArray as $field => $filterValue){
- $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
- }
- $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
-
- $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->lt( 'rtime', $q2->bindValue( $Image->rtime ) ). ' OR '.$q2->expr->eq( 'rtime', $q2->bindValue( $Image->rtime ) ).' AND '.$q2->expr->lt( 'pid', $q2->bindValue( $Image->pid ) ) .')')
- ->orderBy('rtime DESC, pid DESC')
- ->limit( 5 );
-
- $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
-
- $imagesRight = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
-
- } elseif ($modeSort == 'lastratedasc') {
-
- $db = ezcDbInstance::get();
- $session = erLhcoreClassGallery::getSession();
- $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
- $q2 = $q->subSelect();
- $q2->select( 'pid' )->from( 'lh_gallery_images' );
-
- $filterSQLArray = array();
- $countSQLArray = array();
- $countSQL = '';
- $filterSQLString = '';
-
- foreach ($filterArray as $field => $filterValue){
- $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
- $countSQLArray[] = "lh_gallery_images.{$field} = :$field";
- }
-
- $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
- $countSQL = ' AND '.implode(' AND ',$countSQLArray);
-
- $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->lt( 'rtime', $q2->bindValue( $Image->rtime ) ). ' OR '.$q2->expr->eq( 'rtime', $q2->bindValue( $Image->rtime ) ).' AND '.$q2->expr->lt( 'pid', $q2->bindValue( $Image->pid ) ).')' )
- ->orderBy('rtime DESC, pid DESC')
- ->limit( 5 );
-
- $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
-
- $imagesLeft = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
-
- $stmt = $db->prepare('SELECT count(pid) FROM lh_gallery_images WHERE (rtime < :rtime OR rtime = :rtime AND pid < :pid) AND aid = :aid '.$countSQL.' LIMIT 1');
- $stmt->bindValue( ':rtime',$Image->rtime);
- $stmt->bindValue( ':pid',$Image->pid);
- $stmt->bindValue( ':aid',$Image->aid);
-
- foreach ($filterArray as $field => $filterValue){
- $stmt->bindValue( ':'.$field,$filterValue);
- }
-
- $stmt->execute();
- $photos = $stmt->fetchColumn();
- $page = ceil(($photos+1)/20);
-
- $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
-
- $q2 = $q->subSelect();
- $q2->select( 'pid' )->from( 'lh_gallery_images' );
-
- $filterSQLArray = array();
- foreach ($filterArray as $field => $filterValue){
- $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
- }
- $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
-
- $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->gt( 'rtime', $q2->bindValue( $Image->rtime ) ). ' OR '.$q2->expr->eq( 'rtime', $q2->bindValue( $Image->rtime ) ).' AND '.$q2->expr->gt( 'pid', $q2->bindValue( $Image->pid ) ) .')')
- ->orderBy('rtime ASC, pid ASC')
- ->limit( 5 );
-
- $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
-
- $imagesRight = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
-
-
- } elseif ($modeSort == 'toprated') {
-
- $db = ezcDbInstance::get();
- $session = erLhcoreClassGallery::getSession();
- $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
-
- $q2 = $q->subSelect();
- $q2->select( 'pid' )->from( 'lh_gallery_images' );
-
- $filterSQLArray = array();
- $countSQLArray = array();
- $countSQL = '';
- $filterSQLString = '';
-
- foreach ($filterArray as $field => $filterValue){
- $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
- $countSQLArray[] = "lh_gallery_images.{$field} = :$field";
- }
-
- $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
- $countSQL = ' AND '.implode(' AND ',$countSQLArray);
-
- $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->gt( 'pic_rating', $q2->bindValue( $Image->pic_rating ) ). ' OR '.$q2->expr->eq( 'pic_rating', $q2->bindValue( $Image->pic_rating ) ).' AND '.$q2->expr->gt( 'votes', $q2->bindValue( $Image->votes ) ).' OR '.$q2->expr->eq( 'pic_rating', $q2->bindValue( $Image->pic_rating ) ).' AND '.$q2->expr->eq( 'votes', $q2->bindValue( $Image->votes ) ).' AND '.$q2->expr->gt( 'pid', $q2->bindValue( $Image->pid ) ).')')
- ->orderBy('pic_rating ASC, votes ASC, pid ASC')
- ->limit( 5 );
-
- $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
-
- $imagesLeft = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
-
- $stmt = $db->prepare('SELECT count(pid) FROM lh_gallery_images WHERE (pic_rating > :pic_rating OR pic_rating = :pic_rating AND lh_gallery_images.votes > :votes OR pic_rating = :pic_rating AND lh_gallery_images.votes = :votes AND pid > :pid) AND aid = :aid '.$countSQL);
- $stmt->bindValue( ':pic_rating',$Image->pic_rating);
- $stmt->bindValue( ':votes',$Image->votes);
- $stmt->bindValue( ':pid',$Image->pid);
- $stmt->bindValue( ':aid',$Image->aid);
-
- foreach ($filterArray as $field => $filterValue){
- $stmt->bindValue( ':'.$field,$filterValue);
- }
-
- $stmt->execute();
- $photos = $stmt->fetchColumn();
- $page = ceil(($photos+1)/20);
-
- $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
-
- $q2 = $q->subSelect();
- $q2->select( 'pid' )->from( 'lh_gallery_images' );
-
- $filterSQLArray = array();
- foreach ($filterArray as $field => $filterValue){
- $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
- }
- $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
-
- $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->lt( 'pic_rating', $q2->bindValue( $Image->pic_rating ) ). ' OR '.$q2->expr->eq( 'pic_rating', $q2->bindValue( $Image->pic_rating ) ).' AND '.$q2->expr->lt( 'votes', $q2->bindValue( $Image->votes ) ).' OR '.$q2->expr->eq( 'pic_rating', $q2->bindValue( $Image->pic_rating ) ).' AND '.$q2->expr->eq( 'votes', $q2->bindValue( $Image->votes ) ).' AND '.$q2->expr->lt( 'pid', $q2->bindValue( $Image->pid ) ).')')
- ->orderBy('pic_rating DESC, votes DESC, pid DESC')
- ->limit( 5 );
-
- $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
-
- $imagesRight = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
-
-
- } elseif ($modeSort == 'topratedasc') {
-
- $db = ezcDbInstance::get();
- $session = erLhcoreClassGallery::getSession();
- $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
-
- $q2 = $q->subSelect();
- $q2->select( 'pid' )->from( 'lh_gallery_images' );
-
- $filterSQLArray = array();
- $countSQLArray = array();
- $countSQL = '';
- $filterSQLString = '';
-
- foreach ($filterArray as $field => $filterValue){
- $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
- $countSQLArray[] = "lh_gallery_images.{$field} = :$field";
- }
-
- $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
- $countSQL = ' AND '.implode(' AND ',$countSQLArray);
-
- $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->lt( 'pic_rating', $q2->bindValue( $Image->pic_rating ) ). ' OR '.$q2->expr->eq( 'pic_rating', $q2->bindValue( $Image->pic_rating ) ).' AND '.$q2->expr->lt( 'votes', $q2->bindValue( $Image->votes ) ).' OR '.$q2->expr->eq( 'pic_rating', $q2->bindValue( $Image->pic_rating ) ).' AND '.$q2->expr->eq( 'votes', $q2->bindValue( $Image->votes ) ).' AND '.$q2->expr->lt( 'pid', $q2->bindValue( $Image->pid ) ).')')
- ->orderBy('pic_rating DESC, votes DESC, pid DESC')
- ->limit( 5 );
-
- $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
-
- $imagesLeft = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
-
- $stmt = $db->prepare('SELECT count(pid) FROM lh_gallery_images WHERE (pic_rating < :pic_rating OR pic_rating = :pic…
Large files files are truncated, but you can click here to view the full file