/administrator/components/com_modules/views/module/view.html.php

https://bitbucket.org/eternaware/joomus · PHP · 95 lines · 56 code · 13 blank · 26 comment · 16 complexity · e7711c1efa76ad458fdfc749f0bc79e7 MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Administrator
  4. * @subpackage com_modules
  5. *
  6. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. defined('_JEXEC') or die;
  10. /**
  11. * View to edit a module.
  12. *
  13. * @package Joomla.Administrator
  14. * @subpackage com_modules
  15. * @since 1.6
  16. */
  17. class ModulesViewModule extends JViewLegacy
  18. {
  19. protected $form;
  20. protected $item;
  21. protected $state;
  22. /**
  23. * Display the view
  24. */
  25. public function display($tpl = null)
  26. {
  27. $this->form = $this->get('Form');
  28. $this->item = $this->get('Item');
  29. $this->state = $this->get('State');
  30. // Check for errors.
  31. if (count($errors = $this->get('Errors'))) {
  32. JError::raiseError(500, implode("\n", $errors));
  33. return false;
  34. }
  35. $this->addToolbar();
  36. parent::display($tpl);
  37. }
  38. /**
  39. * Add the page title and toolbar.
  40. *
  41. * @since 1.6
  42. */
  43. protected function addToolbar()
  44. {
  45. JFactory::getApplication()->input->set('hidemainmenu', true);
  46. $user = JFactory::getUser();
  47. $isNew = ($this->item->id == 0);
  48. $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $user->get('id'));
  49. $canDo = ModulesHelper::getActions($this->state->get('filter.category_id'), $this->item->id);
  50. $item = $this->get('Item');
  51. JToolbarHelper::title(JText::sprintf('COM_MODULES_MANAGER_MODULE', JText::_($this->item->module)), 'module.png');
  52. // If not checked out, can save the item.
  53. if (!$checkedOut && ($canDo->get('core.edit') || $canDo->get('core.create') )) {
  54. JToolbarHelper::apply('module.apply');
  55. JToolbarHelper::save('module.save');
  56. }
  57. if (!$checkedOut && $canDo->get('core.create')) {
  58. JToolbarHelper::save2new('module.save2new');
  59. }
  60. // If an existing item, can save to a copy.
  61. if (!$isNew && $canDo->get('core.create')) {
  62. JToolbarHelper::save2copy('module.save2copy');
  63. }
  64. if (empty($this->item->id)) {
  65. JToolbarHelper::cancel('module.cancel');
  66. } else {
  67. JToolbarHelper::cancel('module.cancel', 'JTOOLBAR_CLOSE');
  68. }
  69. // Get the help information for the menu item.
  70. $lang = JFactory::getLanguage();
  71. $help = $this->get('Help');
  72. if ($lang->hasKey($help->url)) {
  73. $debug = $lang->setDebug(false);
  74. $url = JText::_($help->url);
  75. $lang->setDebug($debug);
  76. }
  77. else {
  78. $url = null;
  79. }
  80. JToolbarHelper::help($help->key, false, $url);
  81. }
  82. }