Skip to content

Commit

Permalink
Namespace models
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Babker committed Apr 14, 2019
1 parent ab94577 commit 0f11de2
Show file tree
Hide file tree
Showing 7 changed files with 282 additions and 209 deletions.
Expand Up @@ -7,14 +7,22 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Component\Privacy\Administrator\Model;

defined('_JEXEC') or die;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\BaseModel;
use Joomla\CMS\Plugin\PluginHelper;

/**
* Capabilities model class.
*
* @since 3.9.0
*/
class PrivacyModelCapabilities extends JModelLegacy
class CapabilitiesModel extends BaseModel
{
/**
* Retrieve the extension capabilities.
Expand All @@ -25,7 +33,7 @@ class PrivacyModelCapabilities extends JModelLegacy
*/
public function getCapabilities()
{
$app = JFactory::getApplication();
$app = Factory::getApplication();

/*
* Capabilities will be collected in two parts:
Expand All @@ -39,13 +47,13 @@ public function getCapabilities()
* $coreCapabilities array below.
*/

$coreCapabilities = array(
JText::_('COM_PRIVACY_HEADING_CORE_CAPABILITIES') => array(
JText::_('COM_PRIVACY_CORE_CAPABILITY_SESSION_IP_ADDRESS_AND_COOKIE'),
JText::sprintf('COM_PRIVACY_CORE_CAPABILITY_LOGGING_IP_ADDRESS', $app->get('log_path', JPATH_ADMINISTRATOR . '/logs')),
JText::_('COM_PRIVACY_CORE_CAPABILITY_COMMUNICATION_WITH_JOOMLA_ORG'),
)
);
$coreCapabilities = [
Text::_('COM_PRIVACY_HEADING_CORE_CAPABILITIES') => [
Text::_('COM_PRIVACY_CORE_CAPABILITY_SESSION_IP_ADDRESS_AND_COOKIE'),
Text::sprintf('COM_PRIVACY_CORE_CAPABILITY_LOGGING_IP_ADDRESS', $app->get('log_path', JPATH_ADMINISTRATOR . '/logs')),
Text::_('COM_PRIVACY_CORE_CAPABILITY_COMMUNICATION_WITH_JOOMLA_ORG'),
],
];

/*
* We will search for capabilities from the following plugin groups:
Expand All @@ -59,20 +67,20 @@ public function getCapabilities()
* This is in addition to plugin groups which are imported before this method is triggered, generally this is the system group.
*/

JPluginHelper::importPlugin('authentication');
JPluginHelper::importPlugin('captcha');
JPluginHelper::importPlugin('installer');
JPluginHelper::importPlugin('privacy');
JPluginHelper::importPlugin('user');
PluginHelper::importPlugin('authentication');
PluginHelper::importPlugin('captcha');
PluginHelper::importPlugin('installer');
PluginHelper::importPlugin('privacy');
PluginHelper::importPlugin('user');

$pluginResults = $app->triggerEvent('onPrivacyCollectAdminCapabilities');

// We are going to "cheat" here and include this component's capabilities without using a plugin
$extensionCapabilities = array(
JText::_('COM_PRIVACY') => array(
$extensionCapabilities = [
JText::_('COM_PRIVACY') => [
JText::_('COM_PRIVACY_EXTENSION_CAPABILITY_PERSONAL_INFO'),
)
);
],
];

foreach ($pluginResults as $pluginResult)
{
Expand All @@ -96,6 +104,6 @@ public function getCapabilities()
protected function populateState()
{
// Load the parameters.
$this->setState('params', JComponentHelper::getParams('com_privacy'));
$this->setState('params', ComponentHelper::getParams('com_privacy'));
}
}
Expand Up @@ -7,16 +7,22 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Component\Privacy\Administrator\Model;

defined('_JEXEC') or die;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Database\DatabaseQuery;
use Joomla\Database\Exception\ExecutionFailureException;
use Joomla\Utilities\ArrayHelper;

/**
* Consents management model class.
*
* @since 3.9.0
*/
class PrivacyModelConsents extends JModelList
class ConsentsModel extends ListModel
{
/**
* Constructor.
Expand All @@ -25,25 +31,25 @@ class PrivacyModelConsents extends JModelList
*
* @since 3.9.0
*/
public function __construct($config = array())
public function __construct($config = [])
{
if (empty($config['filter_fields']))
{
$config['filter_fields'] = array(
$config['filter_fields'] = [
'id', 'a.id', 'a.user_id',
'created', 'a.created',
'username', 'u.username',
'state', 'a.state'
);
'state', 'a.state',
];
}

parent::__construct($config);
}

/**
* Method to get a JDatabaseQuery object for retrieving the data set from a database.
* Method to get a DatabaseQuery object for retrieving the data set from a database.
*
* @return JDatabaseQuery
* @return DatabaseQuery
*
* @since 3.9.0
*/
Expand Down Expand Up @@ -152,7 +158,7 @@ protected function populateState($ordering = 'a.id', $direction = 'desc')
);

// Load the parameters.
$this->setState('params', JComponentHelper::getParams('com_privacy'));
$this->setState('params', ComponentHelper::getParams('com_privacy'));

// List state information.
parent::populateState($ordering, $direction);
Expand Down Expand Up @@ -182,7 +188,7 @@ public function invalidate($pks)
$db->setQuery($query);
$db->execute();
}
catch (JDatabaseExceptionExecuting $e)
catch (ExecutionFailureException $e)
{
$this->setError($e->getMessage());

Expand Down Expand Up @@ -212,7 +218,7 @@ public function invalidateAll($subject)
$db->setQuery($query);
$db->execute();
}
catch (JDatabaseExceptionExecuting $e)
catch (ExecutionFailureException $e)
{
$this->setError($e->getMessage());

Expand Down
Expand Up @@ -7,14 +7,22 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Component\Privacy\Administrator\Model;

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Menu\MenuItem;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Router\Route;

/**
* Dashboard model class.
*
* @since 3.9.0
*/
class PrivacyModelDashboard extends JModelLegacy
class DashboardModel extends BaseDatabaseModel
{
/**
* Get the information about the published privacy policy
Expand All @@ -25,20 +33,20 @@ class PrivacyModelDashboard extends JModelLegacy
*/
public function getPrivacyPolicyInfo()
{
$policy = array(
'published' => false,
'articlePublished' => false,
'editLink' => '',
);
$policy = [
'published' => false,
'articlePublished' => false,
'editLink' => '',
];

/*
* Prior to 3.9.0 it was common for a plugin such as the User - Profile plugin to define a privacy policy or
* terms of service article, therefore we will also import the user plugin group to process this event.
*/
JPluginHelper::importPlugin('privacy');
JPluginHelper::importPlugin('user');
PluginHelper::importPlugin('privacy');
PluginHelper::importPlugin('user');

JFactory::getApplication()->triggerEvent('onPrivacyCheckPrivacyPolicyPublished', array(&$policy));
Factory::getApplication()->triggerEvent('onPrivacyCheckPrivacyPolicyPublished', [&$policy]);

return $policy;
}
Expand All @@ -55,11 +63,11 @@ public function getRequestCounts()
$db = $this->getDbo();
$query = $db->getQuery(true)
->select(
array(
[
'COUNT(*) AS count',
$db->quoteName('status'),
$db->quoteName('request_type'),
)
]
)
->from($db->quoteName('#__privacy_requests'))
->group($db->quoteName('status'))
Expand All @@ -79,16 +87,16 @@ public function getRequestCounts()
*/
public function getRequestFormPublished()
{
$app = JFactory::getApplication();
$app = Factory::getApplication();
$menu = $app->getMenu('site');

$item = $menu->getItems('link', 'index.php?option=com_privacy&view=request', true);

$status = array(
$status = [
'exists' => false,
'published' => false,
'link' => '',
);
];

$db = $this->getDbo();
$query = $db->getQuery(true)
Expand All @@ -106,14 +114,14 @@ public function getRequestFormPublished()

$linkMode = $app->get('force_ssl', 0) == 2 ? 1 : -1;

if (!($item instanceof JMenuItem))
if (!($item instanceof MenuItem))
{
$status['link'] = JRoute::link('site', 'index.php?option=com_privacy&view=request', true, $linkMode);
$status['link'] = Route::link('site', 'index.php?option=com_privacy&view=request', true, $linkMode);
}
else
{
$status['published'] = true;
$status['link'] = JRoute::link('site', 'index.php?Itemid=' . $item->id, true, $linkMode);
$status['link'] = Route::link('site', 'index.php?Itemid=' . $item->id, true, $linkMode);
}

return $status;
Expand Down

0 comments on commit 0f11de2

Please sign in to comment.