diff --git a/libraries/src/MVC/Model/BaseDatabaseModel.php b/libraries/src/MVC/Model/BaseDatabaseModel.php index 219142e7254e9..bb2ad7972fb92 100644 --- a/libraries/src/MVC/Model/BaseDatabaseModel.php +++ b/libraries/src/MVC/Model/BaseDatabaseModel.php @@ -13,6 +13,7 @@ use Joomla\CMS\MVC\Factory\LegacyFactory; use Joomla\CMS\MVC\Factory\MVCFactoryInterface; use Joomla\Utilities\ArrayHelper; +use Joomla\CMS\Plugin\PluginHelper; /** * Base class for a database aware Joomla Model @@ -620,4 +621,27 @@ protected function cleanCache($group = null, $clientId = 0) // Trigger the onContentCleanCache event. \JEventDispatcher::getInstance()->trigger($this->event_clean_cache, $options); } + + /** + * Trigger an event. + * + * @param string $event The event to trigger. + * @param array $args An array of arguments. + * @param string $group The name of the plugin group to import + * + * @return array An array of results from each event call. + * + * @since 3.0 + */ + + protected function triggerEvent($event, $args = array(), $group = null) + { + if(isset($group)) + { + PluginHelper::importPlugin($group); + } + + $dispatcher = \JEventDispatcher::getInstance(); + return $dispatcher->trigger($event, $args); + } } diff --git a/libraries/src/MVC/Model/ListModel.php b/libraries/src/MVC/Model/ListModel.php index fa972b3c725c3..257e9b920757a 100644 --- a/libraries/src/MVC/Model/ListModel.php +++ b/libraries/src/MVC/Model/ListModel.php @@ -93,6 +93,14 @@ class ListModel extends BaseDatabaseModel */ protected $listBlacklist = array('select'); + /** + * The event that is triggered after the request is created + * + * @var string + * @since 1.6 + */ + protected $event_prepare_list_query = null; + /** * Constructor. * @@ -106,6 +114,15 @@ public function __construct($config = array(), MVCFactoryInterface $factory = nu { parent::__construct($config, $factory); + if (isset($config['event_prepare_list_query'])) + { + $this->event_prepare_list_query = $config['event_prepare_list_query']; + } + elseif (empty($this->event_prepare_list_query)) + { + $this->event_prepare_list_query = 'onPrepareListQuery'; + } + // Add the ordering filtering fields whitelist. if (isset($config['filter_fields'])) { @@ -190,8 +207,13 @@ public function getItems() try { + $query = $this->_getListQuery(); + $args = [$this->context, &$query, $this]; + + $this->triggerEvent($this->event_prepare_list_query, $args); + // Load the list items and add the items to the internal cache. - $this->cache[$store] = $this->_getList($this->_getListQuery(), $this->getStart(), $this->getState('list.limit')); + $this->cache[$store] = $this->_getList($query, $this->getStart(), $this->getState('list.limit')); } catch (\RuntimeException $e) { @@ -285,8 +307,13 @@ public function getTotal() try { + $query = $this->_getListQuery(); + $args = [$this->context, &$query, $this]; + + $this->triggerEvent($this->event_prepare_list_query, $args); + // Load the total and add the total to the internal cache. - $this->cache[$store] = (int) $this->_getListCount($this->_getListQuery()); + $this->cache[$store] = (int) $this->_getListCount($query); } catch (\RuntimeException $e) {