PageRenderTime 129ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/source/components/com_pfprojects/site/views/projects/view.html.php

https://github.com/projectfork/Projectfork
PHP | 221 lines | 129 code | 43 blank | 49 comment | 22 complexity | 2a7b949c53ea53f3d14e0157166d39cf MD5 | raw file
  1. <?php
  2. /**
  3. * @package pkg_projectfork
  4. * @subpackage com_pfprojects
  5. *
  6. * @author Tobias Kuhn (eaxs)
  7. * @copyright Copyright (C) 2006-2013 Tobias Kuhn. All rights reserved.
  8. * @license http://www.gnu.org/licenses/gpl.html GNU/GPL, see LICENSE.txt
  9. */
  10. defined('_JEXEC') or die();
  11. jimport('joomla.application.component.view');
  12. /**
  13. * Project list view class.
  14. *
  15. */
  16. class PFprojectsViewProjects extends JViewLegacy
  17. {
  18. protected $pageclass_sfx;
  19. protected $items;
  20. protected $pagination;
  21. protected $params;
  22. protected $state;
  23. protected $access;
  24. protected $toolbar;
  25. protected $sort_options;
  26. protected $order_options;
  27. /**
  28. * Display the view
  29. *
  30. * @return void
  31. */
  32. public function display($tpl = null)
  33. {
  34. $app = JFactory::getApplication();
  35. $active = $app->getMenu()->getActive();
  36. $this->items = $this->get('Items');
  37. $this->pagination = $this->get('Pagination');
  38. $this->state = $this->get('State');
  39. $this->params = $this->state->get('params');
  40. $this->access = PFprojectsHelper::getActions();
  41. $this->toolbar = $this->getToolbar();
  42. $this->sort_options = $this->getSortOptions();
  43. $this->order_options = $this->getOrderOptions();
  44. // Escape strings for HTML output
  45. $this->pageclass_sfx = htmlspecialchars($this->params->get('pageclass_sfx'));
  46. // Check for errors
  47. if (count($errors = $this->get('Errors'))) {
  48. JError::raiseError(500, implode("\n", $errors));
  49. return false;
  50. }
  51. // Check for empty filter result
  52. if ((count($this->items) == 0) && $this->state->get('filter.isset')) {
  53. $app->enqueueMessage(JText::_('COM_PROJECTFORK_EMPTY_SEARCH_RESULT'));
  54. }
  55. // Check for layout override
  56. if (isset($active->query['layout']) && (JRequest::getCmd('layout') == '')) {
  57. $this->setLayout($active->query['layout']);
  58. }
  59. // Prepare the document
  60. $this->prepareDocument();
  61. // Display the view
  62. parent::display($tpl);
  63. }
  64. /**
  65. * Prepares the document
  66. *
  67. * @return void
  68. */
  69. protected function prepareDocument()
  70. {
  71. $app = JFactory::getApplication();
  72. $menu = $app->getMenu()->getActive();
  73. $pathway = $app->getPathway();
  74. $title = null;
  75. // Because the application sets a default page title, we need to get it from the menu item itself
  76. if ($menu) {
  77. $this->params->def('page_heading', $this->params->get('page_title', $menu->title));
  78. }
  79. else {
  80. $this->params->def('page_heading', JText::_('COM_PROJECTFORK_PROJECTS'));
  81. }
  82. // Set the page title
  83. $title = $this->params->get('page_title', '');
  84. if (empty($title)) {
  85. $title = $app->getCfg('sitename');
  86. }
  87. elseif ($app->getCfg('sitename_pagetitles', 0) == 1) {
  88. $title = JText::sprintf('JPAGETITLE', $app->getCfg('sitename'), $title);
  89. }
  90. elseif ($app->getCfg('sitename_pagetitles', 0) == 2) {
  91. $title = JText::sprintf('JPAGETITLE', $title, $app->getCfg('sitename'));
  92. }
  93. $this->document->setTitle($title);
  94. // Set crawler behavior info
  95. if ($this->params->get('robots')) {
  96. $this->document->setMetadata('robots', $this->params->get('robots'));
  97. }
  98. // Set page description
  99. if ($this->params->get('menu-meta_description')) {
  100. $this->document->setDescription($desc);
  101. }
  102. // Set page keywords
  103. if ($this->params->get('menu-meta_keywords')) {
  104. $this->document->setMetadata('keywords', $keywords);
  105. }
  106. // Add feed links
  107. if ($this->params->get('show_feed_link', 1)) {
  108. $link = '&format=feed&limitstart=';
  109. $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
  110. $this->document->addHeadLink(JRoute::_($link . '&type=rss'), 'alternate', 'rel', $attribs);
  111. $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
  112. $this->document->addHeadLink(JRoute::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
  113. }
  114. }
  115. /**
  116. * Generates the toolbar for the top of the view
  117. *
  118. * @return string Toolbar with buttons
  119. */
  120. protected function getToolbar()
  121. {
  122. $access = PFprojectsHelper::getActions();
  123. $state = $this->get('State');
  124. $options = array();
  125. PFToolbar::button(
  126. 'COM_PROJECTFORK_ACTION_NEW',
  127. 'form.add',
  128. false,
  129. array('access' => $access->get('core.create'))
  130. );
  131. if ($access->get('core.edit.state')) {
  132. $options[] = array('text' => 'COM_PROJECTFORK_ACTION_PUBLISH', 'task' => $this->getName() . '.publish');
  133. $options[] = array('text' => 'COM_PROJECTFORK_ACTION_UNPUBLISH', 'task' => $this->getName() . '.unpublish');
  134. $options[] = array('text' => 'COM_PROJECTFORK_ACTION_ARCHIVE', 'task' => $this->getName() . '.archive');
  135. $options[] = array('text' => 'COM_PROJECTFORK_ACTION_CHECKIN', 'task' => $this->getName() . '.checkin');
  136. }
  137. if ($state->get('filter.published') == -2 && $access->get('core.delete')) {
  138. $options[] = array('text' => 'COM_PROJECTFORK_ACTION_DELETE', 'task' => $this->getName() . '.delete');
  139. }
  140. elseif ($access->get('core.edit.state')) {
  141. $options[] = array('text' => 'COM_PROJECTFORK_ACTION_TRASH', 'task' => $this->getName() . '.trash');
  142. }
  143. if (count($options)) {
  144. PFToolbar::listButton($options);
  145. }
  146. if ($this->params->get('show_filter', '1')) {
  147. PFToolbar::filterButton($this->state->get('filter.isset'));
  148. }
  149. return PFToolbar::render();
  150. }
  151. /**
  152. * Generates the table sort options
  153. *
  154. * @return array HTML list options
  155. */
  156. protected function getSortOptions()
  157. {
  158. $options = array();
  159. $options[] = JHtml::_('select.option', '', JText::_('COM_PROJECTFORK_ORDER_SELECT'));
  160. $options[] = JHtml::_('select.option', 'category_title, a.title', JText::_('COM_PROJECTFORK_ORDER_TITLE'));
  161. $options[] = JHtml::_('select.option', 'a.end_date', JText::_('COM_PROJECTFORK_ORDER_DEADLINE'));
  162. $options[] = JHtml::_('select.option', 'author_name', JText::_('COM_PROJECTFORK_ORDER_AUTHOR'));
  163. return $options;
  164. }
  165. /**
  166. * Generates the table order options
  167. *
  168. * @return array HTML list options
  169. */
  170. protected function getOrderOptions()
  171. {
  172. $options = array();
  173. $options[] = JHtml::_('select.option', '', JText::_('COM_PROJECTFORK_ORDER_SELECT_DIR'));
  174. $options[] = JHtml::_('select.option', 'ASC', JText::_('COM_PROJECTFORK_ORDER_ASC'));
  175. $options[] = JHtml::_('select.option', 'DESC', JText::_('COM_PROJECTFORK_ORDER_DESC'));
  176. return $options;
  177. }
  178. }