Tagged file list improvements

Phoca Download - download manager
rogerco
Phoca Member
Phoca Member
Posts: 47
Joined: 18 Sep 2011, 16:17

Tagged file list improvements

Post by rogerco »

Hi,
A couple of quick improvements to the list of tagged files layout to share. (longish post, includes proposed code modifications, there's a link to a working example at the end)

At the moment when you click on a tag in a file's details (or use that url in a menu item) you get a list of all files sharing that tag. This uses the category display layout but there is no header at the top saying what the list is (if it is a straight category list then you can display the category title and description at the top).

In fact it seems that the tag description is never ever used within the component; it would be logical to display it when showing a list of tagged files.

If you create a template override for com_phocadownload then in the category section you will see at around line 12 in default.php and/or default_bootstrap.php the following

Code: Select all

if ((int)$this->t['tagid'] > 0) {
 	echo $this->loadTemplate('files');
	$this->checkRights = 1;
	if (count($this->files)) {
		echo $this->loadTemplate('pagination');
	}
} else {
Thus if a tagid is specified it simply calls the files list without displaying any header (compare with the lines following the "} else { where if it is a full category list a whole load of header creation stuff is done before calling the file list layout around line 95)

So you could simply insert a line to create a static header at line 13. eg

Code: Select all

echo '<h3>This is a list of tagged files</h3>';
But it would be nice to include the tag title and also follow it with the description. Unfortunately I couldn't find an existing function to pull out the details of a single tag in the component models. You can't modify these files using Joomla template overrides so you are going to have to modify them in the originals and keep a record of what you've done so that you can recreate them when a phocadownload update overwrites your changes.

The quickest and simplest change seemed to be to add a function in the category model file to get details of a tag by id, and then use that in the template override file.

So at the end of file /components/com_phocadownload/models/category.php insert a new function before closing "} ?>" at end around line 271:

Code: Select all

// added RCO function to return info about one tag 
  	function getTag($tagId) {
		$query = 'SELECT a.* FROM #__phocadownload_tags AS a WHERE a.id = '.(int)$tagId;
        	$tagIdObject = $this->_getList( $query, 0, 1 );
	    	return $tagIdObject;            
	}
 //end RCO
The easiest way to do this is using the very useful PhocaCommander component but do be careful on a live site, test offline first if possible.

Now we can call this function from the category layout file in your template override
[template files]/html/com_phocadownload/category/default.php and/or default_bootstrap.php if you are using that
Insert the following at line 13 after if ((int)$this->t['tagid'] > 0) {

Code: Select all

//added RCO to display tag details
	$model = $this->getModel();
	if(method_exists($model,'getTag')){
		$tag = $model->getTag((int)$this->t['tagid']);
		echo '<h3>List of files tagged "'.$tag[0]->title.'"</h3>';
		echo '<p>'.$tag[0]->description.'</p>';
	}
//end RCO
Do this using template override rather than modifying the core file so you can revert easily and are protected from updates loosing your changes.
The test if method_exists will prevent errors if your modification to models/category.php gets overwritten in an update.

This needs some tidying up - there may be a better way of integrating the function into a model and of referencing the returned values. The hard coded string "List of files tagged" should be a language string, whether to display the tag title could be a parameter option etc etc.

In the longer term a whole new set of views and a model specific to document tags needs creating, but this serves as a start. You can see it working here: http://www.green-history.uk/library/doc ... ag?tagid=9.

I will probably start working on this slowly for my own use - if anyone else is interested reply here and I will post anything I develop - but don't expect a quick result!

RogerCO

Tags:
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48402
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Tagged file list improvements

Post by Jan »

Hi, thank you very much for the improvements, yes it would be great if you share all the improvements here.

Thank you, Jan
If you find Phoca extensions useful, please support the project
rogerco
Phoca Member
Phoca Member
Posts: 47
Joined: 18 Sep 2011, 16:17

Re: Tagged file list improvements - update

Post by rogerco »

Whoops, forgot to check that the tag you are trying to list files for actually exists :oops:

Also it is nice to list the number of files found at the top of the list.

Update to code to go in default.php override:

Code: Select all

	$model = $this->getModel();
	if(method_exists($model,'getTag')){
		$tag = $model->getTag((int)$this->t['tagid']);
        	if ($tag) {
			echo '<h3>List of files tagged "'.$tag[0]->title.'"</h3>';
			echo '<p>'.$tag[0]->description.'</p>'; 
          		echo '<h4>'.$this->t['pagination']->total.' files found</h4>';
        	} else {
          		echo 'Tag with id = '.(int)$this->t['tagid'].' appears not to exist';
        	}
	}
Cheers, Roger
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48402
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Tagged file list improvements

Post by Jan »

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