com.lokorin.lokorin.modules
[ class tree: com.lokorin.lokorin.modules ] [ index: com.lokorin.lokorin.modules ] [ all elements ]

Source for file module_download.php

Documentation is available at module_download.php

  1. <?php
  2. /*
  3. * Lokorin.com
  4. * Copyright 2004-2006
  5. * Licensed under the GNU LGPL. See COPYING for full terms.
  6. */
  7. /**
  8. * A project module that displays all download items connected to a project.
  9. * @author Andreas Launila
  10. * @version $Revision: 1.11 $
  11. * @package com.lokorin.lokorin.modules
  12. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  13. */
  14. /**
  15. * For access to common constants and functions.
  16. */
  17. require_once('common.php');
  18. doInclude('lib_projects');
  19. doInclude('lib_downloads');
  20. doInclude('lib_tables');
  21.  
  22. //Check if anything should be downloaded.
  23. if(isset($_GET['id']) && is_numeric($_GET['id'])) {
  24. //Attempt to download the download item with the corresponding unique
  25. //identifier.
  26. try {
  27. $downloadItem = new DownloadItem($_GET['id']);
  28. $downloadItem->download();
  29. } catch(Exception $e) {
  30. logException(new IllegalArgumentException('An invalid download item ' .
  31. 'with id ('.$_GET['id'].') was requested.'));
  32. die('Invalid download.');
  33. }
  34. exit;
  35. }
  36.  
  37. Page::getInstance()->setTitle('Download');
  38. try {
  39. $project = getProjectBasedOnDir();
  40. Page::getInstance()->setProject($project);
  41. } catch(Exception $e) {
  42. logFatalException($e);
  43. }
  44.  
  45. //Display the actual downloads.
  46. $groupedDownloads = $project->getDownloadsGroupedByCategory();
  47. if(count($groupedDownloads) > 0) {
  48. $firstHeader = new Header(array('Name', 'Description', 'Size', 'Link', 'Language'));
  49. $restHeader = new Header(array('Name', 'Size', 'Link', 'Language'));
  50. $isFirstTable = true;
  51. foreach($groupedDownloads as $categoryId => $downloads) {
  52. try {
  53. $category = new DownloadCategory($categoryId);
  54. } catch(IllegalArgumentException $e) {
  55. logException(IllegalStateException("Illegal category id (".
  56. $categoryId.") specified."));
  57. continue;
  58. }
  59. $downloads = sortDownloadsByPopularity($downloads);
  60. $table = new Table();
  61. if($isFirstTable) {
  62. $table->setHeader($firstHeader);
  63. } else {
  64. $table->setHeader($restHeader);
  65. }
  66. foreach($downloads as $download) {
  67. $row = array();
  68. $row[] = $download->getName();
  69. if($isFirstTable){
  70. //Only display the description for the first table.
  71. $row[] = $download->getDescription();
  72. }
  73. $row[] = $download->getSizeLabel();
  74. $row[] = '<a href="'.SELF.'?id='.$download->getId().'">Download</a>';
  75. $lang = $download->getLanguage();
  76. $row[] = $lang->getLink();
  77. $table->addRow($row);
  78. }
  79. if(!$isFirstTable) {
  80. //Don't display the caption for the first table.
  81. echo '<h2>'.$category->getName().'</h2>';
  82. } else {
  83. $isFirstTable = false;
  84. }
  85. echo $table->getTable();
  86. }
  87. } else {
  88. echo 'No downloads were found.';
  89. }
  90.  
  91. Page::getInstance()->display();
  92. ?>

Documentation generated on Sun, 16 Apr 2006 21:04:01 +0200 by phpDocumentor 1.3.0RC4