PageRenderTime 68ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/lhgallery/image.php

http://hppg.googlecode.com/
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

  1. <?php
  2. $Image = false;
  3. $cache = CSCacheAPC::getMem();
  4. // Display mode - album, lastupload
  5. $mode = isset($Params['user_parameters_unordered']['mode']) ? $Params['user_parameters_unordered']['mode'] : 'album';
  6. $Params['user_parameters_unordered']['color'] = filter_var((array)$Params['user_parameters_unordered']['color'],FILTER_VALIDATE_INT,FILTER_REQUIRE_ARRAY);
  7. $Params['user_parameters_unordered']['ncolor'] = filter_var((array)$Params['user_parameters_unordered']['ncolor'],FILTER_VALIDATE_INT,FILTER_REQUIRE_ARRAY);
  8. // Filters
  9. $resolutions = erConfigClassLhConfig::getInstance()->getSetting( 'site', 'resolutions' );
  10. $resolution = isset($Params['user_parameters_unordered']['resolution']) && key_exists($Params['user_parameters_unordered']['resolution'],$resolutions) ? $Params['user_parameters_unordered']['resolution'] : '';
  11. $appendResolutionMode = $resolution != '' ? '/(resolution)/'.$resolution : '';
  12. $modeMatch = $Params['user_parameters_unordered']['match'] == 'all' ? 'all' : '';
  13. $appendMatchMode = $modeMatch == 'all' ? '/(match)/all' : '';
  14. $albumMatch = is_numeric($Params['user_parameters_unordered']['album']) ? (int)$Params['user_parameters_unordered']['album'] : '';
  15. $appendAlbumMode = $albumMatch != '' ? '/(album)/'.$albumMatch : '';
  16. $filterArray = array();
  17. $appendMysqlIndex = array();
  18. if ($resolution != ''){
  19. $filterArray['pwidth'] = $resolutions[$resolution]['width'];
  20. $filterArray['pheight'] = $resolutions[$resolution]['height'];
  21. $appendMysqlIndex[] = 'res';
  22. }
  23. $filterArray['approved'] = 1;
  24. if ( is_numeric($albumMatch) ) {
  25. $filterArray['album_id'] = $albumMatch;
  26. }
  27. $currentUser = erLhcoreClassUser::instance();
  28. // Append cache key, depends on preview modes
  29. $appendCacheKey = '';
  30. // Lets cache the world :D
  31. if ($mode == 'album') {
  32. // Avoids loading persistent object classes etc
  33. if (($albumID = $cache->getCacheVersion('album_id_by_pid'.(int)$Params['user_parameters']['image_id'])) === false){
  34. try {
  35. $Image = erLhcoreClassGallery::getSession()->load( 'erLhcoreClassModelGalleryImage', (int)$Params['user_parameters']['image_id'] );
  36. } catch (Exception $e){
  37. erLhcoreClassModule::redirect('/');
  38. exit;
  39. }
  40. if ($Image->approved == 0){
  41. erLhcoreClassModule::redirect('/');
  42. exit;
  43. }
  44. $albumID = $Image->aid;
  45. $cache->store('album_id_by_pid'.(int)$Params['user_parameters']['image_id'],$albumID);
  46. }
  47. $sortModes = array(
  48. 'new' => 'pid DESC',
  49. 'newasc' => 'pid ASC',
  50. 'popular' => 'hits DESC, pid DESC',
  51. 'popularasc' => 'hits ASC, pid ASC',
  52. 'lasthits' => 'mtime DESC, pid DESC',
  53. 'lasthitsasc' => 'mtime ASC, pid ASC',
  54. 'lastcommented' => 'comtime DESC, pid DESC',
  55. 'lastcommentedasc' => 'comtime ASC, pid ASC',
  56. 'toprated' => 'pic_rating DESC, votes DESC, pid DESC',
  57. 'topratedasc' => 'pic_rating ASC, votes ASC, pid ASC',
  58. 'lastrated' => 'rtime DESC, pid DESC',
  59. 'lastratedasc' => 'rtime ASC, pid ASC'
  60. );
  61. $modeSort = isset($Params['user_parameters_unordered']['sort']) && key_exists($Params['user_parameters_unordered']['sort'],$sortModes) ? $Params['user_parameters_unordered']['sort'] : 'new';
  62. $modeSQL = $sortModes[$modeSort];
  63. switch ($modeSort) {
  64. case 'new':
  65. $appendCacheKey = 'album_image_'.$cache->getCacheVersion('album_'.$albumID).'_album_id_'.$albumID;
  66. break;
  67. case 'newasc':
  68. $appendCacheKey = 'album_image_newasc_'.$cache->getCacheVersion('album_'.$albumID).'_album_id_'.$albumID;
  69. break;
  70. case 'popular':
  71. $appendCacheKey = 'album_image_'.$cache->getCacheVersion('album_'.$albumID).'_popular_'.$cache->getCacheVersion('most_popular_version',time(),1500).'_album_id_'.$albumID;
  72. break;
  73. case 'popularasc':
  74. $appendCacheKey = 'album_image_'.$cache->getCacheVersion('album_'.$albumID).'_popularasc_'.$cache->getCacheVersion('most_popular_version',time(),1500).'_album_id_'.$albumID;
  75. break;
  76. case 'lasthits':
  77. $appendCacheKey = 'album_image_'.$cache->getCacheVersion('album_'.$albumID).'_lasthits_'.$cache->getCacheVersion('last_hits_version',time(),600).'_album_id_'.$albumID;
  78. break;
  79. case 'lasthitsasc':
  80. $appendCacheKey = 'album_image_'.$cache->getCacheVersion('album_'.$albumID).'_lasthitsasc_'.$cache->getCacheVersion('last_hits_version',time(),600).'_album_id_'.$albumID;
  81. break;
  82. case 'lastcommented':
  83. $appendCacheKey = 'album_image_'.$cache->getCacheVersion('last_commented_'.$albumID).'_lastcommented_'.$cache->getCacheVersion('album_'.$albumID).'_album_id_'.$albumID;
  84. break;
  85. case 'lastcommentedasc':
  86. $appendCacheKey = 'album_image_'.$cache->getCacheVersion('last_commented_'.$albumID).'_lastcommentedasc_'.$cache->getCacheVersion('album_'.$albumID).'_album_id_'.$albumID;
  87. break;
  88. case 'toprated':
  89. $appendCacheKey = 'album_image_'.$cache->getCacheVersion('top_rated_'.$albumID).'_toprated_'.$cache->getCacheVersion('album_'.$albumID).'_album_id_'.$albumID;
  90. break;
  91. case 'topratedasc':
  92. $appendCacheKey = 'album_image_'.$cache->getCacheVersion('top_rated_'.$albumID).'_topratedasc_'.$cache->getCacheVersion('album_'.$albumID).'_album_id_'.$albumID;
  93. break;
  94. case 'lastrated':
  95. $appendCacheKey = 'album_image_'.$cache->getCacheVersion('last_rated_'.$albumID).'_lastrated_'.$cache->getCacheVersion('album_'.$albumID).'_album_id_'.$albumID;
  96. break;
  97. case 'lastratedasc':
  98. $appendCacheKey = 'album_image_'.$cache->getCacheVersion('last_rated_'.$albumID).'_lastratedasc_'.$cache->getCacheVersion('album_'.$albumID).'_album_id_'.$albumID;
  99. break;
  100. default:
  101. break;
  102. }
  103. } elseif ($mode == 'search') {
  104. $sortModes = array(
  105. 'new' => '@id DESC',
  106. 'newasc' => '@id ASC',
  107. 'popular' => 'hits DESC, @id DESC',
  108. 'popularasc' => 'hits ASC, @id ASC',
  109. 'lasthits' => 'mtime DESC, @id DESC',
  110. 'lasthitsasc' => 'mtime ASC, @id ASC',
  111. 'lastcommented' => 'comtime DESC, @id DESC',
  112. 'lastcommentedasc' => 'comtime ASC, @id ASC',
  113. 'lastrated' => 'rtime DESC, @id DESC',
  114. 'lastratedasc' => 'rtime ASC, @id ASC',
  115. 'toprated' => 'pic_rating DESC, votes DESC, @id DESC',
  116. 'topratedasc' => 'pic_rating ASC, votes ASC, @id ASC',
  117. 'relevance' => '@relevance DESC, @id DESC',
  118. 'relevanceasc' => '@relevance ASC, @id ASC'
  119. );
  120. // Because sphinx view already includes this filter
  121. unset($filterArray['approved']);
  122. $filterColor = array();
  123. $nfilterColor = array();
  124. // Color filter in search mode
  125. $appendColorMode = '';
  126. $Params['user_parameters_unordered']['color'] = (array)$Params['user_parameters_unordered']['color'];
  127. $pallete_id = $Params['user_parameters_unordered']['color'];
  128. sort($pallete_id);
  129. $Params['user_parameters_unordered']['ncolor'] = (array)$Params['user_parameters_unordered']['ncolor'];
  130. $npallete_id = $Params['user_parameters_unordered']['ncolor'];
  131. sort($npallete_id);
  132. $pallete_items_number = count($pallete_id);
  133. if ($pallete_items_number > 0) {
  134. if ($pallete_items_number > erConfigClassLhConfig::getInstance()->getSetting( 'color_search', 'maximum_filters')) {
  135. $pallete_id = array_slice($pallete_id,0,erConfigClassLhConfig::getInstance()->getSetting( 'color_search', 'maximum_filters'));
  136. $pallete_items_number = erConfigClassLhConfig::getInstance()->getSetting( 'color_search', 'maximum_filters');
  137. }
  138. $filterColor = $pallete_id;
  139. $appendColorMode = '/(color)/'.implode('/',$pallete_id);
  140. }
  141. $npallete_items_number = count($npallete_id);
  142. if ($npallete_items_number > 0) {
  143. if ($npallete_items_number > erConfigClassLhConfig::getInstance()->getSetting( 'color_search', 'maximum_filters')) {
  144. $npallete_id = array_slice($npallete_id,0,erConfigClassLhConfig::getInstance()->getSetting( 'color_search', 'maximum_filters'));
  145. $npallete_items_number = erConfigClassLhConfig::getInstance()->getSetting( 'color_search', 'maximum_filters');
  146. }
  147. $nfilterColor = $npallete_id;
  148. $appendColorMode .= '/(ncolor)/'.implode('/',$npallete_id);
  149. }
  150. $modeSort = isset($Params['user_parameters_unordered']['sort']) && key_exists($Params['user_parameters_unordered']['sort'],$sortModes) ? $Params['user_parameters_unordered']['sort'] : 'relevance';
  151. $modeSQL = $sortModes[$modeSort];
  152. $keywordDecoded = trim(strip_tags(str_replace('+',' ',urldecode($Params['user_parameters_unordered']['keyword']))));
  153. switch ($modeSort) {
  154. case 'new':
  155. $appendCacheKey = 'album_searc_image_'.$keywordDecoded;
  156. break;
  157. case 'newasc':
  158. $appendCacheKey = 'album_searc_image_newasc_'.$keywordDecoded;
  159. break;
  160. case 'popular':
  161. $appendCacheKey = 'album_searc_image_popular_'.$keywordDecoded;
  162. break;
  163. case 'popularasc':
  164. $appendCacheKey = 'album_searc_image_popularasc_'.$keywordDecoded;
  165. break;
  166. case 'lasthits':
  167. $appendCacheKey = 'album_searc_image_lasthits_'.$keywordDecoded;
  168. break;
  169. case 'lasthitsasc':
  170. $appendCacheKey = 'album_searc_image_lasthitsasc_'.$keywordDecoded;
  171. break;
  172. case 'lastcommented':
  173. $appendCacheKey = 'album_searc_image_lastcommented_'.$keywordDecoded;
  174. break;
  175. case 'lastcommentedasc':
  176. $appendCacheKey = 'album_searc_image_lastcommentedasc_'.$keywordDecoded;
  177. break;
  178. case 'toprated':
  179. $appendCacheKey = 'album_searc_image_toprated_'.$keywordDecoded;
  180. break;
  181. case 'topratedasc':
  182. $appendCacheKey = 'album_searc_image_topratedasc_'.$keywordDecoded;
  183. break;
  184. case 'lastrated':
  185. $appendCacheKey = 'album_searc_image_lastrated_'.$keywordDecoded;
  186. break;
  187. case 'lastratedasc':
  188. $appendCacheKey = 'album_searc_image_lastratedasc_'.$keywordDecoded;
  189. break;
  190. default:
  191. break;
  192. }
  193. $appendCacheKey .= '_sphinx_cache_version_'.$cache->getCacheVersion('sphinx_cache_version').'_color_'.erLhcoreClassGallery::multi_implode('_pldid_',$filterColor).'_ncolor_'.erLhcoreClassGallery::multi_implode('_npldid_',$nfilterColor).'_match_mode_'.$modeMatch;
  194. } elseif ($mode == 'myfavorites') {
  195. $favouriteSession = erLhcoreClassModelGalleryMyfavoritesSession::getInstance();
  196. $appendCacheKey = '_my_favorites_version_'.$cache->getCacheVersion('favorite_'.$favouriteSession->id).'_session_id_'.$favouriteSession->id;
  197. } elseif ($mode == 'popularrecent') {
  198. $appendCacheKey = 'popularrecent_mode_image_ajax_pid_'.$cache->getCacheVersion('popularrecent_version',time(),600);
  199. } elseif ($mode == 'ratedrecent') {
  200. $appendCacheKey = 'ratedrecent_mode_image_ajax_pid_version_'.$cache->getCacheVersion('ratedrecent_version');
  201. } elseif ($mode == 'lastuploads') {
  202. $appendCacheKey = 'lastuploads_mode_image_ajax_pid_version_'.$cache->getCacheVersion('last_uploads');
  203. } elseif ($mode == 'lasthits') {
  204. $appendCacheKey = 'lasthits_mode_image_ajax_pid_version_'.$cache->getCacheVersion('last_hits_version',time(),600);
  205. } elseif ($mode == 'popular') {
  206. $appendCacheKey = 'popular_mode_image_ajax_pid_version_'.$cache->getCacheVersion('most_popular_version',time(),1500);
  207. } elseif ($mode == 'lastcommented') {
  208. $appendCacheKey = 'lastcommented_mode_image_ajax_pid_version_'.$cache->getCacheVersion('last_commented');
  209. } elseif ($mode == 'lastrated') {
  210. $appendCacheKey = 'lastrated_mode_image_ajax_pid_version_'.$cache->getCacheVersion('last_rated');
  211. } elseif ($mode == 'toprated') {
  212. $appendCacheKey = 'toprated_mode_image_ajax_pid_version_'.$cache->getCacheVersion('top_rated');
  213. } elseif ($mode == 'color') {
  214. $Params['user_parameters_unordered']['color'] = (array)$Params['user_parameters_unordered']['color'];
  215. $Params['user_parameters_unordered']['ncolor'] = (array)$Params['user_parameters_unordered']['ncolor'];
  216. sort($Params['user_parameters_unordered']['color']);
  217. sort($Params['user_parameters_unordered']['ncolor']);
  218. $appendCacheKey = 'color_mode_image_ajax_pid_version_'.$cache->getCacheVersion('color_images').'_'.erLhcoreClassGallery::multi_implode(',',$Params['user_parameters_unordered']['color']);
  219. $appendCacheKey .= 'ncolor_mode_image_ajax_pid_version_'.$cache->getCacheVersion('color_images').'_'.erLhcoreClassGallery::multi_implode(',',$Params['user_parameters_unordered']['ncolor']);
  220. }
  221. // Will be refactored in the future.
  222. if ($currentUser->isLogged()) {
  223. $appendCacheKey .= 'user_id_'.$currentUser->getUserID();
  224. }
  225. // Global image cache key
  226. $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');
  227. if (($Result = $cache->restore($cacheKeyImageView)) === false)
  228. {
  229. $tpl = erLhcoreClassTemplate::getInstance( 'lhgallery/image.tpl.php');
  230. if (!($Image instanceof erLhcoreClassModelGalleryImage)){
  231. try {
  232. $Image = erLhcoreClassGallery::getSession()->load( 'erLhcoreClassModelGalleryImage', (int)$Params['user_parameters']['image_id'] );
  233. } catch (Exception $e){
  234. erLhcoreClassModule::redirect('/');
  235. exit;
  236. }
  237. if ($Image->approved == 0){
  238. erLhcoreClassModule::redirect('/');
  239. exit;
  240. }
  241. }
  242. // Define ignore fields for lists
  243. $ignore_fields = array('filesize','total_filesize','ctime','owner_id','pic_rating','votes','caption','keywords','pic_raw_ip','approved','mtime','comtime','anaglyph','rtime');
  244. $CommentData = new erLhcoreClassModelGalleryComment();
  245. $needSave = false;
  246. if ($currentUser->isLogged()) {
  247. $CommentData->msg_author = $currentUser->getUserData(true)->username;
  248. } else {
  249. $CommentData->msg_author = erTranslationClassLhTranslation::getInstance()->getTranslation('gallery/image','Guest_');
  250. }
  251. if ($mode == 'album')
  252. {
  253. // Index hint for mysql
  254. $useIndexHint = array(
  255. 'new' => 'pid_6',
  256. 'newasc' => 'pid_6',
  257. 'popular' => 'pid_7',
  258. 'popularasc' => 'pid_7',
  259. 'lasthits' => 'pid_8',
  260. 'lasthitsasc' => 'pid_8',
  261. 'lastcommented' => 'pid_10',
  262. 'lastcommentedasc' => 'pid_10',
  263. 'toprated' => 'pid_9',
  264. 'topratedasc' => 'pid_9',
  265. 'lastrated' => 'a_rated_gen',
  266. 'lastratedasc' => 'a_rated_gen',
  267. //Hint if resolution filter is used
  268. 'new_res' => 'aid',
  269. 'newasc_res' => 'aid',
  270. 'popular_res' => 'pid_11',
  271. 'popularasc_res' => 'pid_11',
  272. 'lasthits_res' => 'aid_2',
  273. 'lasthitsasc_res' => 'aid_2',
  274. 'lastcommented_res' => 'aid_4',
  275. 'lastcommentedasc_res' => 'aid_4',
  276. 'toprated_res' => 'aid_3',
  277. 'topratedasc_res' => 'aid_3',
  278. 'lastrated_res' => 'a_rated_gen_res',
  279. 'lastratedasc_res' => 'a_rated_gen_res',
  280. );
  281. $modeIndex = $modeSort;
  282. if (count($appendMysqlIndex) > 0) {
  283. $modeIndex .= '_'.implode('_',$appendMysqlIndex);
  284. }
  285. if ($modeSort == 'new') {
  286. $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)));
  287. $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);
  288. $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)));
  289. } elseif ($modeSort == 'newasc') {
  290. $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)));
  291. $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);
  292. $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)));
  293. } elseif ($modeSort == 'popular') {
  294. $db = ezcDbInstance::get();
  295. $session = erLhcoreClassGallery::getSession();
  296. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  297. $q2 = $q->subSelect();
  298. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  299. $filterSQLArray = array();
  300. $countSQLArray = array();
  301. $countSQL = '';
  302. $filterSQLString = '';
  303. foreach ($filterArray as $field => $filterValue){
  304. $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
  305. $countSQLArray[] = "lh_gallery_images.{$field} = :$field";
  306. }
  307. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  308. $countSQL = ' AND '.implode(' AND ',$countSQLArray);
  309. $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 ) ).')' )
  310. ->orderBy('hits ASC, pid ASC')
  311. ->limit( 5 );
  312. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  313. $imagesLeft = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  314. $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');
  315. $stmt->bindValue( ':hits',$Image->hits);
  316. $stmt->bindValue( ':pid',$Image->pid);
  317. $stmt->bindValue( ':aid',$Image->aid);
  318. foreach ($filterArray as $field => $filterValue){
  319. $stmt->bindValue( ':'.$field,$filterValue);
  320. }
  321. $stmt->execute();
  322. $photos = $stmt->fetchColumn();
  323. $page = ceil(($photos+1)/20);
  324. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  325. $q2 = $q->subSelect();
  326. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  327. $filterSQLArray = array();
  328. foreach ($filterArray as $field => $filterValue){
  329. $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
  330. }
  331. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  332. $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 ) ).')' )
  333. ->orderBy('hits DESC, pid DESC')
  334. ->limit( 5 );
  335. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  336. $imagesRight = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  337. } elseif ($modeSort == 'popularasc') {
  338. $db = ezcDbInstance::get();
  339. $session = erLhcoreClassGallery::getSession();
  340. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  341. $q2 = $q->subSelect();
  342. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  343. $filterSQLArray = array();
  344. $countSQLArray = array();
  345. $countSQL = '';
  346. $filterSQLString = '';
  347. foreach ($filterArray as $field => $filterValue){
  348. $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
  349. $countSQLArray[] = "lh_gallery_images.{$field} = :$field";
  350. }
  351. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  352. $countSQL = ' AND '.implode(' AND ',$countSQLArray);
  353. $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 ) ) .')')
  354. ->orderBy('hits DESC, pid DESC')
  355. ->limit( 5 );
  356. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  357. $imagesLeft = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  358. $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');
  359. $stmt->bindValue( ':hits',$Image->hits);
  360. $stmt->bindValue( ':pid',$Image->pid);
  361. $stmt->bindValue( ':aid',$Image->aid);
  362. foreach ($filterArray as $field => $filterValue){
  363. $stmt->bindValue( ':'.$field,$filterValue);
  364. }
  365. $stmt->execute();
  366. $photos = $stmt->fetchColumn();
  367. $page = ceil(($photos+1)/20);
  368. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  369. $q2 = $q->subSelect();
  370. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  371. $filterSQLArray = array();
  372. foreach ($filterArray as $field => $filterValue){
  373. $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
  374. }
  375. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  376. $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 ) ).')' )
  377. ->orderBy('hits ASC, pid ASC')
  378. ->limit( 5 );
  379. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  380. $imagesRight = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  381. } elseif ($modeSort == 'lasthits') {
  382. $db = ezcDbInstance::get();
  383. $session = erLhcoreClassGallery::getSession();
  384. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  385. $q2 = $q->subSelect();
  386. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  387. $filterSQLArray = array();
  388. $countSQLArray = array();
  389. $countSQL = '';
  390. $filterSQLString = '';
  391. foreach ($filterArray as $field => $filterValue){
  392. $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
  393. $countSQLArray[] = "lh_gallery_images.{$field} = :$field";
  394. }
  395. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  396. $countSQL = ' AND '.implode(' AND ',$countSQLArray);
  397. $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 ) ).')' )
  398. ->orderBy('mtime ASC, pid ASC')
  399. ->limit( 5 );
  400. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  401. $imagesLeft = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  402. $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');
  403. $stmt->bindValue( ':mtime',$Image->mtime);
  404. $stmt->bindValue( ':pid',$Image->pid);
  405. $stmt->bindValue( ':aid',$Image->aid);
  406. foreach ($filterArray as $field => $filterValue){
  407. $stmt->bindValue( ':'.$field,$filterValue);
  408. }
  409. $stmt->execute();
  410. $photos = $stmt->fetchColumn();
  411. $page = ceil(($photos+1)/20);
  412. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  413. $q2 = $q->subSelect();
  414. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  415. $filterSQLArray = array();
  416. foreach ($filterArray as $field => $filterValue){
  417. $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
  418. }
  419. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  420. $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 ) ) .')')
  421. ->orderBy('mtime DESC, pid DESC')
  422. ->limit( 5 );
  423. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  424. $imagesRight = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  425. } elseif ($modeSort == 'lasthitsasc') {
  426. $db = ezcDbInstance::get();
  427. $session = erLhcoreClassGallery::getSession();
  428. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  429. $q2 = $q->subSelect();
  430. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  431. $filterSQLArray = array();
  432. $countSQLArray = array();
  433. $countSQL = '';
  434. $filterSQLString = '';
  435. foreach ($filterArray as $field => $filterValue){
  436. $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
  437. $countSQLArray[] = "lh_gallery_images.{$field} = :$field";
  438. }
  439. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  440. $countSQL = ' AND '.implode(' AND ',$countSQLArray);
  441. $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 ) ).')' )
  442. ->orderBy('mtime DESC, pid DESC')
  443. ->limit( 5 );
  444. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  445. $imagesLeft = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  446. $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');
  447. $stmt->bindValue( ':mtime',$Image->mtime);
  448. $stmt->bindValue( ':pid',$Image->pid);
  449. $stmt->bindValue( ':aid',$Image->aid);
  450. foreach ($filterArray as $field => $filterValue){
  451. $stmt->bindValue( ':'.$field,$filterValue);
  452. }
  453. $stmt->execute();
  454. $photos = $stmt->fetchColumn();
  455. $page = ceil(($photos+1)/20);
  456. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  457. $q2 = $q->subSelect();
  458. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  459. $filterSQLArray = array();
  460. foreach ($filterArray as $field => $filterValue){
  461. $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
  462. }
  463. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  464. $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 ) ) .')')
  465. ->orderBy('mtime ASC, pid ASC')
  466. ->limit( 5 );
  467. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  468. $imagesRight = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  469. } elseif ($modeSort == 'lastcommented') {
  470. $db = ezcDbInstance::get();
  471. $session = erLhcoreClassGallery::getSession();
  472. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  473. $q2 = $q->subSelect();
  474. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  475. $filterSQLArray = array();
  476. $countSQLArray = array();
  477. $countSQL = '';
  478. $filterSQLString = '';
  479. foreach ($filterArray as $field => $filterValue){
  480. $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
  481. $countSQLArray[] = "lh_gallery_images.{$field} = :$field";
  482. }
  483. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  484. $countSQL = ' AND '.implode(' AND ',$countSQLArray);
  485. $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 ) ) .')')
  486. ->orderBy('comtime ASC, pid ASC')
  487. ->limit( 5 );
  488. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  489. $imagesLeft = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  490. $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');
  491. $stmt->bindValue( ':comtime',$Image->comtime);
  492. $stmt->bindValue( ':pid',$Image->pid);
  493. $stmt->bindValue( ':aid',$Image->aid);
  494. foreach ($filterArray as $field => $filterValue){
  495. $stmt->bindValue( ':'.$field,$filterValue);
  496. }
  497. $stmt->execute();
  498. $photos = $stmt->fetchColumn();
  499. $page = ceil(($photos+1)/20);
  500. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  501. $q2 = $q->subSelect();
  502. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  503. $filterSQLArray = array();
  504. foreach ($filterArray as $field => $filterValue){
  505. $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
  506. }
  507. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  508. $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 ) ) .')')
  509. ->orderBy('comtime DESC, pid DESC')
  510. ->limit( 5 );
  511. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  512. $imagesRight = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  513. } elseif ($modeSort == 'lastcommentedasc') {
  514. $db = ezcDbInstance::get();
  515. $session = erLhcoreClassGallery::getSession();
  516. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  517. $q2 = $q->subSelect();
  518. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  519. $filterSQLArray = array();
  520. $countSQLArray = array();
  521. $countSQL = '';
  522. $filterSQLString = '';
  523. foreach ($filterArray as $field => $filterValue){
  524. $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
  525. $countSQLArray[] = "lh_gallery_images.{$field} = :$field";
  526. }
  527. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  528. $countSQL = ' AND '.implode(' AND ',$countSQLArray);
  529. $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 ) ).')' )
  530. ->orderBy('comtime DESC, pid DESC')
  531. ->limit( 5 );
  532. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  533. $imagesLeft = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  534. $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');
  535. $stmt->bindValue( ':comtime',$Image->comtime);
  536. $stmt->bindValue( ':pid',$Image->pid);
  537. $stmt->bindValue( ':aid',$Image->aid);
  538. foreach ($filterArray as $field => $filterValue){
  539. $stmt->bindValue( ':'.$field,$filterValue);
  540. }
  541. $stmt->execute();
  542. $photos = $stmt->fetchColumn();
  543. $page = ceil(($photos+1)/20);
  544. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  545. $q2 = $q->subSelect();
  546. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  547. $filterSQLArray = array();
  548. foreach ($filterArray as $field => $filterValue){
  549. $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
  550. }
  551. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  552. $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 ) ) .')')
  553. ->orderBy('comtime ASC, pid ASC')
  554. ->limit( 5 );
  555. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  556. $imagesRight = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  557. } elseif ($modeSort == 'lastrated') {
  558. $db = ezcDbInstance::get();
  559. $session = erLhcoreClassGallery::getSession();
  560. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  561. $q2 = $q->subSelect();
  562. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  563. $filterSQLArray = array();
  564. $countSQLArray = array();
  565. $countSQL = '';
  566. $filterSQLString = '';
  567. foreach ($filterArray as $field => $filterValue){
  568. $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
  569. $countSQLArray[] = "lh_gallery_images.{$field} = :$field";
  570. }
  571. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  572. $countSQL = ' AND '.implode(' AND ',$countSQLArray);
  573. $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 ) ) .')')
  574. ->orderBy('rtime ASC, pid ASC')
  575. ->limit( 5 );
  576. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  577. $imagesLeft = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  578. $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');
  579. $stmt->bindValue( ':rtime',$Image->rtime);
  580. $stmt->bindValue( ':pid',$Image->pid);
  581. $stmt->bindValue( ':aid',$Image->aid);
  582. foreach ($filterArray as $field => $filterValue){
  583. $stmt->bindValue( ':'.$field,$filterValue);
  584. }
  585. $stmt->execute();
  586. $photos = $stmt->fetchColumn();
  587. $page = ceil(($photos+1)/20);
  588. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  589. $q2 = $q->subSelect();
  590. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  591. $filterSQLArray = array();
  592. foreach ($filterArray as $field => $filterValue){
  593. $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
  594. }
  595. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  596. $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 ) ) .')')
  597. ->orderBy('rtime DESC, pid DESC')
  598. ->limit( 5 );
  599. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  600. $imagesRight = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  601. } elseif ($modeSort == 'lastratedasc') {
  602. $db = ezcDbInstance::get();
  603. $session = erLhcoreClassGallery::getSession();
  604. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  605. $q2 = $q->subSelect();
  606. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  607. $filterSQLArray = array();
  608. $countSQLArray = array();
  609. $countSQL = '';
  610. $filterSQLString = '';
  611. foreach ($filterArray as $field => $filterValue){
  612. $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
  613. $countSQLArray[] = "lh_gallery_images.{$field} = :$field";
  614. }
  615. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  616. $countSQL = ' AND '.implode(' AND ',$countSQLArray);
  617. $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 ) ).')' )
  618. ->orderBy('rtime DESC, pid DESC')
  619. ->limit( 5 );
  620. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  621. $imagesLeft = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  622. $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');
  623. $stmt->bindValue( ':rtime',$Image->rtime);
  624. $stmt->bindValue( ':pid',$Image->pid);
  625. $stmt->bindValue( ':aid',$Image->aid);
  626. foreach ($filterArray as $field => $filterValue){
  627. $stmt->bindValue( ':'.$field,$filterValue);
  628. }
  629. $stmt->execute();
  630. $photos = $stmt->fetchColumn();
  631. $page = ceil(($photos+1)/20);
  632. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  633. $q2 = $q->subSelect();
  634. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  635. $filterSQLArray = array();
  636. foreach ($filterArray as $field => $filterValue){
  637. $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
  638. }
  639. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  640. $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 ) ) .')')
  641. ->orderBy('rtime ASC, pid ASC')
  642. ->limit( 5 );
  643. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  644. $imagesRight = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  645. } elseif ($modeSort == 'toprated') {
  646. $db = ezcDbInstance::get();
  647. $session = erLhcoreClassGallery::getSession();
  648. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  649. $q2 = $q->subSelect();
  650. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  651. $filterSQLArray = array();
  652. $countSQLArray = array();
  653. $countSQL = '';
  654. $filterSQLString = '';
  655. foreach ($filterArray as $field => $filterValue){
  656. $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
  657. $countSQLArray[] = "lh_gallery_images.{$field} = :$field";
  658. }
  659. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  660. $countSQL = ' AND '.implode(' AND ',$countSQLArray);
  661. $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 ) ).')')
  662. ->orderBy('pic_rating ASC, votes ASC, pid ASC')
  663. ->limit( 5 );
  664. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  665. $imagesLeft = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  666. $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);
  667. $stmt->bindValue( ':pic_rating',$Image->pic_rating);
  668. $stmt->bindValue( ':votes',$Image->votes);
  669. $stmt->bindValue( ':pid',$Image->pid);
  670. $stmt->bindValue( ':aid',$Image->aid);
  671. foreach ($filterArray as $field => $filterValue){
  672. $stmt->bindValue( ':'.$field,$filterValue);
  673. }
  674. $stmt->execute();
  675. $photos = $stmt->fetchColumn();
  676. $page = ceil(($photos+1)/20);
  677. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  678. $q2 = $q->subSelect();
  679. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  680. $filterSQLArray = array();
  681. foreach ($filterArray as $field => $filterValue){
  682. $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
  683. }
  684. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  685. $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 ) ).')')
  686. ->orderBy('pic_rating DESC, votes DESC, pid DESC')
  687. ->limit( 5 );
  688. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  689. $imagesRight = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  690. } elseif ($modeSort == 'topratedasc') {
  691. $db = ezcDbInstance::get();
  692. $session = erLhcoreClassGallery::getSession();
  693. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  694. $q2 = $q->subSelect();
  695. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  696. $filterSQLArray = array();
  697. $countSQLArray = array();
  698. $countSQL = '';
  699. $filterSQLString = '';
  700. foreach ($filterArray as $field => $filterValue){
  701. $filterSQLArray[] = $q2->expr->eq( $field, $filterValue );
  702. $countSQLArray[] = "lh_gallery_images.{$field} = :$field";
  703. }
  704. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  705. $countSQL = ' AND '.implode(' AND ',$countSQLArray);
  706. $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 ) ).')')
  707. ->orderBy('pic_rating DESC, votes DESC, pid DESC')
  708. ->limit( 5 );
  709. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  710. $imagesLeft = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  711. $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