Your IP : 216.73.216.240
<?php
/**
*----------------------------------------------------------------------------
* iCagenda Events Management Extension for Joomla!
*----------------------------------------------------------------------------
* @version 3.9.0 2024-02-25
*
* @package iCagenda.Site
* @subpackage src.Model
* @link https://www.icagenda.com
*
* @author Cyril Rezé
* @copyright (c) 2012-2024 Cyril Rezé / iCagenda. All rights reserved.
* @license GNU General Public License version 3 or later; see LICENSE.txt
*
* @since 3.8
*----------------------------------------------------------------------------
*/
namespace WebiC\Component\iCagenda\Site\Model;
\defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Object\CMSObject;
use Joomla\Registry\Registry;
use Joomla\Utilities\ArrayHelper;
/**
* iCagenda Component Registration Model
*/
class ManagerModel extends \WebiC\Component\iCagenda\Administrator\Model\EventModel
{
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @return void
*/
protected function populateState()
{
$app = Factory::getApplication();
// Load state from the request.
$pk = $app->input->getInt('event_id');
$this->setState('event.id', $pk);
$return = $app->input->get('return', '', 'base64');
$this->setState('return_page', base64_decode($return));
// Load the parameters. Merge Global and Menu Item params into new object
$params = $app->getParams();
if ($menu = $app->getMenu()->getActive()) {
$menuParams = $menu->getParams();
} else {
$menuParams = new Registry();
}
$mergedParams = clone $menuParams;
$mergedParams->merge($params);
$this->setState('params', $mergedParams);
}
/**
* Method to get item data.
*
* @param integer $itemId The id of the item.
*
* @return mixed item data object on success, false on failure.
*/
public function getItem($itemId = null)
{
$itemId = (int) (!empty($itemId)) ? $itemId : $this->getState('event.id');
// Get a row instance.
$table = $this->getTable();
// Attempt to load the row.
$return = $table->load($itemId);
// Check for a table object error.
if ($return === false && $table->getError())
{
$this->setError($table->getError());
return false;
}
$properties = $table->getProperties(1);
$value = ArrayHelper::toObject($properties, CMSObject::class);
// Convert attrib field to Registry.
$value->params = new Registry($value->params);
// Compute selected asset permissions.
$user = Factory::getUser();
$userId = $user->get('id');
$asset = 'com_icagenda.event.' . $value->id;
// $asset = 'com_icagenda';
// Check general edit permission first.
if ($user->authorise('core.edit', $asset))
{
$value->params->set('access-edit', true);
}
// Now check if edit.own is available.
elseif ( ! empty($userId) && $user->authorise('core.edit.own', $asset))
{
// Check for a valid user and that they are the owner.
if ($userId == $value->created_by)
{
$value->params->set('access-edit', true);
}
}
// Check edit state permission.
if ($itemId)
{
// Existing item
$value->params->set('access-change', $user->authorise('core.edit.state', $asset));
}
// else
// {
// New item.
// $value->params->set('access-change', $user->authorise('core.edit.state', 'com_icagenda'));
// }
return $value;
}
/**
* Get the return URL.
*
* @return string The return URL.
*/
public function getReturnPage()
{
return base64_encode($this->getState('return_page'));
}
/**
* Method to save the form data.
*
* @param array $data The form data.
*
* @return boolean True on success.
*/
public function save($data)
{
return parent::save($data);
}
/**
* Method to get the record form.
*
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
*
* @return Form|boolean A Form object on success, false on failure
*/
public function getForm($data = [], $loadData = true)
{
$form = parent::getForm($data, $loadData);
if (empty($form))
{
return false;
}
return $form;
}
/**
* Allows preprocessing of the JForm object.
*
* @param JForm $form The form object
* @param array $data The data to be merged into the form object
* @param string $group The plugin group to be executed
*
* @return void
*/
protected function preprocessForm(Form $form, $data, $group = 'content')
{
return parent::preprocessForm($form, $data, $group);
}
/**
* Method to get a table object, load it if necessary.
*
* @param string $name The table name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $options Configuration array for model. Optional.
*
* @return Table A Table object
*
* @throws \Exception
*/
public function getTable($name = 'Event', $prefix = 'Table', $options = array())
{
return parent::getTable($name, $prefix, $options);
}
/**
* Cleans the cache of com_icagenda and iCagenda modules
*
* @param string $group The cache group
* @param integer $clientId No longer used, will be removed without replacement
* @deprecated 4.3 will be removed in 6.0
*
* @return void
*
* @since 3.8.22
*/
protected function cleanCache($group = null, $clientId = 0)
{
parent::cleanCache('com_icagenda');
parent::cleanCache('mod_iccalendar');
parent::cleanCache('mod_ic_event_list');
}
}