Tagged file list improvements
Posted: 27 May 2018, 10:20
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
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
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:
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) {
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
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 {
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>';
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
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
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