Files
pkg_circolari/site/src/Helper/CircolariHelper.php
2025-07-22 15:41:16 +02:00

72 lines
1.5 KiB
PHP

<?php
/**
* @version CVS: 1.0.0
* @package Com_Circolari
* @author Tommaso Cippitelli <tommaso.cippitelli@protocollicreativi.it>
* @copyright 2025 Tommaso Cippitelli
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Pcrt\Component\Circolari\Site\Helper;
defined('_JEXEC') or die;
use \Joomla\CMS\Factory;
use \Joomla\CMS\MVC\Model\BaseDatabaseModel;
/**
* Class CircolariFrontendHelper
*
* @since 1.0.0
*/
class CircolariHelper
{
/**
* Gets the files attached to an item
*
* @param int $pk The item's id
*
* @param string $table The table's name
*
* @param string $field The field's name
*
* @return array The files
*/
public static function getFiles($pk, $table, $field)
{
$db = Factory::getContainer()->get('DatabaseDriver');
$query = $db->getQuery(true);
$query
->select($field)
->from($table)
->where('id = ' . (int) $pk);
$db->setQuery($query);
return explode(',', $db->loadResult());
}
/**
* Gets the edit permission for an user
*
* @param mixed $item The item
*
* @return bool
*/
public static function canUserEdit($item)
{
$permission = false;
$user = Factory::getApplication()->getIdentity();
if ($user->authorise('core.edit', 'com_circolari') || (isset($item->created_by) && $user->authorise('core.edit.own', 'com_circolari') && $item->created_by == $user->id) || $user->authorise('core.create', 'com_circolari'))
{
$permission = true;
}
return $permission;
}
}