Page 1 of 1

a new view: sections looking like section

Posted: 03 Feb 2010, 00:48
by ewel
I am trying to make a site where certain user groups get access to selected downloads, and users will get access to one or more sections in Phoca Download depending on their access rights. So the sections view is the best for this purpose, because if everything goes well users will get to see only those sections that they are allowed to see.

But frankly I didn't like the layout of the sections view, and I did like the layout of the single section view. So I set out to turn the sections view into a what looks like a repetitive section view - with the image and the description. I thought it might be nice to share here how I did it.


The first file to change is the model. The reason is that the sections model, unlike the section model, does not query the database for the image file and the description of sections. The file to edit is:
components/com_phocadownload/models/section.php

In line 93, where there is the first line of the query of the _getSectionListQuery method, you have to insert "s.image, s.description, " so that it ends up looking like this:

Code: Select all

$query =  " SELECT s.id, s.title, s.alias, s.image, s.description, COUNT(cc.id) AS numcat, '' AS categories"

The second file to work on is the sections view, which is found at:
components/com_phocadownload/views/sections/tmpl/default.php

You can either edit that file or you can use it to make a template override which I think is the best way. To make an override you can copy the file to templates/[yourtemplate]/html/com_phocadownload/sections/default.php.

In that file, you have to delete the following:

Code: Select all

		// Categories
		$numDoc 	= 0;
		$catOutput 	= '';
		foreach ($value->categories as $valueCat) {
			$catOutput 	.= '<p class="pd-category">';
			//$catOutput 	.= '<a href="'. JRoute::_('index.php?option=com_phocadownload&view=category&id='.$valueCat->id.':'.$valueCat->alias.'&Itemid='. JRequest::getVar('Itemid', 1, 'get', 'int')).'">'. $valueCat->title.'</a>';
			
			$catOutput 	.= '<a href="'. JRoute::_(PhocaDownloadHelperRoute::getCategoryRoute($valueCat->id, $valueCat->alias, $value->id)).'">'. $valueCat->title.'</a>';
			
			if ($this->tmpl['displaynumdocsecs'] == 1) {
				$catOutput  .=' <small>('.$valueCat->numdoc .')</small>';
			}
			
			$catOutput 	.= '</p>' . "\n";
			$numDoc = (int)$valueCat->numdoc + (int)$numDoc;
		}
		
		echo '<div class="pd-sections"><div><div><div><h3>';
		//echo '<a href="'. JRoute::_('index.php?option=com_phocadownload&view=section&id='.$value->id.':'.$value->alias.'&Itemid='. JRequest::getVar('Itemid', 1, 'get', 'int')).'">'. $value->title.'</a>';
		echo '<a href="'. JRoute::_(PhocaDownloadHelperRoute::getSectionRoute($value->id, $value->alias)).'">'. $value->title.'</a>';
		
		if ($this->tmpl['displaynumdocsecsheader'] == 1) {
			echo ' <small>('.$value->numcat.'/' . $numDoc .')</small>';
		}
		echo '</h3>';
		echo $catOutput;	
		echo '</div></div></div></div>';
		if ($i%3==0) {
			echo '<div style="clear:both"></div>';
		}
		$i++;
Finally, replace what you just deleted by this:

Code: Select all

		echo '<div id="phoca-dl-section-box">';
		echo '<div class="pd-section">';
		echo '<h3><a href="'. JRoute::_(PhocaDownloadHelperRoute::getSectionRoute($value->id, $value->alias)).'">'. $value->title.'</a></h3>';

		if (!empty($value->image)) {
			$attribs['align'] = '"'.$value->image_position.'"';
			$attribs['hspace'] = '"6"';
			$image = JHTML::_('image', 'images/stories/'.$value->image, JText::_('Phoca Download'), $attribs);
		} else {
			$image = '';
		}

		echo '<div class="contentpane'.$this->params->get( 'pageclass_sfx' ).'">';
		if ( (isset($image) && $image !='') || (isset($value->description) && $value->description != '' && $value->description != '<p>&#160;</p>')) {
			echo '<div class="contentdescription'.$this->params->get( 'pageclass_sfx' ).'">';
			if ( isset($image) ) {
				echo $image;
			}
			echo $value->description
				.'</div>';
		}
		echo '</div>';

		if (!empty($value->categories)) {  
			foreach ($value->categories as $valueCat) {
				echo '<p class="pd-category">';
				echo '<a href="'. JRoute::_(PhocaDownloadHelperRoute::getCategoryRoute($valueCat->id, $valueCat->alias, $value->id)).'">'. $valueCat->title.'</a>';
				echo ' <small>('.$valueCat->numdoc.')</small></p>' . "\n";
			}
			echo '</div>';
		} else {
			echo '<p>&nbsp;</p><p>&nbsp;</p>';
		}   
			echo '<p>&nbsp;</p></div>' ;

Now, each section listed in the sections view will look almost exactly as if it was shown in the section view.

Frankly, I'd recommend these changes to be made to the view as distributed but I suppose that's a matter of taste. In any case, to my taste, now Phoca Download looks great on every page!

Re: a new view: sections looking like section

Posted: 03 Feb 2010, 19:05
by Jan
Hi, thank you for this improvement.

Jan

Re: a new view: sections looking like section

Posted: 21 Jul 2010, 03:22
by jbourque
Ewel,

I have been trying to get this to work so however I'm getting an error in the section.php file with an

Parse error: syntax error, unexpected T_VARIABLE in /home/appealt/public_html/components/com_phocadownload/models/section.php on line 94

Could you attach the 2 files

Joe

Re: a new view: sections looking like section

Posted: 21 Jul 2010, 03:32
by jbourque
I found what I did wrong was missing a ; semicolon

I was hoping that this would add the description to the right side of the title in the section area

Joe

Re: a new view: sections looking like section

Posted: 26 Jul 2010, 16:22
by Jan
Ok