public function getPrevious($catid, $id, $ordering)
{
$app = Factory::getApplication();
$db = Factory::getDBO();
$params = $app->getParams();
$detailWindow = $params->get('detail_window', 0);
if ($detailWindow == 7) {
$tCom = '';
} else {
$tCom = '&tmpl=component';
}
$c = $this->_imgordering['column'];
$s = $this->_imgordering['sort'];
$sP = $s == 'ASC' ? '<' : '>';
$sR = $s == 'ASC' ? 'DESC' : 'ASC';
if ($c == 'count' || $c == 'average') {
$query = 'SELECT a.id, a.alias, c.id as catid, c.alias as catalias, a.filename as filename, b.id AS currentid,' . ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as catslug,' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug' . ' FROM #__phocagallery AS a' . ' LEFT JOIN #__phocagallery_img_votes_statistics AS ra ON ra.imgid = a.id,' . ' #__phocagallery AS b' . ' LEFT JOIN #__phocagallery_categories AS c ON c.id = b.catid' . ' LEFT JOIN #__phocagallery_img_votes_statistics AS rb ON rb.imgid = b.id' . ' WHERE a.catid = ' . (int) $catid . ' AND b.id = ' . (int) $id . ' AND (' . ' (ra.' . $c . ' = rb.' . $c . ' AND a.id ' . $sP . ' b.id) OR ' . ' (CASE WHEN ra.' . $c . ' IS NOT NULL AND rb.' . $c . ' IS NOT NULL THEN ra.' . $c . ' ' . $sP . ' rb.' . $c . ' END) OR ' . ' (CASE WHEN ra.' . $c . ' IS NULL AND rb.' . $c . ' IS NOT NULL THEN 0 ' . $sP . ' rb.' . $c . ' END) OR ' . ' (CASE WHEN ra.' . $c . ' IS NOT NULL AND rb.' . $c . ' IS NULL THEN ra.' . $c . ' ' . $sP . ' 0 END) OR ' . ' (CASE WHEN ra.' . $c . ' IS NULL AND rb.' . $c . ' IS NULL THEN a.id ' . $sP . ' b.id END) ' . ')' . ' AND a.published = 1' . ' ORDER BY ra.' . $c . ' ' . $sR . ', a.id ' . $sR;
} else {
$query = 'SELECT a.id, a.alias, c.id as catid, c.alias as catalias, a.filename as filename, b.id AS currentid,' . ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as catslug,' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug' . ' FROM #__phocagallery AS a,' . ' #__phocagallery AS b' . ' LEFT JOIN #__phocagallery_categories AS c ON c.id = b.catid' . ' WHERE a.catid = ' . (int) $catid . ' AND b.id = ' . (int) $id . ' AND (a.' . $c . ' ' . $sP . ' b.' . $c . ' OR (a.' . $c . ' = b.' . $c . ' and a.id ' . $sP . ' b.id))' . ' AND a.published = 1' . ' ORDER BY a.' . $c . ' ' . $sR . ', a.id ' . $sR;
}
$db->setQuery($query);
$prevAll = $db->loadObjectList();
$class = 'pg-imgbgd';
$imgName = 'icon-prev';
$idCss = '';
if ($this->type == 'multibox') {
$class = 'pg-imgbd-multibox-prev';
$imgName = 'icon-prev-multibox';
$idCss = ' id="phocagallerymultiboxprev" ';
}
$prev = '<div class="' . $class . '"' . $idCss . '>';
if ($this->type == 'multibox') {
$prev .= HTMLHelper::_('image', 'media/com_phocagallery/images/' . $imgName . '-grey.png', Text::_('COM_PHOCAGALLERY_PREV_IMAGE')) . '</div>';
} else {
$prev .= PhocaGalleryRenderFront::renderIcon('prev', 'media/com_phocagallery/images/icon-prev-grey.png', Text::_('COM_PHOCAGALLERY_PREV_IMAGE'), 'ph-icon-disabled') . '</div>';
}
foreach ($prevAll as $key => $value) {
if (isset($value->id) && $value->id > 0) {
$href = Route::_(PhocaGalleryRoute::getImageRoute($value->id, $value->catid, $value->alias, $value->catalias) . $tCom);
$prev = '<div class="' . $class . '"' . $idCss . '>' . '<a href="' . $href . '"' . ' title="' . Text::_('COM_PHOCAGALLERY_PREV_IMAGE') . '" id="prev" >';
if ($this->type == 'multibox') {
$prev .= HTMLHelper::_('image', 'media/com_phocagallery/images/' . $imgName . '.png', Text::_('COM_PHOCAGALLERY_PREV_IMAGE')) . '</a></div>';
} else {
$prev .= PhocaGalleryRenderFront::renderIcon('prev', 'media/com_phocagallery/images/icon-prev.png', Text::_('COM_PHOCAGALLERY_PREV_IMAGE'), '') . '</a></div>';
}
break;
} else {
$prev = '<div class="' . $class . '"' . $idCss . '>';
if ($this->type == 'multibox') {
$prev .= HTMLHelper::_('image', 'media/com_phocagallery/images/' . $imgName . '-grey.png', Text::_('COM_PHOCAGALLERY_PREV_IMAGE')) . '</div>';
} else {
$prev .= PhocaGalleryRenderFront::renderIcon('prev', 'media/com_phocagallery/images/icon-prev-grey.png', Text::_('COM_PHOCAGALLERY_PREV_IMAGE'), 'ph-icon-disabled') . '</div>';
}
break;
}
}
return $prev;
}