2024-01-27 07:09:33 +00:00
|
|
|
/**
|
|
|
|
* The Component code name.
|
|
|
|
*
|
|
|
|
* @var String
|
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
|
|
|
protected String $component;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Permission Class.
|
|
|
|
*
|
|
|
|
* @var Permission
|
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
|
|
|
protected Permission $permission;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @param Config $config The Config Class.
|
|
|
|
* @param Permission $permission The Permission Class.
|
|
|
|
*
|
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
|
|
|
public function __construct(Config $config, Permission $permission)
|
|
|
|
{
|
|
|
|
$this->component = $config->component_code_name;
|
|
|
|
$this->permission = $permission;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Can Delete Function Code
|
|
|
|
*
|
|
|
|
* @param string $nameSingleCode The single code name of the view.
|
|
|
|
*
|
|
|
|
* @since 3.2.0
|
|
|
|
* @return string The can delete method code
|
|
|
|
*/
|
|
|
|
public function get(string $nameSingleCode): string
|
|
|
|
{
|
|
|
|
$allow = [];
|
|
|
|
|
|
|
|
// setup the default script
|
2024-03-14 12:29:20 +00:00
|
|
|
$allow[] = PHP_EOL . Indent::_(2) . "if (empty(\$record->id) || (\$record->published != -2))";
|
2024-01-27 07:09:33 +00:00
|
|
|
$allow[] = Indent::_(2) . "{";
|
|
|
|
$allow[] = Indent::_(3) . "return false;";
|
|
|
|
$allow[] = Indent::_(2) . "}" . PHP_EOL;
|
|
|
|
|
|
|
|
// check if the item has permissions.
|
|
|
|
$allow[] = Indent::_(2) . "//" . Line::_(__Line__, __Class__)
|
|
|
|
. " The record has been set. Check the record permissions.";
|
|
|
|
$allow[] = Indent::_(2) . "return \$this->getCurrentUser()->authorise('"
|
|
|
|
. $this->permission->getAction($nameSingleCode, 'core.delete') . "', 'com_" . $this->component . "."
|
|
|
|
. $nameSingleCode . ".' . (int) \$record->id);";
|
|
|
|
|
|
|
|
return implode(PHP_EOL, $allow);
|
|
|
|
}
|