[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_categories/controllers/ -> category.php (source)

   1  <?php
   2  /**
   3   * @package     Joomla.Administrator
   4   * @subpackage  com_categories
   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  
  10  defined('_JEXEC') or die;
  11  
  12  jimport('joomla.application.component.controllerform');
  13  
  14  /**
  15   * The Category Controller
  16   *
  17   * @package     Joomla.Administrator
  18   * @subpackage  com_categories
  19   * @since       1.6
  20   */
  21  class CategoriesControllerCategory extends JControllerForm
  22  {
  23      /**
  24       * The extension for which the categories apply.
  25       *
  26       * @var    string
  27       * @since  1.6
  28       */
  29      protected $extension;
  30  
  31      /**
  32       * Constructor.
  33       *
  34       * @param  array  $config  An optional associative array of configuration settings.
  35       *
  36       * @since  1.6
  37       * @see    JController
  38       */
  39  	public function __construct($config = array())
  40      {
  41          parent::__construct($config);
  42  
  43          // Guess the JText message prefix. Defaults to the option.
  44          if (empty($this->extension))
  45          {
  46              $this->extension = JRequest::getCmd('extension', 'com_content');
  47          }
  48      }
  49  
  50      /**
  51       * Method to check if you can add a new record.
  52       *
  53       * @param   array  $data  An array of input data.
  54       *
  55       * @return  boolean
  56       *
  57       * @since   1.6
  58       */
  59  	protected function allowAdd($data = array())
  60      {
  61          $user = JFactory::getUser();
  62          return ($user->authorise('core.create', $this->extension) || count($user->getAuthorisedCategories($this->extension, 'core.create')));
  63      }
  64  
  65      /**
  66       * Method to check if you can edit a record.
  67       *
  68       * @param   array   $data  An array of input data.
  69       * @param   string  $key   The name of the key for the primary key.
  70       *
  71       * @return  boolean
  72       *
  73       * @since   1.6
  74       */
  75  	protected function allowEdit($data = array(), $key = 'parent_id')
  76      {
  77          // Initialise variables.
  78          $recordId = (int) isset($data[$key]) ? $data[$key] : 0;
  79          $user = JFactory::getUser();
  80          $userId = $user->get('id');
  81  
  82          // Check general edit permission first.
  83          if ($user->authorise('core.edit', $this->extension))
  84          {
  85              return true;
  86          }
  87  
  88          // Check specific edit permission.
  89          if ($user->authorise('core.edit', $this->extension . '.category.' . $recordId))
  90          {
  91              return true;
  92          }
  93  
  94          // Fallback on edit.own.
  95          // First test if the permission is available.
  96          if ($user->authorise('core.edit.own', $this->extension . '.category.' . $recordId) || $user->authorise('core.edit.own', $this->extension))
  97          {
  98              // Now test the owner is the user.
  99              $ownerId = (int) isset($data['created_user_id']) ? $data['created_user_id'] : 0;
 100              if (empty($ownerId) && $recordId)
 101              {
 102                  // Need to do a lookup from the model.
 103                  $record = $this->getModel()->getItem($recordId);
 104  
 105                  if (empty($record))
 106                  {
 107                      return false;
 108                  }
 109  
 110                  $ownerId = $record->created_user_id;
 111              }
 112  
 113              // If the owner matches 'me' then do the test.
 114              if ($ownerId == $userId)
 115              {
 116                  return true;
 117              }
 118          }
 119          return false;
 120      }
 121  
 122      /**
 123       * Method to run batch operations.
 124       *
 125       * @param   object  $model  The model.
 126       *
 127       * @return  boolean     True if successful, false otherwise and internal error is set.
 128       *
 129       * @since   1.6
 130       */
 131  	public function batch($model = null)
 132      {
 133          JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
 134  
 135          // Set the model
 136          $model = $this->getModel('Category');
 137  
 138          // Preset the redirect
 139          $this->setRedirect('index.php?option=com_categories&view=categories&extension=' . $this->extension);
 140  
 141          return parent::batch($model);
 142      }
 143  
 144      /**
 145       * Gets the URL arguments to append to an item redirect.
 146       *
 147       * @param   integer  $recordId  The primary key id for the item.
 148       * @param   string   $urlVar    The name of the URL variable for the id.
 149       *
 150       * @return  string  The arguments to append to the redirect URL.
 151       *
 152       * @since   1.6
 153       */
 154  	protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id')
 155      {
 156          $append = parent::getRedirectToItemAppend($recordId);
 157          $append .= '&extension=' . $this->extension;
 158  
 159          return $append;
 160      }
 161  
 162      /**
 163       * Gets the URL arguments to append to a list redirect.
 164       *
 165       * @return  string  The arguments to append to the redirect URL.
 166       *
 167       * @since   1.6
 168       */
 169  	protected function getRedirectToListAppend()
 170      {
 171          $append = parent::getRedirectToListAppend();
 172          $append .= '&extension=' . $this->extension;
 173  
 174          return $append;
 175      }
 176  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1