/*
* Get the next button in Gallery - in opened window
*/
public function getNext($catid, $id, $ordering, $hrefOnly = 0)
{
$app = Factory::getApplication();
$db = Factory::getDBO();
$paramsC = ComponentHelper::getParams('com_phocagallery');
$detailWindow = $paramsC->get('detail_window', 0);
if ($detailWindow == 7) {
$tCom = '';
} else {
$tCom = '&tmpl=component';
}
$c = $this->_imgordering['column'];
$s = $this->_imgordering['sort'];
$sP = $s == 'DESC' ? '<' : '>';
$sR = $s == 'ASC' ? 'DESC' : 'ASC';
//Select all ids from db_gallery - we search for next_id (!!! next_id can be id without file
//in the server. If the next id has no file in the server we must go from next_id to next next_id
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 . ' ' . $s . ', a.id ' . $s;
} 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 . ' ' . $s . ', a.id ' . $s;
}
$db->setQuery($query);
$nextAll = $db->loadObjectList();
$class = 'pg-imgbgd';
$imgName = 'icon-next';
$idCss = '';
if ($this->type == 'multibox') {
$class = 'pg-imgbd-multibox-next';
$imgName = 'icon-next-multibox';
$idCss = ' id="phocagallerymultiboxnext" ';
}
$href = '';
$next = '<div class="' . $class . '"' . $idCss . '>';
if ($this->type == 'multibox') {
$next .= HTMLHelper::_('image', 'media/com_phocagallery/images/' . $imgName . '-grey.png', Text::_('COM_PHOCAGALLERY_NEXT_IMAGE')) . '</div>';
} else {
$next .= PhocaGalleryRenderFront::renderIcon('next', 'media/com_phocagallery/images/icon-next-grey.png', Text::_('COM_PHOCAGALLERY_NEXT_IMAGE'), 'ph-icon-disabled') . '</div>';
}
//non-active button will be displayed as Default, we will see if we find active link
foreach ($nextAll as $key => $value) {
// Is there some next id, if not end this and return grey link
if (isset($value->id) && $value->id > 0) {
// onclick="disableBackAndNext()"
//$href = JRoute::_('index.php?option=com_phocagallery&view=detail&catid='. $value->catslug.'&id='.$value->slug.$tCom.'&Itemid='. JFactory::getApplication()->input->get('Itemid', 1, 'get', 'int'));
$href = Route::_(PhocaGalleryRoute::getImageRoute($value->id, $value->catid, $value->alias, $value->catalias) . $tCom);
$next = '<div class="' . $class . '"' . $idCss . '>' . '<a href="' . $href . '"' . ' title="' . Text::_('COM_PHOCAGALLERY_NEXT_IMAGE') . '" id="next" >';
if ($this->type == 'multibox') {
$next .= HTMLHelper::_('image', 'media/com_phocagallery/images/' . $imgName . '.png', Text::_('COM_PHOCAGALLERY_NEXT_IMAGE')) . '</div>';
} else {
$next .= PhocaGalleryRenderFront::renderIcon('next', 'media/com_phocagallery/images/icon-next.png', Text::_('COM_PHOCAGALLERY_NEXT_IMAGE')) . '</div>';
}
break;
// end it, we must need not to find next ordering
} else {
$href = '';
$next = '<div class="' . $class . '"' . $idCss . '>';
if ($this->type == 'multibox') {
$next .= HTMLHelper::_('image', 'media/com_phocagallery/images/' . $imgName . '-grey.png', Text::_('COM_PHOCAGALLERY_NEXT_IMAGE')) . '</div>';
} else {
$next .= PhocaGalleryRenderFront::renderIcon('next', 'media/com_phocagallery/images/icon-next-grey.png', Text::_('COM_PHOCAGALLERY_NEXT_IMAGE'), 'ph-icon-disabled') . '</div>';
}
//.JHtml::_('image', 'media/com_phocagallery/images/'.$imgName.'-grey.png', JText::_( 'COM_PHOCAGALLERY_NEXT_IMAGE' )).'</div>';
break;
// end it, we must need not to find next ordering
}
}
if ($hrefOnly == 1) {
return $href;
}
return $next;
}