Dynamic menu item

126 views
Skip to first unread message

Keith Blackie

unread,
Jun 16, 2010, 11:44:00 PM6/16/10
to joomla-de...@googlegroups.com
I have a need for something that I have not yet seen in any of the available extensions.
 
I am using a component that builds a list of uploaded files sorted by category and displays them to the user to select and download as desired. However, I would like to take it one step further in that I would like to assign that display as an archive on the menu and have another menu item that automatically points to the last uploaded file.
 
The scenario is that we save our newsletters to the server in an archive for anyone to download in the future, but we have several hundred in the archive. In order to make it as simple as possible, we would like to have the last newsletter uploaded connected to a menu item. I can't allow the person creating the newsletter access to the backend because they would just mess things up... but they can upload the files easily enough.
 
Is it possible to cause a menu click to download a file without hard coding it as a URL? I can write whatever code is necessary, but I am not sure of the technical aspects of pointing a menu item to a script that downloads the latest file.
 
The way I envision it is the user clicks the menu, it calls the function to read the database list of files uploaded, gets the ID for the latest one uploaded, grabs the file and serves it up to the user.


I hope this is making sense. 
 
Keith Blackie

Matt Thomas

unread,
Jun 17, 2010, 8:56:45 AM6/17/10
to joomla-de...@googlegroups.com
Hi Keith,

I have a few thoughts for you.

Does the mot recent newsletter always have the same name? If so, you could use an external link menu item type pointing at that file (i.e. newsletters/latest.pdf).

I also see no reason why you couldn't point an external menu item to a script that grabs the latest article and triggers a file download. I just tested triggering a PHP script with a menu item and it worked.

You may want to take a look at DOCman . Combined with their productivity pack, both extremely cheap, it supports mass file uploads into categories as well as has a module that displays the last X number of uploaded files. You could always create a menu that points to an article that has the module embedded using {loadposition} .

Best,

Matt

Matt Thomas
Founder - betweenbrain
web • print • identity • creative
www.betweenbrain.com

betweenbrain at The Joomla! Resources Directory™ - http://betweenbra.in/resources

Joomla! 1.6 Nightly Build http://betweenbra.in/x/7
Joomla! 1.6 Issue Tracker http://betweenbra.in/x/5



--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.

Keith Blackie

unread,
Jun 17, 2010, 9:23:10 AM6/17/10
to joomla-de...@googlegroups.com
Matt,
 
You gave me something to consider. The newsletter isn't always the same name, but if I can call an external php script to return a web page that triggers a download, that would be the resolution. I can sort the files server side and return the latest one easily enough.
 
The reason the files are named differently is because when they are uploaded, the upload script gives them a unique name so as to prevent the overwriting of existing files. The display name on the archive is for the user only. When they select the link, it finds the correct file from the database and serves it up.
 
Keith

Matt Thomas

unread,
Jun 17, 2010, 9:33:27 AM6/17/10
to joomla-de...@googlegroups.com
Hi Keith,

Glad I was able to give you something to consider. I fully understand and support the need for unique file names, I use them as well. It sounds like you are on the right path for your needs. It would be cool to see what you come up with when it's done. If you don't mind sharing, please drop us a note.


Best,

Matt

Matt Thomas
Founder - betweenbrain
web • print • identity • creative
www.betweenbrain.com

betweenbrain at The Joomla! Resources Directory™ - http://betweenbra.in/resources

Joomla! 1.6 Nightly Build http://betweenbra.in/x/7
Joomla! 1.6 Issue Tracker http://betweenbra.in/x/5



Keith Blackie

unread,
Jun 17, 2010, 10:12:39 AM6/17/10
to joomla-de...@googlegroups.com
Matt
 
After a bit of thought, I simply extended the functionality in the controller and model, while I am not yet sure how to build it into the admin side as a menu type, I can call it using an external URL and that works fine for now.

In the controller:
 
 function downloadlatest()
 {
  $catid  = JRequest::getVar( 'catid', array(0), 'get', 'array' );
  $model  = $this->getModel('files');
  $model->downloadlast( $catid[0] );
 }
In the model:
 
 function downloadLast($catid)
 {
                $query = "SELECT filename, type, size, path FROM #__filebucket WHERE id=(SELECT MAX(id) FROM #__filebucket WHERE cat_id=$catid)";
  $this->_db->setQuery( $query );
  $rows = $this->_db->loadRow();
  list($name, $type, $size, $filePath) = $rows;
  header("Content-Disposition: attachment; filename=$name");
  header("Content-length: $size");
  header("Content-type: $type");
  readfile($filePath);
}
 
On the menu item:
Type = External Link
 
Reply all
Reply to author
Forward
0 new messages