PageRenderTime 24ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/source/components/com_pftasks/site/views/taskform/view.html.php

https://github.com/projectfork/Projectfork
PHP | 183 lines | 116 code | 38 blank | 29 comment | 16 complexity | 2c37ed9f378ee4a0284cc877ffd51b85 MD5 | raw file
  1. <?php
  2. /**
  3. * @package pkg_projectfork
  4. * @subpackage com_pftasks
  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. * Task Form View Class for Projectfork component
  14. *
  15. */
  16. class PFtasksViewTaskForm extends JViewLegacy
  17. {
  18. protected $form;
  19. protected $item;
  20. protected $return_page;
  21. protected $state;
  22. protected $pageclass_sfx;
  23. protected $toolbar;
  24. public function display($tpl = null)
  25. {
  26. // Initialise variables.
  27. $app = JFactory::getApplication();
  28. $user = JFactory::getUser();
  29. // Get model data.
  30. $this->state = $this->get('State');
  31. $this->item = $this->get('Item');
  32. $this->form = $this->get('Form');
  33. $this->return_page = $this->get('ReturnPage');
  34. $this->toolbar = $this->getToolbar();
  35. // Check for errors.
  36. if (count($errors = $this->get('Errors'))) {
  37. JError::raiseWarning(500, implode("\n", $errors));
  38. return false;
  39. }
  40. // Permission check.
  41. if ($this->item->id <= 0) {
  42. $access = PFtasksHelper::getActions();
  43. $authorised = $access->get('core.create');
  44. }
  45. else {
  46. $authorised = $this->item->params->get('access-edit');
  47. }
  48. if ($authorised !== true) {
  49. JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR'));
  50. return false;
  51. }
  52. //Escape strings for HTML output
  53. $this->pageclass_sfx = htmlspecialchars($this->state->params->get('pageclass_sfx'));
  54. $this->params = $this->state->params;
  55. $this->user = $user;
  56. // Prepare the document
  57. $this->_prepareDocument();
  58. // Display the view
  59. parent::display($tpl);
  60. }
  61. /**
  62. * Prepares the document
  63. *
  64. */
  65. protected function _prepareDocument()
  66. {
  67. $app = JFactory::getApplication();
  68. $menu = $app->getMenu()->getActive();
  69. $pathway = $app->getPathway();
  70. $title = null;
  71. $def_title = JText::_('COM_PROJECTFORK_PAGE_' . ($this->item->id > 0 ? 'EDIT' : 'ADD') . '_TASK');
  72. // Because the application sets a default page title, we need to get it from the menu item itself
  73. if ($menu) {
  74. if (strpos($menu->link, 'view=tasks') !== false) {
  75. $this->params->def('page_heading', $def_title);
  76. }
  77. else {
  78. $this->params->def('page_heading', $this->params->get('page_title', $menu->title));
  79. }
  80. }
  81. else {
  82. $this->params->def('page_heading', $def_title);
  83. }
  84. $title = $this->params->def('page_title', $def_title);
  85. if ($app->getCfg('sitename_pagetitles', 0) == 1) {
  86. $title = JText::sprintf('JPAGETITLE', $app->getCfg('sitename'), $title);
  87. }
  88. elseif ($app->getCfg('sitename_pagetitles', 0) == 2) {
  89. $title = JText::sprintf('JPAGETITLE', $title, $app->getCfg('sitename'));
  90. }
  91. $this->document->setTitle($title);
  92. $pathway = $app->getPathWay();
  93. $pathway->addItem($title, '');
  94. if ($this->params->get('menu-meta_description')) {
  95. $this->document->setDescription($this->params->get('menu-meta_description'));
  96. }
  97. if ($this->params->get('menu-meta_keywords')) {
  98. $this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
  99. }
  100. if ($this->params->get('robots')) {
  101. $this->document->setMetadata('robots', $this->params->get('robots'));
  102. }
  103. }
  104. /**
  105. * Generates the toolbar for the top of the view
  106. *
  107. * @return string Toolbar with buttons
  108. */
  109. protected function getToolbar()
  110. {
  111. $options = array();
  112. $user = JFactory::getUser();
  113. $create_list = true;
  114. $create_ms = $user->authorise('core.create', 'com_pfmilestones');
  115. $options[] = array(
  116. 'text' => 'JSAVE',
  117. 'task' => $this->getName() . '.save');
  118. $options[] = array(
  119. 'text' => 'COM_PROJECTFORK_ACTION_2NEW',
  120. 'task' => $this->getName() . '.save2new');
  121. $options[] = array(
  122. 'text' => 'COM_PROJECTFORK_ACTION_2COPY',
  123. 'task' => $this->getName() . '.save2copy',
  124. 'options' => array('access' => ($this->item->id > 0)));
  125. if ($create_list || $create_ms) {
  126. $options[] = array('text' => 'divider');
  127. }
  128. $options[] = array(
  129. 'text' => 'COM_PROJECTFORK_ACTION_2MILESTONE',
  130. 'task' => $this->getName() . '.save2milestone',
  131. 'options' => array('access' => $create_ms));
  132. $options[] = array(
  133. 'text' => 'COM_PROJECTFORK_ACTION_2TASKLIST',
  134. 'task' => $this->getName() . '.save2tasklist',
  135. 'options' => array('access' => $create_list));
  136. PFToolbar::dropdownButton($options, array('icon' => 'icon-white icon-ok'));
  137. PFToolbar::button(
  138. 'JCANCEL',
  139. $this->getName() . '.cancel',
  140. false,
  141. array('class' => '', 'icon' => '')
  142. );
  143. return PFToolbar::render();
  144. }
  145. }