Display New Icon also in categories view

Phoca Gallery - image gallery extension
rodedo
Phoca Member
Phoca Member
Posts: 16
Joined: 12 Sep 2017, 10:04

Display New Icon also in categories view

Post by rodedo »

For the Category view there is the option to show a "new" icon on the pictures for a given number of days after upload.
Is there the possibility to show the same icon also in categories view on a new category or on a category that contains "new" pictures?
If the answer is not (as I assume because I did not find the related setting), can some-one point to the files where this functionality is implemented for the images and the files to eventually override for implementing it in the categories view?
Thanks!
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 47794
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Display New Icon also in categories view

Post by Jan »

Hi,

for now there is no such option, so yes, this needs to be customized directly in the code. It depends on where you want to display it. E.g. in categories view you need to load all images from selected category and get information about each image.

Unfortunately I didn't do such customization yet, so cannot give any clue specific advice.

For images it works this way:

Code: Select all

PhocaGalleryRenderFront::getOverImageIcons($cv->date, $cv->hits);
Ask the getOverImageIcons function for displaying the icons.

The function is located here:
administrator\components\com_phocagallery\libraries\phocagallery\render\renderfront.php

So in fact you need to load the images from the category, ask each image for this function and when some of the image should get this icon, you should mark the category then. :idea:

Jan
If you find Phoca extensions useful, please support the project
rodedo
Phoca Member
Phoca Member
Posts: 16
Joined: 12 Sep 2017, 10:04

Re: Display New Icon also in categories view

Post by rodedo »

Thanks to your info, I could easily add the "new" icon on new categories based on the category date, but I am having an hard time in "getting" the list of images within the category in order to loop through them...
I saw how you loop through images in: /com_phocagallery/category/default_images.php ( foreach($this->items ...) ) but, obviously, the object $this is different in "categories" view and in "category" view; could you give me an hint on how to create / access the object which contains all image from within categories view?
So far I have created an override in my template for the file: /com_phocagallery/categories/default_categories.php, changing it as follows:

Code: Select all

$this->cv = new stdClass();
//added
echo '<style type="text/css">'. "\n";
echo '		.pg-csv-box {'. "\n";
echo '			position: relative;'. "\n";
echo '		}'. "\n";
echo '	  </style>'. "\n";
//stop add
echo '<div id="pg-msnr-container">';
print_r ($this->cv);
foreach ($this->categories as $ck => $cv){
	echo '<div class="pg-csv-box">'."\n";
	echo ' <div class="pg-csv-box-img pg-box1">'. "\n";
	echo '  <div class="pg-box2">'. "\n";
	echo '   <div class="pg-box3">'. "\n";
	echo '<a href="'.$cv->link.'">'. "\n";
	if (isset($cv->mosaic) && $cv->mosaic != '') {
		echo $cv->mosaic;
	} else if (isset($cv->extpic) && $cv->extpic != '') {
		$correctImageRes = PhocaGalleryPicasa::correctSizeWithRate($cv->extw, $cv->exth, $this->tmpl['picasa_correct_width'], $this->tmpl['picasa_correct_height']);
		//echo JHtml::_( 'image', $cv->linkthumbnailpath, $cv->title, array('width' => $correctImageRes['width'], 'height' => $correctImageRes['height']));
		echo JHtml::_( 'image', $cv->linkthumbnailpath, $cv->title, array( 'style' => 'width:'. $correctImageRes['width'] .'px;height:'.$correctImageRes['height'] .'px;'));
	} else {
		echo JHtml::_( 'image', $cv->linkthumbnailpath, $cv->title);
	}
	echo '</a>'. "\n";
//added
	$rdd_catdate = PhocaGalleryRenderFront::getOverImageIcons($cv->date, $cv->hits);
	if ($rdd_catdate == '') {
		//here loop through images and pass image dates and hits to function, break loop as soon as function returns something different than '';
	} else {
		echo $rdd_catdate;
	}
// stop add
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 47794
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Display New Icon also in categories view

Post by Jan »

Hi, yes, the object this is different in categories view (load categories) and in category view (load images), so you need to load the images from the category manually - see the model:

components/com_phocagallery/models/category.php - this model loads list of images for category view, so such functions can be copied to load the information about new images (of course the sql should be simplified, because of memory resources, you should ask the database only the columns/data you really need - the image date)

Jan
If you find Phoca extensions useful, please support the project
rodedo
Phoca Member
Phoca Member
Posts: 16
Joined: 12 Sep 2017, 10:04

Re: Display New Icon also in categories view

Post by rodedo »

Thanks, I was indeed going in this direction, but I complicated my life by trying to reuse the model functions instead of copying them...
Anyway, I did it and I am posting it for others to benefit and eventually for merging it in next official version?!
I have created an override for the categories view in my template and I modified only the default_categories.php file adding the following block at the beginning of the file, right after the 'defined('_JEXEC') or die('Restricted access');' statement:

Code: Select all

// added by Rosario De Domenico, mutuated by category.php model
function rdd_buildQuery($rdd_cat) {
	$app = JFactory::getApplication();
	$user = JFactory::getUser();
	$params = $app->getParams();
	$wheres = array();
	$enable_overlib	= $params->get( 'enable_overlib', 0 );
	$imageOrdering = PhocaGalleryOrdering::getOrderingString($rdd_cat->ordering, 1);
	$cimgid = $app->input->get( 'cimgid', 0, 'int');
	if ($cimgid > 0) {
		$wheres[] = ' a.id = '.(int)$cimgid;
	}
	$selectUser = '';
	$leftUser = '';
	if ($enable_overlib > 3) {
		$selectUser	= ', ua.id AS userid, ua.username AS username, ua.name AS usernameno';
		$leftUser 	= ' LEFT JOIN #__users AS ua ON ua.id = a.userid';
	}
	$published  = ' AND a.published = 1';
	$published .= ' AND a.approved = 1';
	$wheres[]	= ' a.catid= '.(int)$rdd_cat->id;
	$leftCat	= ' LEFT JOIN #__phocagallery_categories AS cc ON cc.id = a.catid';
	$query		= 'SELECT a.*, cc.alias AS catalias, cc.accessuserid AS cataccessuserid, cc.access AS cataccess,'
				. ' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(\':\', cc.id, cc.alias) ELSE cc.id END as catslug'
				. $selectUser
				.' FROM #__phocagallery AS a'
				.' LEFT JOIN #__phocagallery_img_votes_statistics AS r ON r.imgid = a.id'
				. $leftCat
				. $leftUser
				. $leftTag
				. ' WHERE ' . implode( ' AND ', $wheres )
				. $published
				. $imageOrdering['output'];
	return $query;
}

function rdd_getImages($rdd_query) {
	$db = JFactory::getDbo();
	$db->setQuery($rdd_query);
	$row = $db->loadObjectList();
	return $row;
}

echo '<style type="text/css">'. "\n";
echo '		.pg-csv-box {'. "\n";
echo '			position: relative;'. "\n";
echo '		}'. "\n";
echo '	  </style>'. "\n";
//end add
and the following block inside the main foreach loop, right after the closure of the <a> tag (statement: 'echo '</a>'. "\n";'):

Code: Select all

// added by Rosario De Domenico
	$rdd_catdate = PhocaGalleryRenderFront::getOverImageIcons($cv->date, $cv->hits);
	if ($rdd_catdate == '') { // category is not new, let's check images inside it
		$query = rdd_buildQuery($cv);
		$images = rdd_getImages($query);
		foreach($images as $img) {
			$rdd_imgdate = PhocaGalleryRenderFront::getOverImageIcons($img->date, $img->hits);
			if ($rdd_imgdate != '') {
				echo $rdd_imgdate;
				break;
			}
		}
	} else { // category it-self is new
		echo $rdd_catdate;
	}
//end add (no other changes)
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 47794
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Display New Icon also in categories view

Post by Jan »

Ok, thank you for the code.

Jan
If you find Phoca extensions useful, please support the project
Post Reply