/administrator/components/com_weblinks/views/weblink/view.html.php

https://bitbucket.org/eternaware/joomus · PHP · 87 lines · 49 code · 12 blank · 26 comment · 13 complexity · a6d16786d350f05297001940a54a1c9e MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Administrator
  4. * @subpackage com_weblinks
  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 weblink.
  12. *
  13. * @package Joomla.Administrator
  14. * @subpackage com_weblinks
  15. * @since 1.5
  16. */
  17. class WeblinksViewWeblink extends JViewLegacy
  18. {
  19. protected $state;
  20. protected $item;
  21. protected $form;
  22. /**
  23. * Display the view
  24. */
  25. public function display($tpl = null)
  26. {
  27. $this->state = $this->get('State');
  28. $this->item = $this->get('Item');
  29. $this->form = $this->get('Form');
  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. $userId = $user->get('id');
  48. $isNew = ($this->item->id == 0);
  49. $checkedOut = !($this->item->checked_out == 0 || $this->item->checked_out == $user->get('id'));
  50. // Since we don't track these assets at the item level, use the category id.
  51. $canDo = WeblinksHelper::getActions($this->item->catid, 0);
  52. JToolbarHelper::title(JText::_('COM_WEBLINKS_MANAGER_WEBLINK'), 'weblinks.png');
  53. // If not checked out, can save the item.
  54. if (!$checkedOut && ($canDo->get('core.edit')||(count($user->getAuthorisedCategories('com_weblinks', 'core.create')))))
  55. {
  56. JToolbarHelper::apply('weblink.apply');
  57. JToolbarHelper::save('weblink.save');
  58. }
  59. if (!$checkedOut && (count($user->getAuthorisedCategories('com_weblinks', 'core.create')))){
  60. JToolbarHelper::save2new('weblink.save2new');
  61. }
  62. // If an existing item, can save to a copy.
  63. if (!$isNew && (count($user->getAuthorisedCategories('com_weblinks', 'core.create')) > 0)) {
  64. JToolbarHelper::save2copy('weblink.save2copy');
  65. }
  66. if (empty($this->item->id)) {
  67. JToolbarHelper::cancel('weblink.cancel');
  68. }
  69. else {
  70. JToolbarHelper::cancel('weblink.cancel', 'JTOOLBAR_CLOSE');
  71. }
  72. JToolbarHelper::divider();
  73. JToolbarHelper::help('JHELP_COMPONENTS_WEBLINKS_LINKS_EDIT');
  74. }
  75. }