Controller_ProjectList.class.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * Controller for listing projects
  4. *
  5. * @author Christopher Han <xiphux@gmail.com>
  6. * @copyright Copyright (c) 2010 Christopher Han
  7. * @package GitPHP
  8. * @subpackage Controller
  9. */
  10. class GitPHP_Controller_ProjectList extends GitPHP_ControllerBase
  11. {
  12. /**
  13. * Initialize controller
  14. */
  15. public function Initialize()
  16. {
  17. $this->multiProject = true;
  18. parent::Initialize();
  19. if ($this->userList && ($this->userList->GetCount() > 0)) {
  20. if (!$this->config->GetValue('showrestrictedprojects') || (isset($this->params['opml']) && ($this->params['opml'] === true)) || (isset($this->params['txt']) && ($this->params['txt'] === true))) {
  21. $this->projectList->FilterByUser((!empty($_SESSION['gitphpuser']) ? $_SESSION['gitphpuser'] : null));
  22. }
  23. }
  24. if (empty($this->params['sort']))
  25. $this->params['sort'] = 'project';
  26. }
  27. /**
  28. * Gets the template for this controller
  29. *
  30. * @return string template filename
  31. */
  32. protected function GetTemplate()
  33. {
  34. if (isset($this->params['opml']) && ($this->params['opml'] === true)) {
  35. return 'opml.tpl';
  36. } else if (isset($this->params['txt']) && ($this->params['txt'] === true)) {
  37. return 'projectindex.tpl';
  38. }
  39. return 'projectlist.tpl';
  40. }
  41. /**
  42. * Gets the cache key for this controller
  43. *
  44. * @return string cache key
  45. */
  46. protected function GetCacheKey()
  47. {
  48. $cachekey = (!empty($_SESSION['gitphpuser']) ? $_SESSION['gitphpuser'] : '');
  49. if (isset($this->params['opml']) && ($this->params['opml'] === true)) {
  50. return $cachekey;
  51. } else if (isset($this->params['txt']) && ($this->params['txt'] === true)) {
  52. return $cachekey;
  53. }
  54. $cachekey .= '|' . $this->params['sort'] . '|' . (isset($this->params['search']) ? $this->params['search'] : '');
  55. return $cachekey;
  56. }
  57. /**
  58. * Gets the name of this controller's action
  59. *
  60. * @param boolean $local true if caller wants the localized action name
  61. * @return string action name
  62. */
  63. public function GetName($local = false)
  64. {
  65. if (isset($this->params['opml']) && ($this->params['opml'] === true)) {
  66. if ($local && $this->resource) {
  67. return $this->resource->translate('opml');
  68. }
  69. return 'opml';
  70. } else if (isset($this->params['txt']) && ($this->params['txt'] === true)) {
  71. if ($local && $this->resource) {
  72. return $this->resource->translate('project index');
  73. }
  74. return 'project index';
  75. }
  76. if ($local && $this->resource) {
  77. return $this->resource->translate('projects');
  78. }
  79. return 'projects';
  80. }
  81. /**
  82. * Loads headers for this template
  83. */
  84. protected function LoadHeaders()
  85. {
  86. if (isset($this->params['opml']) && ($this->params['opml'] === true)) {
  87. $this->headers[] = "Content-type: text/xml; charset=UTF-8";
  88. $this->DisableLogging();
  89. $this->preserveWhitespace = true;
  90. } else if (isset($this->params['txt']) && ($this->params['txt'] === true)) {
  91. $this->headers[] = "Content-type: text/plain; charset=utf-8";
  92. $this->headers[] = "Content-Disposition: inline; filename=\"index.aux\"";
  93. $this->DisableLogging();
  94. } else {
  95. parent::LoadHeaders();
  96. }
  97. }
  98. /**
  99. * Loads data for this template
  100. */
  101. protected function LoadData()
  102. {
  103. $this->tpl->assign('sort', $this->params['sort']);
  104. $this->projectList->Sort($this->params['sort']);
  105. if ((empty($this->params['opml']) || ($this->params['opml'] !== true)) &&
  106. (empty($this->params['txt']) || ($this->params['txt'] !== true)) &&
  107. (!empty($this->params['search']))) {
  108. $this->tpl->assign('search', $this->params['search']);
  109. $matches = $this->projectList->Filter($this->params['search']);
  110. if (count($matches) > 0) {
  111. $this->tpl->assign('projectlist', $matches);
  112. }
  113. } else {
  114. if ($this->projectList->Count() > 0)
  115. $this->tpl->assign('projectlist', $this->projectList);
  116. }
  117. }
  118. }