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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user