- md5
- f04c7406edbd62d31143e7b4b8ccd446
- sha1
- ebb27482febfdc34d3d1f9e0657568481313a9c3
- sha256
- 23603517486e8dfad30f5ae990b8672e0c7836582a3dd86174007665c3de854c
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
<?php
/**
* @package Joomla.Administrator
* @subpackage com_fields
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
use Joomla\Registry\Registry;
/**
* The Group controller
*
* @since 3.7.0
*/
class FieldsControllerGroup extends JControllerForm
{
/**
* The prefix to use with controller messages.
*
* @var string
* @since 3.7.0
*/
protected $text_prefix = 'COM_FIELDS_GROUP';
/**
* The component for which the group applies.
*
* @var string
* @since 3.7.0
*/
private $component = '';
/**
* Class constructor.
*
* @param array $config A named array of configuration variables.
*
* @since 3.7.0
*/
public function __construct($config = array())
{
parent::__construct($config);
$parts = FieldsHelper::extract($this->input->getCmd('context'));
if ($parts)
{
$this->component = $parts[0];
}
}
/**
* Method to run batch operations.
*
* @param object $model The model.
*
* @return boolean True if successful, false otherwise and internal error is set.
*
* @since 3.7.0
*/
public function batch($model = null)
{
$this->checkToken();
// Set the model
$model = $this->getModel('Group');
// Preset the redirect
$this->setRedirect('index.php?option=com_fields&view=groups');
return parent::batch($model);
}
/**
* Method override to check if you can add a new record.
*
* @param array $data An array of input data.
*
* @return boolean
*
* @since 3.7.0
*/
protected function allowAdd($data = array())
{
return JFactory::getUser()->authorise('core.create', $this->component);
}
/**
* Method override to check if you can edit an existing record.
*
* @param array $data An array of input data.
* @param string $key The name of the key for the primary key.
*
* @return boolean
*
* @since 3.7.0
*/
protected function allowEdit($data = array(), $key = 'parent_id')
{
$recordId = (int) isset($data[$key]) ? $data[$key] : 0;
$user = JFactory::getUser();
// Zero record (parent_id:0), return component edit permission by calling parent controller method
if (!$recordId)
{
return parent::allowEdit($data, $key);
}
// Check edit on the record asset (explicit or inherited)
if ($user->authorise('core.edit', $this->component . '.fieldgroup.' . $recordId))
{
return true;
}
// Check edit own on the record asset (explicit or inherited)
if ($user->authorise('core.edit.own', $this->component . '.fieldgroup.' . $recordId) || $user->authorise('core.edit.own', $this->component))
{
// Existing record already has an owner, get it
$record = $this->getModel()->getItem($recordId);
if (empty($record))
{
return false;
}
// Grant if current user is owner of the record
return $user->id == $record->created_by;
}
return false;
}
/**
* Function that allows child controller access to model data after the data has been saved.
*
* @param JModelLegacy $model The data model object.
* @param array $validData The validated data.
*
* @return void
*
* @since 3.7.0
*/
protected function postSaveHook(JModelLegacy $model, $validData = array())
{
$item = $model->getItem();
if (isset($item->params) && is_array($item->params))
{
$registry = new Registry;
$registry->loadArray($item->params);
$item->params = (string) $registry;
}
return;
}
}
The same content is in 26 releases, Joomla 3.9.2-rc to 3.9.14. See them all, or every version of this file.