Finally, we come to the actual download area. This just needs to be a simple controller, which lists the users' entries from the access table, along with links to the corresponding downloads.
Our controller needs to query the database, cache the results, and add them to a template tag. Obviously, the controller also needs to check that the user is logged in; otherwise, an error message should be displayed.
private function listDownloads() { $this->registry->getObject('template')-> buildFromTemplates('header.tpl.php', 'downloads.tpl.php', 'footer.tpl.php'); $u = $this->registry->getObject('authenticate')->getUserID(); $sql = "SELECT p.name, d.file FROM content c, content_types_products p, download_access d WHERE c.ID=d.product AND p.content_version=c.current_revision AND d.user_id={$u}"; $cache = $this->registry->getObject('db')->cacheQuery( $sql ); $this->registry->getObject('template')->getPage()-> addTag('downloads', array( 'SQL', $cache ) ); }
The corresponding view file would look like this:
<h1>Downloads</h1> <ul> <!-- START downloads --> <li><a href="ourdownloadarea/{file}">{name}</a></li> <!-- END downloads --> </ul>