acf
This commit is contained in:
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Highlights
|
||||
* @author Eddy Prosperi <eddy.prosperi@protocollicreativi.it>
|
||||
* @copyright 2024 Eddy Prosperi
|
||||
* @license GNU General Public License versione 2 o successiva; vedi LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Pcrt\Component\Highlights\Site\Controller;
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
|
||||
|
||||
/**
|
||||
* Display Component Controller
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class DisplayController extends \Joomla\CMS\MVC\Controller\BaseController
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $config An optional associative array of configuration settings.
|
||||
* Recognized key values include 'name', 'default_task', 'model_path', and
|
||||
* 'view_path' (this list is not meant to be comprehensive).
|
||||
* @param MVCFactoryInterface $factory The factory.
|
||||
* @param CMSApplication $app The JApplication for the dispatcher
|
||||
* @param Input $input Input
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct($config = array(), MVCFactoryInterface $factory = null, $app = null, $input = null)
|
||||
{
|
||||
parent::__construct($config, $factory, $app, $input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to display a view.
|
||||
*
|
||||
* @param boolean $cachable If true, the view output will be cached.
|
||||
* @param boolean $urlparams An array of safe URL parameters and their variable types, for valid values see {@link InputFilter::clean()}.
|
||||
*
|
||||
* @return \Joomla\CMS\MVC\Controller\BaseController This object to support chaining.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function display($cachable = false, $urlparams = false)
|
||||
{
|
||||
|
||||
$view = $this->input->getCmd('view', 'highlights');
|
||||
$view = $view == "featured" ? 'highlights' : $view;
|
||||
$this->input->set('view', $view);
|
||||
|
||||
|
||||
parent::display($cachable, $urlparams);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
220
components/com_highlights/src/Controller/HighlightController.php
Normal file
220
components/com_highlights/src/Controller/HighlightController.php
Normal file
@ -0,0 +1,220 @@
|
||||
<?php
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Highlights
|
||||
* @author Eddy Prosperi <eddy.prosperi@protocollicreativi.it>
|
||||
* @copyright 2024 Eddy Prosperi
|
||||
* @license GNU General Public License versione 2 o successiva; vedi LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Pcrt\Component\Highlights\Site\Controller;
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
use \Joomla\CMS\Application\SiteApplication;
|
||||
use \Joomla\CMS\Factory;
|
||||
use \Joomla\CMS\Language\Multilanguage;
|
||||
use \Joomla\CMS\Language\Text;
|
||||
use \Joomla\CMS\MVC\Controller\BaseController;
|
||||
use \Joomla\CMS\Router\Route;
|
||||
use \Joomla\CMS\Uri\Uri;
|
||||
use \Joomla\Utilities\ArrayHelper;
|
||||
|
||||
/**
|
||||
* Highlight class.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
class HighlightController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Method to check out an item for editing and redirect to the edit form.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
// Get the previous edit id (if any) and the current edit id.
|
||||
$previousId = (int) $this->app->getUserState('com_highlights.edit.highlight.id');
|
||||
$editId = $this->input->getInt('id', 0);
|
||||
|
||||
// Set the user id for the user to edit in the session.
|
||||
$this->app->setUserState('com_highlights.edit.highlight.id', $editId);
|
||||
|
||||
// Get the model.
|
||||
$model = $this->getModel('Highlight', 'Site');
|
||||
|
||||
// Check out the item
|
||||
if ($editId)
|
||||
{
|
||||
$model->checkout($editId);
|
||||
}
|
||||
|
||||
// Check in the previous user.
|
||||
if ($previousId && $previousId !== $editId)
|
||||
{
|
||||
$model->checkin($previousId);
|
||||
}
|
||||
|
||||
// Redirect to the edit screen.
|
||||
$this->setRedirect(Route::_('index.php?option=com_highlights&view=highlightform&layout=edit', false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to save data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws Exception
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function publish()
|
||||
{
|
||||
// Checking if the user can remove object
|
||||
$user = $this->app->getIdentity();
|
||||
|
||||
if ($user->authorise('core.edit', 'com_highlights') || $user->authorise('core.edit.state', 'com_highlights'))
|
||||
{
|
||||
$model = $this->getModel('Highlight', 'Site');
|
||||
|
||||
// Get the user data.
|
||||
$id = $this->input->getInt('id');
|
||||
$state = $this->input->getInt('state');
|
||||
|
||||
// Attempt to save the data.
|
||||
$return = $model->publish($id, $state);
|
||||
|
||||
// Check for errors.
|
||||
if ($return === false)
|
||||
{
|
||||
$this->setMessage(Text::sprintf('Save failed: %s', $model->getError()), 'warning');
|
||||
}
|
||||
|
||||
// Clear the profile id from the session.
|
||||
$this->app->setUserState('com_highlights.edit.highlight.id', null);
|
||||
|
||||
// Flush the data from the session.
|
||||
$this->app->setUserState('com_highlights.edit.highlight.data', null);
|
||||
|
||||
// Redirect to the list screen.
|
||||
$this->setMessage(Text::_('COM_HIGHLIGHTS_ITEM_SAVED_SUCCESSFULLY'));
|
||||
$menu = Factory::getApplication()->getMenu();
|
||||
$item = $menu->getActive();
|
||||
|
||||
if (!$item)
|
||||
{
|
||||
// If there isn't any menu item active, redirect to list view
|
||||
$this->setRedirect(Route::_('index.php?option=com_highlights&view=highlights', false));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->setRedirect(Route::_('index.php?Itemid='. $item->id, false));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \Exception(500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check in record
|
||||
*
|
||||
* @return boolean True on success
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function checkin()
|
||||
{
|
||||
// Check for request forgeries.
|
||||
$this->checkToken('GET');
|
||||
|
||||
$id = $this->input->getInt('id', 0);
|
||||
$model = $this->getModel();
|
||||
$item = $model->getItem($id);
|
||||
|
||||
// Checking if the user can remove object
|
||||
$user = $this->app->getIdentity();
|
||||
|
||||
if ($user->authorise('core.manage', 'com_highlights') || $item->checked_out == $user->id) {
|
||||
|
||||
$return = $model->checkin($id);
|
||||
|
||||
if ($return === false)
|
||||
{
|
||||
// Checkin failed.
|
||||
$message = Text::sprintf('JLIB_APPLICATION_ERROR_CHECKIN_FAILED', $model->getError());
|
||||
$this->setRedirect(Route::_('index.php?option=com_highlights&view=highlight' . '&id=' . $id, false), $message, 'error');
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Checkin succeeded.
|
||||
$message = Text::_('COM_HIGHLIGHTS_CHECKEDIN_SUCCESSFULLY');
|
||||
$this->setRedirect(Route::_('index.php?option=com_highlights&view=highlight' . '&id=' . $id, false), $message);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
// Checking if the user can remove object
|
||||
$user = $this->app->getIdentity();
|
||||
|
||||
if ($user->authorise('core.delete', 'com_highlights'))
|
||||
{
|
||||
$model = $this->getModel('Highlight', 'Site');
|
||||
|
||||
// Get the user data.
|
||||
$id = $this->input->getInt('id', 0);
|
||||
|
||||
// Attempt to save the data.
|
||||
$return = $model->delete($id);
|
||||
|
||||
// Check for errors.
|
||||
if ($return === false)
|
||||
{
|
||||
$this->setMessage(Text::sprintf('Delete failed', $model->getError()), 'warning');
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check in the profile.
|
||||
if ($return)
|
||||
{
|
||||
$model->checkin($return);
|
||||
}
|
||||
|
||||
$this->app->setUserState('com_highlights.edit.highlight.id', null);
|
||||
$this->app->setUserState('com_highlights.edit.highlight.data', null);
|
||||
|
||||
$this->app->enqueueMessage(Text::_('COM_HIGHLIGHTS_ITEM_DELETED_SUCCESSFULLY'), 'success');
|
||||
$this->app->redirect(Route::_('index.php?option=com_highlights&view=highlights', false));
|
||||
}
|
||||
|
||||
// Redirect to the list screen.
|
||||
$menu = Factory::getApplication()->getMenu();
|
||||
$item = $menu->getActive();
|
||||
$this->setRedirect(Route::_($item->link, false));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \Exception(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,273 @@
|
||||
<?php
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Highlights
|
||||
* @author Eddy Prosperi <eddy.prosperi@protocollicreativi.it>
|
||||
* @copyright 2024 Eddy Prosperi
|
||||
* @license GNU General Public License versione 2 o successiva; vedi LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Pcrt\Component\Highlights\Site\Controller;
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Application\SiteApplication;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Multilanguage;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Controller\FormController;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
use Joomla\Utilities\ArrayHelper;
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
|
||||
/**
|
||||
* Highlight class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class HighlightformController extends FormController
|
||||
{
|
||||
/**
|
||||
* Method to check out an item for editing and redirect to the edit form.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function edit($key = NULL, $urlVar = NULL)
|
||||
{
|
||||
// Get the previous edit id (if any) and the current edit id.
|
||||
$previousId = (int) $this->app->getUserState('com_highlights.edit.highlight.id');
|
||||
$editId = $this->input->getInt('id', 0);
|
||||
|
||||
// Set the user id for the user to edit in the session.
|
||||
$this->app->setUserState('com_highlights.edit.highlight.id', $editId);
|
||||
|
||||
// Get the model.
|
||||
$model = $this->getModel('Highlightform', 'Site');
|
||||
|
||||
// Check out the item
|
||||
if ($editId)
|
||||
{
|
||||
$model->checkout($editId);
|
||||
}
|
||||
|
||||
// Check in the previous user.
|
||||
if ($previousId)
|
||||
{
|
||||
$model->checkin($previousId);
|
||||
}
|
||||
|
||||
// Redirect to the edit screen.
|
||||
$this->setRedirect(Route::_('index.php?option=com_highlights&view=highlightform&layout=edit', false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to save data.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws Exception
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function save($key = NULL, $urlVar = NULL)
|
||||
{
|
||||
// Check for request forgeries.
|
||||
$this->checkToken();
|
||||
|
||||
// Initialise variables.
|
||||
$model = $this->getModel('Highlightform', 'Site');
|
||||
|
||||
// Get the user data.
|
||||
$data = $this->input->get('jform', array(), 'array');
|
||||
|
||||
// Validate the posted data.
|
||||
$form = $model->getForm();
|
||||
|
||||
if (!$form)
|
||||
{
|
||||
throw new \Exception($model->getError(), 500);
|
||||
}
|
||||
|
||||
// Send an object which can be modified through the plugin event
|
||||
$objData = (object) $data;
|
||||
$this->app->triggerEvent(
|
||||
'onContentNormaliseRequestData',
|
||||
array($this->option . '.' . $this->context, $objData, $form)
|
||||
);
|
||||
|
||||
$data = (array) $objData;
|
||||
|
||||
// Validate the posted data.
|
||||
$data = $model->validate($form, $data);
|
||||
|
||||
// Check for errors.
|
||||
if ($data === false)
|
||||
{
|
||||
// Get the validation messages.
|
||||
$errors = $model->getErrors();
|
||||
|
||||
// Push up to three validation messages out to the user.
|
||||
for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++)
|
||||
{
|
||||
if ($errors[$i] instanceof \Exception)
|
||||
{
|
||||
$this->app->enqueueMessage($errors[$i]->getMessage(), 'warning');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->app->enqueueMessage($errors[$i], 'warning');
|
||||
}
|
||||
}
|
||||
|
||||
$jform = $this->input->get('jform', array(), 'ARRAY');
|
||||
|
||||
// Save the data in the session.
|
||||
$this->app->setUserState('com_highlights.edit.highlight.data', $jform);
|
||||
|
||||
// Redirect back to the edit screen.
|
||||
$id = (int) $this->app->getUserState('com_highlights.edit.highlight.id');
|
||||
$this->setRedirect(Route::_('index.php?option=com_highlights&view=highlightform&layout=edit&id=' . $id, false));
|
||||
|
||||
$this->redirect();
|
||||
}
|
||||
|
||||
// Attempt to save the data.
|
||||
$return = $model->save($data);
|
||||
|
||||
// Check for errors.
|
||||
if ($return === false)
|
||||
{
|
||||
// Save the data in the session.
|
||||
$this->app->setUserState('com_highlights.edit.highlight.data', $data);
|
||||
|
||||
// Redirect back to the edit screen.
|
||||
$id = (int) $this->app->getUserState('com_highlights.edit.highlight.id');
|
||||
$this->setMessage(Text::sprintf('Save failed', $model->getError()), 'warning');
|
||||
$this->setRedirect(Route::_('index.php?option=com_highlights&view=highlightform&layout=edit&id=' . $id, false));
|
||||
$this->redirect();
|
||||
}
|
||||
|
||||
// Check in the profile.
|
||||
if ($return)
|
||||
{
|
||||
$model->checkin($return);
|
||||
}
|
||||
|
||||
// Clear the profile id from the session.
|
||||
$this->app->setUserState('com_highlights.edit.highlight.id', null);
|
||||
|
||||
// Redirect to the list screen.
|
||||
if (!empty($return))
|
||||
{
|
||||
$this->setMessage(Text::_('COM_HIGHLIGHTS_ITEM_SAVED_SUCCESSFULLY'));
|
||||
}
|
||||
|
||||
$menu = Factory::getApplication()->getMenu();
|
||||
$item = $menu->getActive();
|
||||
$url = (empty($item->link) ? 'index.php?option=com_highlights&view=highlights' : $item->link);
|
||||
$this->setRedirect(Route::_($url, false));
|
||||
|
||||
// Flush the data from the session.
|
||||
$this->app->setUserState('com_highlights.edit.highlight.data', null);
|
||||
|
||||
// Invoke the postSave method to allow for the child class to access the model.
|
||||
$this->postSaveHook($model, $data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to abort current operation
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function cancel($key = NULL)
|
||||
{
|
||||
|
||||
// Get the current edit id.
|
||||
$editId = (int) $this->app->getUserState('com_highlights.edit.highlight.id');
|
||||
|
||||
// Get the model.
|
||||
$model = $this->getModel('Highlightform', 'Site');
|
||||
|
||||
// Check in the item
|
||||
if ($editId)
|
||||
{
|
||||
$model->checkin($editId);
|
||||
}
|
||||
|
||||
$menu = Factory::getApplication()->getMenu();
|
||||
$item = $menu->getActive();
|
||||
$url = (empty($item->link) ? 'index.php?option=com_highlights&view=highlights' : $item->link);
|
||||
$this->setRedirect(Route::_($url, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to remove data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
$model = $this->getModel('Highlightform', 'Site');
|
||||
$pk = $this->input->getInt('id');
|
||||
|
||||
// Attempt to save the data
|
||||
try
|
||||
{
|
||||
// Check in before delete
|
||||
$return = $model->checkin($return);
|
||||
// Clear id from the session.
|
||||
$this->app->setUserState('com_highlights.edit.highlight.id', null);
|
||||
|
||||
$menu = $this->app->getMenu();
|
||||
$item = $menu->getActive();
|
||||
$url = (empty($item->link) ? 'index.php?option=com_highlights&view=highlights' : $item->link);
|
||||
|
||||
if($return)
|
||||
{
|
||||
$model->delete($pk);
|
||||
$this->setMessage(Text::_('COM_HIGHLIGHTS_ITEM_DELETED_SUCCESSFULLY'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->setMessage(Text::_('COM_HIGHLIGHTS_ITEM_DELETED_UNSUCCESSFULLY'), 'warning');
|
||||
}
|
||||
|
||||
|
||||
$this->setRedirect(Route::_($url, false));
|
||||
// Flush the data from the session.
|
||||
$this->app->setUserState('com_highlights.edit.highlight.data', null);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$errorType = ($e->getCode() == '404') ? 'error' : 'warning';
|
||||
$this->setMessage($e->getMessage(), $errorType);
|
||||
$this->setRedirect('index.php?option=com_highlights&view=highlights');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function that allows child controller access to model data
|
||||
* after the data has been saved.
|
||||
*
|
||||
* @param BaseDatabaseModel $model The data model object.
|
||||
* @param array $validData The validated data.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function postSaveHook(BaseDatabaseModel $model, $validData = array())
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Highlights
|
||||
* @author Eddy Prosperi <eddy.prosperi@protocollicreativi.it>
|
||||
* @copyright 2024 Eddy Prosperi
|
||||
* @license GNU General Public License versione 2 o successiva; vedi LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Pcrt\Component\Highlights\Site\Controller;
|
||||
|
||||
\defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Application\SiteApplication;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Multilanguage;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Controller\FormController;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
use Joomla\Utilities\ArrayHelper;
|
||||
|
||||
/**
|
||||
* Highlights class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class HighlightsController extends FormController
|
||||
{
|
||||
/**
|
||||
* Proxy for getModel.
|
||||
*
|
||||
* @param string $name The model name. Optional.
|
||||
* @param string $prefix The class prefix. Optional
|
||||
* @param array $config Configuration array for model. Optional
|
||||
*
|
||||
* @return object The model
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getModel($name = 'Highlights', $prefix = 'Site', $config = array())
|
||||
{
|
||||
return parent::getModel($name, $prefix, array('ignore_request' => true));
|
||||
}
|
||||
}
|
||||
35
components/com_highlights/src/Dispatcher/Dispatcher.php
Normal file
35
components/com_highlights/src/Dispatcher/Dispatcher.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Highlights
|
||||
* @author Eddy Prosperi <eddy.prosperi@protocollicreativi.it>
|
||||
* @copyright 2024 Eddy Prosperi
|
||||
* @license GNU General Public License versione 2 o successiva; vedi LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Pcrt\Component\Highlights\Site\Dispatcher;
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
use Joomla\CMS\Dispatcher\ComponentDispatcher;
|
||||
use Joomla\CMS\Language\Text;
|
||||
|
||||
/**
|
||||
* ComponentDispatcher class for Com_Highlights
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Dispatcher extends ComponentDispatcher
|
||||
{
|
||||
/**
|
||||
* Dispatch a controller task. Redirecting the user if appropriate.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function dispatch()
|
||||
{
|
||||
parent::dispatch();
|
||||
}
|
||||
}
|
||||
67
components/com_highlights/src/Field/CreatedbyField.php
Normal file
67
components/com_highlights/src/Field/CreatedbyField.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Highlights
|
||||
* @author Eddy Prosperi <eddy.prosperi@protocollicreativi.it>
|
||||
* @copyright 2024 Eddy Prosperi
|
||||
* @license GNU General Public License versione 2 o successiva; vedi LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Pcrt\Component\Highlights\Site\Field;
|
||||
|
||||
defined('JPATH_BASE') or die;
|
||||
|
||||
use \Joomla\CMS\Factory;
|
||||
use \Joomla\CMS\Form\FormField;
|
||||
use \Joomla\CMS\User\UserFactoryInterface;
|
||||
|
||||
/**
|
||||
* Supports an HTML select list of categories
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class CreatedbyField extends FormField
|
||||
{
|
||||
/**
|
||||
* The form field type.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $type = 'createdby';
|
||||
|
||||
/**
|
||||
* Method to get the field input markup.
|
||||
*
|
||||
* @return string The field input markup.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function getInput()
|
||||
{
|
||||
// Initialize variables.
|
||||
$html = array();
|
||||
|
||||
// Load user
|
||||
$user_id = $this->value;
|
||||
|
||||
if ($user_id)
|
||||
{
|
||||
$container = \Joomla\CMS\Factory::getContainer();
|
||||
$userFactory = $container->get(UserFactoryInterface::class);
|
||||
$user = $userFactory->loadUserById($user_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
$user = Factory::getApplication()->getIdentity();
|
||||
$html[] = '<input type="hidden" name="' . $this->name . '" value="' . $user->id . '" />';
|
||||
}
|
||||
|
||||
if (!$this->hidden)
|
||||
{
|
||||
$html[] = "<div>" . $user->name . " (" . $user->username . ")</div>";
|
||||
}
|
||||
|
||||
return implode($html);
|
||||
}
|
||||
}
|
||||
296
components/com_highlights/src/Field/ForeignkeyField.php
Normal file
296
components/com_highlights/src/Field/ForeignkeyField.php
Normal file
@ -0,0 +1,296 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Highlights
|
||||
* @author Eddy Prosperi <eddy.prosperi@protocollicreativi.it>
|
||||
* @copyright 2024 Eddy Prosperi
|
||||
* @license GNU General Public License versione 2 o successiva; vedi LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Pcrt\Component\Highlights\Site\Field;
|
||||
|
||||
defined('JPATH_BASE') or die;
|
||||
|
||||
use \Joomla\CMS\Factory;
|
||||
use \Joomla\CMS\HTML\HTMLHelper;
|
||||
use \Joomla\CMS\Language\Text;
|
||||
use \Joomla\CMS\Form\Field\ListField;
|
||||
|
||||
/**
|
||||
* Supports a value from an external table
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class ForeignKeyField extends ListField
|
||||
{
|
||||
/**
|
||||
* The form field type.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $type = 'foreignkey';
|
||||
|
||||
protected $layout = 'joomla.form.field.list-fancy-select';
|
||||
|
||||
/**
|
||||
* The translate.
|
||||
*
|
||||
* @var boolean
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $translate = true;
|
||||
|
||||
protected $header = false;
|
||||
|
||||
private $input_type;
|
||||
|
||||
private $table;
|
||||
|
||||
private $key_field;
|
||||
|
||||
private $value_field;
|
||||
|
||||
private $option_key_field;
|
||||
|
||||
private $option_value_field;
|
||||
|
||||
private $condition;
|
||||
|
||||
/**
|
||||
* Method to get the field input markup.
|
||||
*
|
||||
* @return string The field input markup.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function processQuery()
|
||||
{
|
||||
// Type of input the field shows
|
||||
$this->input_type = $this->getAttribute('input_type');
|
||||
|
||||
// Database Table
|
||||
$this->table = $this->getAttribute('table');
|
||||
|
||||
// The field that the field will save on the database
|
||||
$this->key_field = (string) $this->getAttribute('key_field');
|
||||
|
||||
// The column that the field shows in the input
|
||||
$this->value_field = (string) $this->getAttribute('value_field');
|
||||
|
||||
// The option field that the field will save on the database
|
||||
$this->option_key_field = (string) $this->getAttribute('option_key_field');
|
||||
|
||||
// The option value that the field shows in the input
|
||||
$this->option_value_field = (string) $this->getAttribute('option_value_field');
|
||||
|
||||
// Flag to identify if the fk_value is multiple
|
||||
$this->value_multiple = (int) $this->getAttribute('value_multiple', 0);
|
||||
|
||||
$this->required = (string) $this->getAttribute('required', 0);
|
||||
|
||||
// Flag to identify if the fk_value hides the trashed items
|
||||
$this->hideTrashed = (int) $this->getAttribute('hide_trashed', 0);
|
||||
|
||||
// Flag to identify if the fk_value hides the unpublished items
|
||||
$this->hideUnpublished = (int) $this->getAttribute('hide_unpublished', 0);
|
||||
|
||||
// Flag to identify if the fk_value hides the published items
|
||||
$this->hidePublished = (int) $this->getAttribute('hide_published', 0);
|
||||
|
||||
// Flag to identify if the fk_value hides the archived items
|
||||
$this->hideArchived = (int) $this->getAttribute('hide_archived', 0);
|
||||
|
||||
// Flag to identify if the fk has default order
|
||||
$this->fk_ordering = (string) $this->getAttribute('fk_ordering');
|
||||
|
||||
// The where SQL for foreignkey
|
||||
$this->condition = (string) $this->getAttribute('condition');
|
||||
|
||||
// Flag for translate options
|
||||
$this->translate = (bool) $this->getAttribute('translate');
|
||||
|
||||
// Initialize variables.
|
||||
$html = '';
|
||||
$fk_value = '';
|
||||
|
||||
// Load all the field options
|
||||
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// Support for multiple fields on fk_values
|
||||
if ($this->value_multiple == 1)
|
||||
{
|
||||
// Get the fields for multiple value
|
||||
$this->value_fields = (string) $this->getAttribute('value_field_multiple');
|
||||
$this->value_fields = explode(',', $this->value_fields);
|
||||
$this->separator = (string) $this->getAttribute('separator');
|
||||
|
||||
$fk_value = ' CONCAT(';
|
||||
|
||||
foreach ($this->value_fields as $field)
|
||||
{
|
||||
$fk_value .= $db->quoteName($field) . ', \'' . $this->separator . '\', ';
|
||||
}
|
||||
|
||||
$fk_value = substr($fk_value, 0, -(strlen($this->separator) + 6));
|
||||
$fk_value .= ') AS ' . $db->quoteName($this->value_field);
|
||||
}
|
||||
else
|
||||
{
|
||||
$fk_value = $db->quoteName($this->value_field);
|
||||
}
|
||||
|
||||
$query
|
||||
->select(
|
||||
array(
|
||||
$db->quoteName($this->key_field),
|
||||
$fk_value
|
||||
)
|
||||
)
|
||||
->from($this->table);
|
||||
|
||||
if ($this->hideTrashed)
|
||||
{
|
||||
$query->where($db->quoteName('state') . ' != -2');
|
||||
}
|
||||
|
||||
if ($this->hideUnpublished)
|
||||
{
|
||||
$query->where($db->quoteName('state') . ' != 0');
|
||||
}
|
||||
|
||||
if ($this->hidePublished)
|
||||
{
|
||||
$query->where($db->quoteName('state') . ' != 1');
|
||||
}
|
||||
|
||||
if ($this->hideArchived)
|
||||
{
|
||||
$query->where($db->quoteName('state') . ' != 2');
|
||||
}
|
||||
|
||||
if ($this->fk_ordering)
|
||||
{
|
||||
$query->order($this->fk_ordering);
|
||||
}
|
||||
|
||||
if($this->condition)
|
||||
{
|
||||
$query->where($this->condition);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the field input for a foreignkey field.
|
||||
*
|
||||
* @return string The field input.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function getInput()
|
||||
{
|
||||
$data = $this->getLayoutData();
|
||||
|
||||
if (!\is_array($this->value) && !empty($this->value))
|
||||
{
|
||||
if (\is_object($this->value))
|
||||
{
|
||||
$this->value = get_object_vars($this->value);
|
||||
}
|
||||
|
||||
// String in format 2,5,4
|
||||
if (\is_string($this->value))
|
||||
{
|
||||
$this->value = explode(',', $this->value);
|
||||
}
|
||||
|
||||
// Integer is given
|
||||
if (\is_int($this->value))
|
||||
{
|
||||
$this->value = array($this->value);
|
||||
}
|
||||
|
||||
$data['value'] = $this->value;
|
||||
}
|
||||
|
||||
$data['options'] = $this->getOptions();
|
||||
|
||||
return $this->getRenderer($this->layout)->render($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the field options.
|
||||
*
|
||||
* @return array The field option objects.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
$options = array();
|
||||
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||
try
|
||||
{
|
||||
$db->setQuery($this->processQuery());
|
||||
$results = $db->loadObjectList();
|
||||
}
|
||||
catch (ExecutionFailureException $e)
|
||||
{
|
||||
Factory::getApplication()->enqueueMessage(Text::_('JERROR_AN_ERROR_HAS_OCCURRED'), 'error');
|
||||
}
|
||||
|
||||
// Add header.
|
||||
if (!empty($this->header))
|
||||
{
|
||||
$options[] = (object) ["value" => '', "text" => Text::_($this->header)];
|
||||
}
|
||||
|
||||
if(!empty($this->option_value_field) || !empty($this->option_key_field))
|
||||
{
|
||||
$options[] = (object) ["value" => $this->option_key_field, "text" => Text::_($this->option_value_field)];
|
||||
}
|
||||
|
||||
// Build the field options.
|
||||
if (!empty($results))
|
||||
{
|
||||
foreach ($results as $item)
|
||||
{
|
||||
$options[] = (object) [
|
||||
"value" => $item->{$this->key_field},
|
||||
"text" => $this->translate == true ? Text::_($item->{$this->value_field}) : $item->{$this->value_field}
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Merge any additional options in the XML definition.
|
||||
$options = array_merge(parent::getOptions(), $options);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper method for getting attributes from the form element
|
||||
*
|
||||
* @param string $attr_name Attribute name
|
||||
* @param mixed $default Optional value to return if attribute not found
|
||||
*
|
||||
* @return mixed The value of the attribute if it exists, null otherwise
|
||||
*/
|
||||
public function getAttribute($attr_name, $default = null)
|
||||
{
|
||||
if (!empty($this->element[$attr_name]))
|
||||
{
|
||||
return $this->element[$attr_name];
|
||||
}
|
||||
else
|
||||
{
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
}
|
||||
53
components/com_highlights/src/Field/ModifiedbyField.php
Normal file
53
components/com_highlights/src/Field/ModifiedbyField.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Highlights
|
||||
* @author Eddy Prosperi <eddy.prosperi@protocollicreativi.it>
|
||||
* @copyright 2024 Eddy Prosperi
|
||||
* @license GNU General Public License versione 2 o successiva; vedi LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Pcrt\Component\Highlights\Site\Field;
|
||||
|
||||
defined('JPATH_BASE') or die;
|
||||
|
||||
use \Joomla\CMS\Factory;
|
||||
use \Joomla\CMS\Form\FormField;
|
||||
|
||||
/**
|
||||
* Supports an HTML select list of categories
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class ModifiedbyField extends FormField
|
||||
{
|
||||
/**
|
||||
* The form field type.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $type = 'modifiedby';
|
||||
|
||||
/**
|
||||
* Method to get the field input markup.
|
||||
*
|
||||
* @return string The field input markup.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function getInput()
|
||||
{
|
||||
// Initialize variables.
|
||||
$html = array();
|
||||
$user = Factory::getApplication()->getIdentity();
|
||||
$html[] = '<input type="hidden" name="' . $this->name . '" value="' . $user->id . '" />';
|
||||
|
||||
if (!$this->hidden)
|
||||
{
|
||||
$html[] = "<div>" . $user->name . " (" . $user->username . ")</div>";
|
||||
}
|
||||
|
||||
return implode($html);
|
||||
}
|
||||
}
|
||||
83
components/com_highlights/src/Field/NestedparentField.php
Normal file
83
components/com_highlights/src/Field/NestedparentField.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Highlights
|
||||
* @author Eddy Prosperi <eddy.prosperi@protocollicreativi.it>
|
||||
* @copyright 2024 Eddy Prosperi
|
||||
* @license GNU General Public License versione 2 o successiva; vedi LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Pcrt\Component\Highlights\Site\Field;
|
||||
|
||||
defined('JPATH_BASE') or die;
|
||||
|
||||
use Joomla\CMS\Helper\UserGroupsHelper;
|
||||
use \Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Form\Field\ListField;
|
||||
|
||||
/**
|
||||
* Supports an HTML select list of categories
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class NestedparentField extends ListField
|
||||
{
|
||||
/**
|
||||
* The form field type.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $type = 'nestedparent';
|
||||
|
||||
/**
|
||||
* Method to get the field options.
|
||||
*
|
||||
* @return array The field option objects.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
$options = array();
|
||||
$table = $this->getAttribute('table');
|
||||
|
||||
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||
$query = $db->getQuery(true)
|
||||
->select('DISTINCT(a.id) AS value, a.title AS text, a.level, a.lft')
|
||||
->from($table . ' AS a');
|
||||
|
||||
|
||||
// Prevent parenting to children of this item.
|
||||
if ($id = $this->form->getValue('id'))
|
||||
{
|
||||
$query->join('LEFT', $db->quoteName($table) . ' AS p ON p.id = ' . (int) $id)
|
||||
->where('NOT(a.lft >= p.lft AND a.rgt <= p.rgt)');
|
||||
}
|
||||
|
||||
$query->order('a.lft ASC');
|
||||
|
||||
// Get the options.
|
||||
$db->setQuery($query);
|
||||
|
||||
try
|
||||
{
|
||||
$options = $db->loadObjectList();
|
||||
}
|
||||
catch (\RuntimeException $e)
|
||||
{
|
||||
\JError::raiseWarning(500, $e->getMessage());
|
||||
}
|
||||
|
||||
// Pad the option text with spaces using depth level as a multiplier.
|
||||
for ($i = 0, $n = count($options); $i < $n; $i++)
|
||||
{
|
||||
$options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->text;
|
||||
}
|
||||
|
||||
// Merge any additional options in the XML definition.
|
||||
$options = array_merge(parent::getOptions(), $options);
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
49
components/com_highlights/src/Field/SubmitField.php
Normal file
49
components/com_highlights/src/Field/SubmitField.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Highlights
|
||||
* @author Eddy Prosperi <eddy.prosperi@protocollicreativi.it>
|
||||
* @copyright 2024 Eddy Prosperi
|
||||
* @license GNU General Public License versione 2 o successiva; vedi LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Pcrt\Component\Highlights\Site\Field;
|
||||
|
||||
// Check to ensure this file is included in Joomla!
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
use \Joomla\CMS\Language\Text;
|
||||
use \Joomla\CMS\Form\FormField;
|
||||
|
||||
/**
|
||||
* Class SubmitField
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class SubmitField extends FormField
|
||||
{
|
||||
protected $type = 'submit';
|
||||
|
||||
protected $value;
|
||||
|
||||
protected $for;
|
||||
|
||||
/**
|
||||
* Get a form field markup for the input
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getInput()
|
||||
{
|
||||
$this->value = $this->getAttribute('value');
|
||||
|
||||
return '<button id="' . $this->id . '"'
|
||||
. ' name="submit_' . $this->for . '"'
|
||||
. ' value="' . $this->value . '"'
|
||||
. ' title="' . Text::_('JSEARCH_FILTER_SUBMIT') . '"'
|
||||
. ' class="btn" style="margin-top: -10px;">'
|
||||
. Text::_('JSEARCH_FILTER_SUBMIT')
|
||||
. ' </button>';
|
||||
}
|
||||
}
|
||||
65
components/com_highlights/src/Field/TimecreatedField.php
Normal file
65
components/com_highlights/src/Field/TimecreatedField.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Highlights
|
||||
* @author Eddy Prosperi <eddy.prosperi@protocollicreativi.it>
|
||||
* @copyright 2024 Eddy Prosperi
|
||||
* @license GNU General Public License versione 2 o successiva; vedi LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Pcrt\Component\Highlights\Site\Field;
|
||||
|
||||
defined('JPATH_BASE') or die;
|
||||
|
||||
use \Joomla\CMS\Factory;
|
||||
use \Joomla\CMS\Language\Text;
|
||||
use \Joomla\CMS\Form\FormField;
|
||||
use \Joomla\CMS\Date\Date;
|
||||
|
||||
/**
|
||||
* Supports an HTML select list of categories
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class TimecreatedField extends FormField
|
||||
{
|
||||
/**
|
||||
* The form field type.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $type = 'timecreated';
|
||||
|
||||
/**
|
||||
* Method to get the field input markup.
|
||||
*
|
||||
* @return string The field input markup.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function getInput()
|
||||
{
|
||||
// Initialize variables.
|
||||
$html = array();
|
||||
|
||||
$time_created = $this->value;
|
||||
|
||||
if (!strtotime($time_created))
|
||||
{
|
||||
$time_created = Factory::getDate()->toSql();
|
||||
$html[] = '<input type="hidden" name="' . $this->name . '" value="' . $time_created . '" />';
|
||||
}
|
||||
|
||||
$hidden = (boolean) $this->element['hidden'];
|
||||
|
||||
if ($hidden == null || !$hidden)
|
||||
{
|
||||
$jdate = new Date($time_created);
|
||||
$pretty_date = $jdate->format(Text::_('DATE_FORMAT_LC2'));
|
||||
$html[] = "<div>" . $pretty_date . "</div>";
|
||||
}
|
||||
|
||||
return implode($html);
|
||||
}
|
||||
}
|
||||
68
components/com_highlights/src/Field/TimeupdatedField.php
Normal file
68
components/com_highlights/src/Field/TimeupdatedField.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Highlights
|
||||
* @author Eddy Prosperi <eddy.prosperi@protocollicreativi.it>
|
||||
* @copyright 2024 Eddy Prosperi
|
||||
* @license GNU General Public License versione 2 o successiva; vedi LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Pcrt\Component\Highlights\Site\Field;
|
||||
|
||||
defined('JPATH_BASE') or die;
|
||||
|
||||
use \Joomla\CMS\Factory;
|
||||
use \Joomla\CMS\Language\Text;
|
||||
use \Joomla\CMS\Form\FormField;
|
||||
use \Joomla\CMS\Date\Date;
|
||||
|
||||
/**
|
||||
* Supports an HTML select list of categories
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class TimeupdatedField extends FormField
|
||||
{
|
||||
/**
|
||||
* The form field type.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected $type = 'timeupdated';
|
||||
|
||||
/**
|
||||
* Method to get the field input markup.
|
||||
*
|
||||
* @return string The field input markup.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function getInput()
|
||||
{
|
||||
// Initialize variables.
|
||||
$html = array();
|
||||
|
||||
$old_time_updated = $this->value;
|
||||
$hidden = (boolean) $this->element['hidden'];
|
||||
|
||||
if ($hidden == null || !$hidden)
|
||||
{
|
||||
if (!strtotime($old_time_updated))
|
||||
{
|
||||
$html[] = '-';
|
||||
}
|
||||
else
|
||||
{
|
||||
$jdate = new Date($old_time_updated);
|
||||
$pretty_date = $jdate->format(Text::_('DATE_FORMAT_LC2'));
|
||||
$html[] = "<div>" . $pretty_date . "</div>";
|
||||
}
|
||||
}
|
||||
|
||||
$time_updated = Factory::getDate()->toSql();
|
||||
$html[] = '<input type="hidden" name="' . $this->name . '" value="' . $time_updated . '" />';
|
||||
|
||||
return implode($html);
|
||||
}
|
||||
}
|
||||
1
components/com_highlights/src/Field/index.html
Normal file
1
components/com_highlights/src/Field/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body></body></html>
|
||||
71
components/com_highlights/src/Helper/HighlightsHelper.php
Normal file
71
components/com_highlights/src/Helper/HighlightsHelper.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Highlights
|
||||
* @author Eddy Prosperi <eddy.prosperi@protocollicreativi.it>
|
||||
* @copyright 2024 Eddy Prosperi
|
||||
* @license GNU General Public License versione 2 o successiva; vedi LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Pcrt\Component\Highlights\Site\Helper;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use \Joomla\CMS\Factory;
|
||||
use \Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
|
||||
/**
|
||||
* Class HighlightsFrontendHelper
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class HighlightsHelper
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 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_highlights') || (isset($item->created_by) && $user->authorise('core.edit.own', 'com_highlights') && $item->created_by == $user->id) || $user->authorise('core.create', 'com_highlights'))
|
||||
{
|
||||
$permission = true;
|
||||
}
|
||||
|
||||
return $permission;
|
||||
}
|
||||
}
|
||||
1
components/com_highlights/src/Helper/index.html
Normal file
1
components/com_highlights/src/Helper/index.html
Normal file
@ -0,0 +1 @@
|
||||
<html><body></body></html>
|
||||
351
components/com_highlights/src/Model/HighlightModel.php
Normal file
351
components/com_highlights/src/Model/HighlightModel.php
Normal file
@ -0,0 +1,351 @@
|
||||
<?php
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Highlights
|
||||
* @author Eddy Prosperi <eddy.prosperi@protocollicreativi.it>
|
||||
* @copyright 2024 Eddy Prosperi
|
||||
* @license GNU General Public License versione 2 o successiva; vedi LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Pcrt\Component\Highlights\Site\Model;
|
||||
// No direct access.
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use \Joomla\CMS\Factory;
|
||||
use \Joomla\Utilities\ArrayHelper;
|
||||
use \Joomla\CMS\Language\Text;
|
||||
use \Joomla\CMS\Table\Table;
|
||||
use \Joomla\CMS\MVC\Model\ItemModel;
|
||||
use \Joomla\CMS\Helper\TagsHelper;
|
||||
use \Joomla\CMS\Object\CMSObject;
|
||||
use \Joomla\CMS\User\UserFactoryInterface;
|
||||
use \Pcrt\Component\Highlights\Site\Helper\HighlightsHelper;
|
||||
|
||||
/**
|
||||
* Highlights model.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class HighlightModel extends ItemModel
|
||||
{
|
||||
public $_item;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function populateState()
|
||||
{
|
||||
$app = Factory::getApplication('com_highlights');
|
||||
$user = $app->getIdentity();
|
||||
|
||||
// Check published state
|
||||
if ((!$user->authorise('core.edit.state', 'com_highlights')) && (!$user->authorise('core.edit', 'com_highlights')))
|
||||
{
|
||||
$this->setState('filter.published', 1);
|
||||
$this->setState('filter.archived', 2);
|
||||
}
|
||||
|
||||
// Load state from the request userState on edit or from the passed variable on default
|
||||
if (Factory::getApplication()->input->get('layout') == 'edit')
|
||||
{
|
||||
$id = Factory::getApplication()->getUserState('com_highlights.edit.highlight.id');
|
||||
}
|
||||
else
|
||||
{
|
||||
$id = Factory::getApplication()->input->get('id');
|
||||
Factory::getApplication()->setUserState('com_highlights.edit.highlight.id', $id);
|
||||
}
|
||||
|
||||
$this->setState('highlight.id', $id);
|
||||
|
||||
// Load the parameters.
|
||||
$params = $app->getParams();
|
||||
$params_array = $params->toArray();
|
||||
|
||||
if (isset($params_array['item_id']))
|
||||
{
|
||||
$this->setState('highlight.id', $params_array['item_id']);
|
||||
}
|
||||
|
||||
$this->setState('params', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get an object.
|
||||
*
|
||||
* @param integer $id The id of the object to get.
|
||||
*
|
||||
* @return mixed Object on success, false on failure.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getItem($id = null)
|
||||
{
|
||||
if ($this->_item === null)
|
||||
{
|
||||
$this->_item = false;
|
||||
|
||||
if (empty($id))
|
||||
{
|
||||
$id = $this->getState('highlight.id');
|
||||
}
|
||||
|
||||
// Get a level row instance.
|
||||
$table = $this->getTable();
|
||||
|
||||
// Attempt to load the row.
|
||||
if ($table && $table->load($id))
|
||||
{
|
||||
|
||||
|
||||
// Check published state.
|
||||
if ($published = $this->getState('filter.published'))
|
||||
{
|
||||
if (isset($table->state) && $table->state != $published)
|
||||
{
|
||||
throw new \Exception(Text::_('COM_HIGHLIGHTS_ITEM_NOT_LOADED'), 403);
|
||||
}
|
||||
}
|
||||
|
||||
// Convert the Table to a clean CMSObject.
|
||||
$properties = $table->getProperties(1);
|
||||
$this->_item = ArrayHelper::toObject($properties, CMSObject::class);
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (empty($this->_item))
|
||||
{
|
||||
throw new \Exception(Text::_('COM_HIGHLIGHTS_ITEM_NOT_LOADED'), 404);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$container = \Joomla\CMS\Factory::getContainer();
|
||||
|
||||
$userFactory = $container->get(UserFactoryInterface::class);
|
||||
|
||||
if (isset($this->_item->created_by))
|
||||
{
|
||||
$user = $userFactory->loadUserById($this->_item->created_by);
|
||||
$this->_item->created_by_name = $user->name;
|
||||
}
|
||||
|
||||
$container = \Joomla\CMS\Factory::getContainer();
|
||||
|
||||
$userFactory = $container->get(UserFactoryInterface::class);
|
||||
|
||||
if (isset($this->_item->modified_by))
|
||||
{
|
||||
$user = $userFactory->loadUserById($this->_item->modified_by);
|
||||
$this->_item->modified_by_name = $user->name;
|
||||
}
|
||||
|
||||
if (isset($this->_item->etichetta) && $this->_item->etichetta != '')
|
||||
{
|
||||
if (is_object($this->_item->etichetta))
|
||||
{
|
||||
$this->_item->etichetta = ArrayHelper::fromObject($this->_item->etichetta);
|
||||
}
|
||||
|
||||
$values = (is_array($this->_item->etichetta)) ? $this->_item->etichetta : explode(',',$this->_item->etichetta);
|
||||
|
||||
$textValue = array();
|
||||
|
||||
foreach ($values as $value)
|
||||
{
|
||||
$db = $this->getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$query
|
||||
->select('`#__highlights_etichetta_4129035`.`nome`')
|
||||
->from($db->quoteName('#__highlights_etichetta', '#__highlights_etichetta_4129035'))
|
||||
->where($db->quoteName('nome') . ' = ' . $db->quote($value));
|
||||
|
||||
$db->setQuery($query);
|
||||
$results = $db->loadObject();
|
||||
|
||||
if ($results)
|
||||
{
|
||||
$textValue[] = $results->nome;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_item->etichetta = !empty($textValue) ? implode(', ', $textValue) : $this->_item->etichetta;
|
||||
|
||||
}
|
||||
|
||||
return $this->_item;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get an instance of Table class
|
||||
*
|
||||
* @param string $type Name of the Table class to get an instance of.
|
||||
* @param string $prefix Prefix for the table class name. Optional.
|
||||
* @param array $config Array of configuration values for the Table object. Optional.
|
||||
*
|
||||
* @return Table|bool Table if success, false on failure.
|
||||
*/
|
||||
public function getTable($type = 'Highlight', $prefix = 'Administrator', $config = array())
|
||||
{
|
||||
return parent::getTable($type, $prefix, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id of an item by alias
|
||||
* @param string $alias Item alias
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @deprecated No replacement
|
||||
*/
|
||||
public function getItemIdByAlias($alias)
|
||||
{
|
||||
$table = $this->getTable();
|
||||
$properties = $table->getProperties();
|
||||
$result = null;
|
||||
$aliasKey = null;
|
||||
if (method_exists($this, 'getAliasFieldNameByView'))
|
||||
{
|
||||
$aliasKey = $this->getAliasFieldNameByView('highlight');
|
||||
}
|
||||
|
||||
|
||||
if (key_exists('alias', $properties))
|
||||
{
|
||||
$table->load(array('alias' => $alias));
|
||||
$result = $table->id;
|
||||
}
|
||||
elseif (isset($aliasKey) && key_exists($aliasKey, $properties))
|
||||
{
|
||||
$table->load(array($aliasKey => $alias));
|
||||
$result = $table->id;
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to check in an item.
|
||||
*
|
||||
* @param integer $id The id of the row to check out.
|
||||
*
|
||||
* @return boolean True on success, false on failure.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function checkin($id = null)
|
||||
{
|
||||
// Get the id.
|
||||
$id = (!empty($id)) ? $id : (int) $this->getState('highlight.id');
|
||||
|
||||
if ($id)
|
||||
{
|
||||
// Initialise the table
|
||||
$table = $this->getTable();
|
||||
|
||||
// Attempt to check the row in.
|
||||
if (method_exists($table, 'checkin'))
|
||||
{
|
||||
if (!$table->checkin($id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to check out an item for editing.
|
||||
*
|
||||
* @param integer $id The id of the row to check out.
|
||||
*
|
||||
* @return boolean True on success, false on failure.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function checkout($id = null)
|
||||
{
|
||||
// Get the user id.
|
||||
$id = (!empty($id)) ? $id : (int) $this->getState('highlight.id');
|
||||
|
||||
|
||||
if ($id)
|
||||
{
|
||||
// Initialise the table
|
||||
$table = $this->getTable();
|
||||
|
||||
// Get the current user object.
|
||||
$user = Factory::getApplication()->getIdentity();
|
||||
|
||||
// Attempt to check the row out.
|
||||
if (method_exists($table, 'checkout'))
|
||||
{
|
||||
if (!$table->checkout($user->get('id'), $id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish the element
|
||||
*
|
||||
* @param int $id Item id
|
||||
* @param int $state Publish state
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function publish($id, $state)
|
||||
{
|
||||
$table = $this->getTable();
|
||||
|
||||
$table->load($id);
|
||||
$table->state = $state;
|
||||
|
||||
return $table->store();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to delete an item
|
||||
*
|
||||
* @param int $id Element id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$table = $this->getTable();
|
||||
|
||||
|
||||
return $table->delete($id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
415
components/com_highlights/src/Model/HighlightformModel.php
Normal file
415
components/com_highlights/src/Model/HighlightformModel.php
Normal file
@ -0,0 +1,415 @@
|
||||
<?php
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Highlights
|
||||
* @author Eddy Prosperi <eddy.prosperi@protocollicreativi.it>
|
||||
* @copyright 2024 Eddy Prosperi
|
||||
* @license GNU General Public License versione 2 o successiva; vedi LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Pcrt\Component\Highlights\Site\Model;
|
||||
// No direct access.
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use \Joomla\CMS\Factory;
|
||||
use \Joomla\Utilities\ArrayHelper;
|
||||
use \Joomla\CMS\Language\Text;
|
||||
use \Joomla\CMS\Table\Table;
|
||||
use \Joomla\CMS\MVC\Model\FormModel;
|
||||
use \Joomla\CMS\Object\CMSObject;
|
||||
use \Joomla\CMS\Helper\TagsHelper;
|
||||
|
||||
/**
|
||||
* Highlights model.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class HighlightformModel extends FormModel
|
||||
{
|
||||
private $item = null;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function populateState()
|
||||
{
|
||||
$app = Factory::getApplication('com_highlights');
|
||||
|
||||
// Load state from the request userState on edit or from the passed variable on default
|
||||
if (Factory::getApplication()->input->get('layout') == 'edit')
|
||||
{
|
||||
$id = Factory::getApplication()->getUserState('com_highlights.edit.highlight.id');
|
||||
}
|
||||
else
|
||||
{
|
||||
$id = Factory::getApplication()->input->get('id');
|
||||
Factory::getApplication()->setUserState('com_highlights.edit.highlight.id', $id);
|
||||
}
|
||||
|
||||
$this->setState('highlight.id', $id);
|
||||
|
||||
// Load the parameters.
|
||||
$params = $app->getParams();
|
||||
$params_array = $params->toArray();
|
||||
|
||||
if (isset($params_array['item_id']))
|
||||
{
|
||||
$this->setState('highlight.id', $params_array['item_id']);
|
||||
}
|
||||
|
||||
$this->setState('params', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get an ojbect.
|
||||
*
|
||||
* @param integer $id The id of the object to get.
|
||||
*
|
||||
* @return Object|boolean Object on success, false on failure.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getItem($id = null)
|
||||
{
|
||||
if ($this->item === null)
|
||||
{
|
||||
$this->item = false;
|
||||
|
||||
if (empty($id))
|
||||
{
|
||||
$id = $this->getState('highlight.id');
|
||||
}
|
||||
|
||||
// Get a level row instance.
|
||||
$table = $this->getTable();
|
||||
$properties = $table->getProperties();
|
||||
$this->item = ArrayHelper::toObject($properties, CMSObject::class);
|
||||
|
||||
if ($table !== false && $table->load($id) && !empty($table->id))
|
||||
{
|
||||
$user = Factory::getApplication()->getIdentity();
|
||||
$id = $table->id;
|
||||
|
||||
|
||||
$canEdit = $user->authorise('core.edit', 'com_highlights') || $user->authorise('core.create', 'com_highlights');
|
||||
|
||||
if (!$canEdit && $user->authorise('core.edit.own', 'com_highlights'))
|
||||
{
|
||||
$canEdit = $user->id == $table->created_by;
|
||||
}
|
||||
|
||||
if (!$canEdit)
|
||||
{
|
||||
throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403);
|
||||
}
|
||||
|
||||
// Check published state.
|
||||
if ($published = $this->getState('filter.published'))
|
||||
{
|
||||
if (isset($table->state) && $table->state != $published)
|
||||
{
|
||||
return $this->item;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert the Table to a clean CMSObject.
|
||||
$properties = $table->getProperties(1);
|
||||
$this->item = ArrayHelper::toObject($properties, CMSObject::class);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $this->item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the table
|
||||
*
|
||||
* @param string $type Name of the Table class
|
||||
* @param string $prefix Optional prefix for the table class name
|
||||
* @param array $config Optional configuration array for Table object
|
||||
*
|
||||
* @return Table|boolean Table if found, boolean false on failure
|
||||
*/
|
||||
public function getTable($type = 'Highlight', $prefix = 'Administrator', $config = array())
|
||||
{
|
||||
return parent::getTable($type, $prefix, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item by alias
|
||||
*
|
||||
* @param string $alias Alias string
|
||||
*
|
||||
* @return int Element id
|
||||
*/
|
||||
public function getItemIdByAlias($alias)
|
||||
{
|
||||
$table = $this->getTable();
|
||||
$properties = $table->getProperties();
|
||||
|
||||
if (!in_array('alias', $properties))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$table->load(array('alias' => $alias));
|
||||
$id = $table->id;
|
||||
|
||||
|
||||
return $id;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to check in an item.
|
||||
*
|
||||
* @param integer $id The id of the row to check out.
|
||||
*
|
||||
* @return boolean True on success, false on failure.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function checkin($id = null)
|
||||
{
|
||||
// Get the id.
|
||||
$id = (!empty($id)) ? $id : (int) $this->getState('highlight.id');
|
||||
|
||||
if ($id)
|
||||
{
|
||||
// Initialise the table
|
||||
$table = $this->getTable();
|
||||
|
||||
// Attempt to check the row in.
|
||||
if (method_exists($table, 'checkin'))
|
||||
{
|
||||
if (!$table->checkin($id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to check out an item for editing.
|
||||
*
|
||||
* @param integer $id The id of the row to check out.
|
||||
*
|
||||
* @return boolean True on success, false on failure.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function checkout($id = null)
|
||||
{
|
||||
// Get the user id.
|
||||
$id = (!empty($id)) ? $id : (int) $this->getState('highlight.id');
|
||||
|
||||
if ($id)
|
||||
{
|
||||
// Initialise the table
|
||||
$table = $this->getTable();
|
||||
|
||||
// Get the current user object.
|
||||
$user = Factory::getApplication()->getIdentity();
|
||||
|
||||
// Attempt to check the row out.
|
||||
if (method_exists($table, 'checkout'))
|
||||
{
|
||||
if (!$table->checkout($user->get('id'), $id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the profile form.
|
||||
*
|
||||
* The base form is loaded from XML
|
||||
*
|
||||
* @param array $data An optional array of data for the form to interogate.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
*
|
||||
* @return Form A Form object on success, false on failure
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getForm($data = array(), $loadData = true)
|
||||
{
|
||||
// Get the form.
|
||||
$form = $this->loadForm('com_highlights.highlight', 'highlightform', array(
|
||||
'control' => 'jform',
|
||||
'load_data' => $loadData
|
||||
)
|
||||
);
|
||||
|
||||
if (empty($form))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the data that should be injected in the form.
|
||||
*
|
||||
* @return array The default data is an empty array.
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function loadFormData()
|
||||
{
|
||||
$data = Factory::getApplication()->getUserState('com_highlights.edit.highlight.data', array());
|
||||
|
||||
if (empty($data))
|
||||
{
|
||||
$data = $this->getItem();
|
||||
}
|
||||
|
||||
if ($data)
|
||||
{
|
||||
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to save the form data.
|
||||
*
|
||||
* @param array $data The form data
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Exception
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function save($data)
|
||||
{
|
||||
$id = (!empty($data['id'])) ? $data['id'] : (int) $this->getState('highlight.id');
|
||||
$state = (!empty($data['state'])) ? 1 : 0;
|
||||
$user = Factory::getApplication()->getIdentity();
|
||||
|
||||
|
||||
if ($id)
|
||||
{
|
||||
// Check the user can edit this item
|
||||
$authorised = $user->authorise('core.edit', 'com_highlights') || $authorised = $user->authorise('core.edit.own', 'com_highlights');
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check the user can create new items in this section
|
||||
$authorised = $user->authorise('core.create', 'com_highlights');
|
||||
}
|
||||
|
||||
if ($authorised !== true)
|
||||
{
|
||||
throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403);
|
||||
}
|
||||
|
||||
$table = $this->getTable();
|
||||
|
||||
if(!empty($id))
|
||||
{
|
||||
$table->load($id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
try{
|
||||
if ($table->save($data) === true)
|
||||
{
|
||||
return $table->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
Factory::getApplication()->enqueueMessage($table->getError(), 'error');
|
||||
return false;
|
||||
}
|
||||
}catch(\Exception $e)
|
||||
{
|
||||
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to delete data
|
||||
*
|
||||
* @param int $pk Item primary key
|
||||
*
|
||||
* @return int The id of the deleted item
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$user = Factory::getApplication()->getIdentity();
|
||||
|
||||
|
||||
if (empty($id))
|
||||
{
|
||||
$id = (int) $this->getState('highlight.id');
|
||||
}
|
||||
|
||||
if ($id == 0 || $this->getItem($id) == null)
|
||||
{
|
||||
throw new \Exception(Text::_('COM_HIGHLIGHTS_ITEM_DOESNT_EXIST'), 404);
|
||||
}
|
||||
|
||||
if ($user->authorise('core.delete', 'com_highlights') !== true)
|
||||
{
|
||||
throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'), 403);
|
||||
}
|
||||
|
||||
$table = $this->getTable();
|
||||
|
||||
if ($table->delete($id) !== true)
|
||||
{
|
||||
throw new \Exception(Text::_('JERROR_FAILED'), 501);
|
||||
}
|
||||
|
||||
return $id;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if data can be saved
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getCanSave()
|
||||
{
|
||||
$table = $this->getTable();
|
||||
|
||||
return $table !== false;
|
||||
}
|
||||
|
||||
}
|
||||
288
components/com_highlights/src/Model/HighlightsModel.php
Normal file
288
components/com_highlights/src/Model/HighlightsModel.php
Normal file
@ -0,0 +1,288 @@
|
||||
<?php
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Highlights
|
||||
* @author Eddy Prosperi <eddy.prosperi@protocollicreativi.it>
|
||||
* @copyright 2024 Eddy Prosperi
|
||||
* @license GNU General Public License versione 2 o successiva; vedi LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Pcrt\Component\Highlights\Site\Model;
|
||||
// No direct access.
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use \Joomla\CMS\Factory;
|
||||
use \Joomla\CMS\Language\Text;
|
||||
use \Joomla\CMS\MVC\Model\ListModel;
|
||||
use \Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
|
||||
use \Joomla\CMS\Helper\TagsHelper;
|
||||
use \Joomla\CMS\Layout\FileLayout;
|
||||
use \Joomla\Database\ParameterType;
|
||||
use \Joomla\Utilities\ArrayHelper;
|
||||
use \Pcrt\Component\Highlights\Site\Helper\HighlightsHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Methods supporting a list of Highlights records.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class HighlightsModel extends ListModel
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $config An optional associative array of configuration settings.
|
||||
*
|
||||
* @see JController
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct($config = array())
|
||||
{
|
||||
if (empty($config['filter_fields']))
|
||||
{
|
||||
$config['filter_fields'] = array(
|
||||
'id', 'a.id',
|
||||
'state', 'a.state',
|
||||
'ordering', 'a.ordering',
|
||||
'created_by', 'a.created_by',
|
||||
'modified_by', 'a.modified_by',
|
||||
'etichetta', 'a.etichetta',
|
||||
'titolo', 'a.titolo',
|
||||
'sottotitolo', 'a.sottotitolo',
|
||||
'descrizione', 'a.descrizione',
|
||||
'lingua', 'a.lingua',
|
||||
'link_pulsante', 'a.link_pulsante',
|
||||
'testo_pulsante', 'a.testo_pulsante',
|
||||
'data', 'a.data',
|
||||
'immagine_main', 'a.immagine_main',
|
||||
'immagine_secondaria', 'a.immagine_secondaria',
|
||||
'data_inizio_pubblicazione', 'a.data_inizio_pubblicazione',
|
||||
'data_fine_pubblicazione', 'a.data_fine_pubblicazione',
|
||||
);
|
||||
}
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @param string $ordering Elements order
|
||||
* @param string $direction Order direction
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function populateState($ordering = null, $direction = null)
|
||||
{
|
||||
// List state information.
|
||||
parent::populateState('a.id', 'ASC');
|
||||
|
||||
$app = Factory::getApplication();
|
||||
$list = $app->getUserState($this->context . '.list');
|
||||
|
||||
$value = $app->getUserState($this->context . '.list.limit', $app->get('list_limit', 25));
|
||||
$list['limit'] = $value;
|
||||
|
||||
$this->setState('list.limit', $value);
|
||||
|
||||
$value = $app->input->get('limitstart', 0, 'uint');
|
||||
$this->setState('list.start', $value);
|
||||
|
||||
$ordering = $this->getUserStateFromRequest($this->context .'.filter_order', 'filter_order', 'a.id');
|
||||
$direction = strtoupper($this->getUserStateFromRequest($this->context .'.filter_order_Dir', 'filter_order_Dir', 'ASC'));
|
||||
|
||||
if(!empty($ordering) || !empty($direction))
|
||||
{
|
||||
$list['fullordering'] = $ordering . ' ' . $direction;
|
||||
}
|
||||
|
||||
$app->setUserState($this->context . '.list', $list);
|
||||
|
||||
|
||||
|
||||
$context = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
|
||||
$this->setState('filter.search', $context);
|
||||
|
||||
// Split context into component and optional section
|
||||
if (!empty($context))
|
||||
{
|
||||
$parts = FieldsHelper::extract($context);
|
||||
|
||||
if ($parts)
|
||||
{
|
||||
$this->setState('filter.component', $parts[0]);
|
||||
$this->setState('filter.section', $parts[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an SQL query to load the list data.
|
||||
*
|
||||
* @return DatabaseQuery
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function getListQuery()
|
||||
{
|
||||
// Create a new query object.
|
||||
$db = $this->getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// Select the required fields from the table.
|
||||
$query->select(
|
||||
$this->getState(
|
||||
'list.select', 'DISTINCT a.*'
|
||||
)
|
||||
);
|
||||
|
||||
$query->from('`#__highlights_` AS a');
|
||||
|
||||
// Join over the users for the checked out user.
|
||||
$query->select('uc.name AS uEditor');
|
||||
$query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out');
|
||||
|
||||
// Join over the created by field 'created_by'
|
||||
$query->join('LEFT', '#__users AS created_by ON created_by.id = a.created_by');
|
||||
|
||||
// Join over the created by field 'modified_by'
|
||||
$query->join('LEFT', '#__users AS modified_by ON modified_by.id = a.modified_by');
|
||||
// Join over the foreign key 'etichetta'
|
||||
$query->select('`#__highlights_etichetta_4129035`.`nome` AS etichette_fk_value_4129035');
|
||||
$query->join('LEFT', '#__highlights_etichetta AS #__highlights_etichetta_4129035 ON #__highlights_etichetta_4129035.`nome` = a.`etichetta`');
|
||||
|
||||
if (!Factory::getApplication()->getIdentity()->authorise('core.edit', 'com_highlights'))
|
||||
{
|
||||
$query->where('a.state = 1');
|
||||
}
|
||||
else
|
||||
{
|
||||
$query->where('(a.state IN (0, 1))');
|
||||
}
|
||||
|
||||
// Filter by search in title
|
||||
$search = $this->getState('filter.search');
|
||||
|
||||
if (!empty($search))
|
||||
{
|
||||
if (stripos($search, 'id:') === 0)
|
||||
{
|
||||
$query->where('a.id = ' . (int) substr($search, 3));
|
||||
}
|
||||
else
|
||||
{
|
||||
$search = $db->Quote('%' . $db->escape($search, true) . '%');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Add the list ordering clause.
|
||||
$orderCol = $this->state->get('list.ordering', 'a.id');
|
||||
$orderDirn = $this->state->get('list.direction', 'ASC');
|
||||
|
||||
if ($orderCol && $orderDirn)
|
||||
{
|
||||
$query->order($db->escape($orderCol . ' ' . $orderDirn));
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get an array of data items
|
||||
*
|
||||
* @return mixed An array of data on success, false on failure.
|
||||
*/
|
||||
public function getItems()
|
||||
{
|
||||
$items = parent::getItems();
|
||||
|
||||
foreach ($items as $item)
|
||||
{
|
||||
|
||||
if (isset($item->etichetta))
|
||||
{
|
||||
|
||||
$values = explode(',', $item->etichetta);
|
||||
$textValue = array();
|
||||
|
||||
foreach ($values as $value)
|
||||
{
|
||||
$db = $this->getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
$query
|
||||
->select('`#__highlights_etichetta_4129035`.`nome`')
|
||||
->from($db->quoteName('#__highlights_etichetta', '#__highlights_etichetta_4129035'))
|
||||
->where($db->quoteName('#__highlights_etichetta_4129035.nome') . ' = '. $db->quote($db->escape($value)));
|
||||
|
||||
$db->setQuery($query);
|
||||
$results = $db->loadObject();
|
||||
|
||||
if ($results)
|
||||
{
|
||||
$textValue[] = $results->nome;
|
||||
}
|
||||
}
|
||||
|
||||
$item->etichetta = !empty($textValue) ? implode(', ', $textValue) : $item->etichetta;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the default function to check Date fields format, identified by
|
||||
* "_dateformat" suffix, and erases the field if it's not correct.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function loadFormData()
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$filters = $app->getUserState($this->context . '.filter', array());
|
||||
$error_dateformat = false;
|
||||
|
||||
foreach ($filters as $key => $value)
|
||||
{
|
||||
if (strpos($key, '_dateformat') && !empty($value) && $this->isValidDate($value) == null)
|
||||
{
|
||||
$filters[$key] = '';
|
||||
$error_dateformat = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($error_dateformat)
|
||||
{
|
||||
$app->enqueueMessage(Text::_("COM_HIGHLIGHTS_SEARCH_FILTER_DATE_FORMAT"), "warning");
|
||||
$app->setUserState($this->context . '.filter', $filters);
|
||||
}
|
||||
|
||||
return parent::loadFormData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a given date is valid and in a specified format (YYYY-MM-DD)
|
||||
*
|
||||
* @param string $date Date to be checked
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isValidDate($date)
|
||||
{
|
||||
$date = str_replace('/', '-', $date);
|
||||
return (date_create($date)) ? Factory::getDate($date)->format("Y-m-d") : null;
|
||||
}
|
||||
}
|
||||
21
components/com_highlights/src/Service/Category.php
Normal file
21
components/com_highlights/src/Service/Category.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Highlights
|
||||
* @author Eddy Prosperi <eddy.prosperi@protocollicreativi.it>
|
||||
* @copyright 2024 Eddy Prosperi
|
||||
* @license GNU General Public License versione 2 o successiva; vedi LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Pcrt\Component\Highlights\Site\Service;
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use \Joomla\CMS\Categories\Categories;
|
||||
/**
|
||||
* Content Component Category Tree
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
151
components/com_highlights/src/Service/Router.php
Normal file
151
components/com_highlights/src/Service/Router.php
Normal file
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Highlights
|
||||
* @author Eddy Prosperi <eddy.prosperi@protocollicreativi.it>
|
||||
* @copyright 2024 Eddy Prosperi
|
||||
* @license GNU General Public License versione 2 o successiva; vedi LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Pcrt\Component\Highlights\Site\Service;
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Component\Router\RouterViewConfiguration;
|
||||
use Joomla\CMS\Component\Router\RouterView;
|
||||
use Joomla\CMS\Component\Router\Rules\StandardRules;
|
||||
use Joomla\CMS\Component\Router\Rules\NomenuRules;
|
||||
use Joomla\CMS\Component\Router\Rules\MenuRules;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Categories\Categories;
|
||||
use Joomla\CMS\Application\SiteApplication;
|
||||
use Joomla\CMS\Categories\CategoryFactoryInterface;
|
||||
use Joomla\CMS\Categories\CategoryInterface;
|
||||
use Joomla\Database\DatabaseInterface;
|
||||
use Joomla\CMS\Menu\AbstractMenu;
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
|
||||
/**
|
||||
* Class HighlightsRouter
|
||||
*
|
||||
*/
|
||||
class Router extends RouterView
|
||||
{
|
||||
private $noIDs;
|
||||
/**
|
||||
* The category factory
|
||||
*
|
||||
* @var CategoryFactoryInterface
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $categoryFactory;
|
||||
|
||||
/**
|
||||
* The category cache
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private $categoryCache = [];
|
||||
|
||||
public function __construct(SiteApplication $app, AbstractMenu $menu, CategoryFactoryInterface $categoryFactory, DatabaseInterface $db)
|
||||
{
|
||||
$params = ComponentHelper::getParams('com_highlights');
|
||||
$this->noIDs = (bool) $params->get('sef_ids');
|
||||
$this->categoryFactory = $categoryFactory;
|
||||
|
||||
|
||||
$highlights = new RouterViewConfiguration('highlights');
|
||||
$this->registerView($highlights);
|
||||
$ccHighlight = new RouterViewConfiguration('highlight');
|
||||
$ccHighlight->setKey('id')->setParent($highlights);
|
||||
$this->registerView($ccHighlight);
|
||||
$highlightform = new RouterViewConfiguration('highlightform');
|
||||
$highlightform->setKey('id');
|
||||
$this->registerView($highlightform);
|
||||
|
||||
parent::__construct($app, $menu);
|
||||
|
||||
$this->attachRule(new MenuRules($this));
|
||||
$this->attachRule(new StandardRules($this));
|
||||
$this->attachRule(new NomenuRules($this));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Method to get the segment(s) for an highlight
|
||||
*
|
||||
* @param string $id ID of the highlight to retrieve the segments for
|
||||
* @param array $query The request that is built right now
|
||||
*
|
||||
* @return array|string The segments of this item
|
||||
*/
|
||||
public function getHighlightSegment($id, $query)
|
||||
{
|
||||
return array((int) $id => $id);
|
||||
}
|
||||
/**
|
||||
* Method to get the segment(s) for an highlightform
|
||||
*
|
||||
* @param string $id ID of the highlightform to retrieve the segments for
|
||||
* @param array $query The request that is built right now
|
||||
*
|
||||
* @return array|string The segments of this item
|
||||
*/
|
||||
public function getHighlightformSegment($id, $query)
|
||||
{
|
||||
return $this->getHighlightSegment($id, $query);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to get the segment(s) for an highlight
|
||||
*
|
||||
* @param string $segment Segment of the highlight to retrieve the ID for
|
||||
* @param array $query The request that is parsed right now
|
||||
*
|
||||
* @return mixed The id of this item or false
|
||||
*/
|
||||
public function getHighlightId($segment, $query)
|
||||
{
|
||||
return (int) $segment;
|
||||
}
|
||||
/**
|
||||
* Method to get the segment(s) for an highlightform
|
||||
*
|
||||
* @param string $segment Segment of the highlightform to retrieve the ID for
|
||||
* @param array $query The request that is parsed right now
|
||||
*
|
||||
* @return mixed The id of this item or false
|
||||
*/
|
||||
public function getHighlightformId($segment, $query)
|
||||
{
|
||||
return $this->getHighlightId($segment, $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get categories from cache
|
||||
*
|
||||
* @param array $options The options for retrieving categories
|
||||
*
|
||||
* @return CategoryInterface The object containing categories
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function getCategories(array $options = []): CategoryInterface
|
||||
{
|
||||
$key = serialize($options);
|
||||
|
||||
if (!isset($this->categoryCache[$key]))
|
||||
{
|
||||
$this->categoryCache[$key] = $this->categoryFactory->createCategory($options);
|
||||
}
|
||||
|
||||
return $this->categoryCache[$key];
|
||||
}
|
||||
}
|
||||
140
components/com_highlights/src/View/Highlight/HtmlView.php
Normal file
140
components/com_highlights/src/View/Highlight/HtmlView.php
Normal file
@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Highlights
|
||||
* @author Eddy Prosperi <eddy.prosperi@protocollicreativi.it>
|
||||
* @copyright 2024 Eddy Prosperi
|
||||
* @license GNU General Public License versione 2 o successiva; vedi LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Pcrt\Component\Highlights\Site\View\Highlight;
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||
use \Joomla\CMS\Factory;
|
||||
use \Joomla\CMS\Language\Text;
|
||||
|
||||
/**
|
||||
* View class for a list of Highlights.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class HtmlView extends BaseHtmlView
|
||||
{
|
||||
protected $state;
|
||||
|
||||
protected $item;
|
||||
|
||||
protected $form;
|
||||
|
||||
protected $params;
|
||||
|
||||
/**
|
||||
* Display the view
|
||||
*
|
||||
* @param string $tpl Template name
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$user = $app->getIdentity();
|
||||
|
||||
$this->state = $this->get('State');
|
||||
$this->item = $this->get('Item');
|
||||
$this->params = $app->getParams('com_highlights');
|
||||
|
||||
if (!empty($this->item))
|
||||
{
|
||||
$this->form = $this->get('Form');
|
||||
}
|
||||
|
||||
// Check for errors.
|
||||
if (count($errors = $this->get('Errors')))
|
||||
{
|
||||
throw new \Exception(implode("\n", $errors));
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($this->_layout == 'edit')
|
||||
{
|
||||
$authorised = $user->authorise('core.create', 'com_highlights');
|
||||
|
||||
if ($authorised !== true)
|
||||
{
|
||||
throw new \Exception(Text::_('JERROR_ALERTNOAUTHOR'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->_prepareDocument();
|
||||
|
||||
parent::display($tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the document
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function _prepareDocument()
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$menus = $app->getMenu();
|
||||
$title = null;
|
||||
|
||||
// Because the application sets a default page title,
|
||||
// We need to get it from the menu item itself
|
||||
$menu = $menus->getActive();
|
||||
|
||||
if ($menu)
|
||||
{
|
||||
$this->params->def('page_heading', $this->params->get('page_title', $menu->title));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->params->def('page_heading', Text::_('COM_HIGHLIGHTS_DEFAULT_PAGE_TITLE'));
|
||||
}
|
||||
|
||||
$title = $this->params->get('page_title', '');
|
||||
|
||||
if (empty($title))
|
||||
{
|
||||
$title = $app->get('sitename');
|
||||
}
|
||||
elseif ($app->get('sitename_pagetitles', 0) == 1)
|
||||
{
|
||||
$title = Text::sprintf('JPAGETITLE', $app->get('sitename'), $title);
|
||||
}
|
||||
elseif ($app->get('sitename_pagetitles', 0) == 2)
|
||||
{
|
||||
$title = Text::sprintf('JPAGETITLE', $title, $app->get('sitename'));
|
||||
}
|
||||
|
||||
$this->document->setTitle($title);
|
||||
|
||||
if ($this->params->get('menu-meta_description'))
|
||||
{
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('menu-meta_keywords'))
|
||||
{
|
||||
$this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots'))
|
||||
{
|
||||
$this->document->setMetadata('robots', $this->params->get('robots'));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
129
components/com_highlights/src/View/Highlightform/HtmlView.php
Normal file
129
components/com_highlights/src/View/Highlightform/HtmlView.php
Normal file
@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Highlights
|
||||
* @author Eddy Prosperi <eddy.prosperi@protocollicreativi.it>
|
||||
* @copyright 2024 Eddy Prosperi
|
||||
* @license GNU General Public License versione 2 o successiva; vedi LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Pcrt\Component\Highlights\Site\View\Highlightform;
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||
use \Joomla\CMS\Factory;
|
||||
use \Joomla\CMS\Language\Text;
|
||||
|
||||
/**
|
||||
* View class for a list of Highlights.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class HtmlView extends BaseHtmlView
|
||||
{
|
||||
protected $state;
|
||||
|
||||
protected $item;
|
||||
|
||||
protected $form;
|
||||
|
||||
protected $params;
|
||||
|
||||
protected $canSave;
|
||||
|
||||
/**
|
||||
* Display the view
|
||||
*
|
||||
* @param string $tpl Template name
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$user = $app->getIdentity();
|
||||
|
||||
$this->state = $this->get('State');
|
||||
$this->item = $this->get('Item');
|
||||
$this->params = $app->getParams('com_highlights');
|
||||
$this->canSave = $this->get('CanSave');
|
||||
$this->form = $this->get('Form');
|
||||
|
||||
// Check for errors.
|
||||
if (count($errors = $this->get('Errors')))
|
||||
{
|
||||
throw new \Exception(implode("\n", $errors));
|
||||
}
|
||||
|
||||
|
||||
|
||||
$this->_prepareDocument();
|
||||
|
||||
parent::display($tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the document
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function _prepareDocument()
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$menus = $app->getMenu();
|
||||
$title = null;
|
||||
|
||||
// Because the application sets a default page title,
|
||||
// we need to get it from the menu item itself
|
||||
$menu = $menus->getActive();
|
||||
|
||||
if ($menu)
|
||||
{
|
||||
$this->params->def('page_heading', $this->params->get('page_title', $menu->title));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->params->def('page_heading', Text::_('COM_HIGHLIGHTS_DEFAULT_PAGE_TITLE'));
|
||||
}
|
||||
|
||||
$title = $this->params->get('page_title', '');
|
||||
|
||||
if (empty($title))
|
||||
{
|
||||
$title = $app->get('sitename');
|
||||
}
|
||||
elseif ($app->get('sitename_pagetitles', 0) == 1)
|
||||
{
|
||||
$title = Text::sprintf('JPAGETITLE', $app->get('sitename'), $title);
|
||||
}
|
||||
elseif ($app->get('sitename_pagetitles', 0) == 2)
|
||||
{
|
||||
$title = Text::sprintf('JPAGETITLE', $title, $app->get('sitename'));
|
||||
}
|
||||
|
||||
$this->document->setTitle($title);
|
||||
|
||||
if ($this->params->get('menu-meta_description'))
|
||||
{
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('menu-meta_keywords'))
|
||||
{
|
||||
$this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots'))
|
||||
{
|
||||
$this->document->setMetadata('robots', $this->params->get('robots'));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
135
components/com_highlights/src/View/Highlights/HtmlView.php
Normal file
135
components/com_highlights/src/View/Highlights/HtmlView.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @version CVS: 1.0.0
|
||||
* @package Com_Highlights
|
||||
* @author Eddy Prosperi <eddy.prosperi@protocollicreativi.it>
|
||||
* @copyright 2024 Eddy Prosperi
|
||||
* @license GNU General Public License versione 2 o successiva; vedi LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Pcrt\Component\Highlights\Site\View\Highlights;
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use \Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||
use \Joomla\CMS\Factory;
|
||||
use \Joomla\CMS\Language\Text;
|
||||
|
||||
/**
|
||||
* View class for a list of Highlights.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class HtmlView extends BaseHtmlView
|
||||
{
|
||||
protected $items;
|
||||
|
||||
protected $pagination;
|
||||
|
||||
protected $state;
|
||||
|
||||
protected $params;
|
||||
|
||||
/**
|
||||
* Display the view
|
||||
*
|
||||
* @param string $tpl Template name
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
|
||||
$this->state = $this->get('State');
|
||||
$this->items = $this->get('Items');
|
||||
$this->pagination = $this->get('Pagination');
|
||||
$this->params = $app->getParams('com_highlights');
|
||||
|
||||
|
||||
// Check for errors.
|
||||
if (count($errors = $this->get('Errors')))
|
||||
{
|
||||
throw new \Exception(implode("\n", $errors));
|
||||
}
|
||||
|
||||
$this->_prepareDocument();
|
||||
parent::display($tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the document
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function _prepareDocument()
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$menus = $app->getMenu();
|
||||
$title = null;
|
||||
|
||||
// Because the application sets a default page title,
|
||||
// we need to get it from the menu item itself
|
||||
$menu = $menus->getActive();
|
||||
|
||||
if ($menu)
|
||||
{
|
||||
$this->params->def('page_heading', $this->params->get('page_title', $menu->title));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->params->def('page_heading', Text::_('COM_HIGHLIGHTS_DEFAULT_PAGE_TITLE'));
|
||||
}
|
||||
|
||||
$title = $this->params->get('page_title', '');
|
||||
|
||||
if (empty($title))
|
||||
{
|
||||
$title = $app->get('sitename');
|
||||
}
|
||||
elseif ($app->get('sitename_pagetitles', 0) == 1)
|
||||
{
|
||||
$title = Text::sprintf('JPAGETITLE', $app->get('sitename'), $title);
|
||||
}
|
||||
elseif ($app->get('sitename_pagetitles', 0) == 2)
|
||||
{
|
||||
$title = Text::sprintf('JPAGETITLE', $title, $app->get('sitename'));
|
||||
}
|
||||
|
||||
$this->document->setTitle($title);
|
||||
|
||||
if ($this->params->get('menu-meta_description'))
|
||||
{
|
||||
$this->document->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('menu-meta_keywords'))
|
||||
{
|
||||
$this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots'))
|
||||
{
|
||||
$this->document->setMetadata('robots', $this->params->get('robots'));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if state is set
|
||||
*
|
||||
* @param mixed $state State
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getState($state)
|
||||
{
|
||||
return isset($this->state->{$state}) ? $this->state->{$state} : false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user