PageRenderTime 62ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/source/components/com_pfmilestones/site/views/milestones/view.html.php

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