-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
PrivacyHelper.php
87 lines (74 loc) · 2.02 KB
/
PrivacyHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* @package Joomla.Administrator
* @subpackage com_privacy
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Privacy\Administrator\Helper;
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\ContentHelper;
use Joomla\Component\Privacy\Administrator\Export\Domain;
/**
* Privacy component helper.
*
* @since 3.9.0
*/
class PrivacyHelper extends ContentHelper
{
/**
* Render the data request as a XML document.
*
* @param Domain[] $exportData The data to be exported.
*
* @return string
*
* @since 3.9.0
*/
public static function renderDataAsXml(array $exportData)
{
$export = new \SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><data-export />');
foreach ($exportData as $domain)
{
$xmlDomain = $export->addChild('domain');
$xmlDomain->addAttribute('name', $domain->name);
$xmlDomain->addAttribute('description', $domain->description);
foreach ($domain->getItems() as $item)
{
$xmlItem = $xmlDomain->addChild('item');
if ($item->id)
{
$xmlItem->addAttribute('id', $item->id);
}
foreach ($item->getFields() as $field)
{
$xmlItem->{$field->name} = $field->value;
}
}
}
$dom = new \DOMDocument;
$dom->loadXML($export->asXML());
$dom->formatOutput = true;
return $dom->saveXML();
}
/**
* Gets the privacyconsent system plugin extension id.
*
* @return integer The privacyconsent system plugin extension id.
*
* @since 3.9.2
*/
public static function getPrivacyConsentPluginId()
{
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('extension_id'))
->from($db->quoteName('#__extensions'))
->where($db->quoteName('folder') . ' = ' . $db->quote('system'))
->where($db->quoteName('element') . ' = ' . $db->quote('privacyconsent'));
$db->setQuery($query);
return (int) $db->loadResult();
}
}