Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
moodle-tool_lifecycle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elc
moodle-tool_lifecycle
Commits
2c4e7e4e
Commit
2c4e7e4e
authored
5 years ago
by
Justus Dieckmann
Committed by
Tobias Reischmann
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Privacy: Implement get_users_in_context and delete_data_for_users
parent
7746bd01
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
classes/privacy/provider.php
+45
-3
45 additions, 3 deletions
classes/privacy/provider.php
with
45 additions
and
3 deletions
classes/privacy/provider.php
+
45
−
3
View file @
2c4e7e4e
...
@@ -26,7 +26,10 @@ namespace tool_lifecycle\privacy;
...
@@ -26,7 +26,10 @@ namespace tool_lifecycle\privacy;
use
core_privacy
\local\metadata\collection
;
use
core_privacy
\local\metadata\collection
;
use
core_privacy\local\request\approved_contextlist
;
use
core_privacy\local\request\approved_contextlist
;
use
core_privacy\local\request\approved_userlist
;
use
core_privacy
\local\request\context
;
use
core_privacy
\local\request\contextlist
;
use
core_privacy
\local\request\contextlist
;
use
core_privacy
\local\request\userlist
;
use
core_privacy
\local\request\writer
;
use
core_privacy
\local\request\writer
;
defined
(
'MOODLE_INTERNAL'
)
||
die
();
defined
(
'MOODLE_INTERNAL'
)
||
die
();
...
@@ -37,8 +40,15 @@ defined('MOODLE_INTERNAL') || die();
...
@@ -37,8 +40,15 @@ defined('MOODLE_INTERNAL') || die();
* @copyright 2019 Justus Dieckmann WWU
* @copyright 2019 Justus Dieckmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
*/
class
provider
implements
\core_privacy\local\metadata\provider
,
class
provider
implements
\core_privacy\local\request\plugin\provider
{
// This plugin has data.
\core_privacy\local\metadata\provider
,
// This plugin currently implements the original plugin_provider interface.
\core_privacy\local\request\plugin\provider
,
// This plugin is capable of determining which users have data within it.
\core_privacy\local\request\core_userlist_provider
{
/**
/**
* Returns meta data about this system.
* Returns meta data about this system.
...
@@ -84,7 +94,7 @@ class provider implements \core_privacy\local\metadata\provider,
...
@@ -84,7 +94,7 @@ class provider implements \core_privacy\local\metadata\provider,
public
static
function
export_user_data
(
approved_contextlist
$contextlist
)
{
public
static
function
export_user_data
(
approved_contextlist
$contextlist
)
{
global
$DB
;
global
$DB
;
foreach
(
$contextlist
->
get_contexts
()
as
$context
)
{
foreach
(
$contextlist
->
get_contexts
()
as
$context
)
{
if
(
$context
->
contextlevel
===
CONTEXT_SYSTEM
)
{
if
(
$context
instanceof
\context_system
)
{
$records
=
$DB
->
get_records
(
'tool_lifecycle_action_log'
,
array
(
'userid'
=>
$contextlist
->
get_user
()
->
id
));
$records
=
$DB
->
get_records
(
'tool_lifecycle_action_log'
,
array
(
'userid'
=>
$contextlist
->
get_user
()
->
id
));
$writer
=
writer
::
with_context
(
$contextlist
->
current
());
$writer
=
writer
::
with_context
(
$contextlist
->
current
());
foreach
(
$records
as
$record
)
{
foreach
(
$records
as
$record
)
{
...
@@ -125,4 +135,36 @@ class provider implements \core_privacy\local\metadata\provider,
...
@@ -125,4 +135,36 @@ class provider implements \core_privacy\local\metadata\provider,
}
}
}
}
}
}
/**
* Get the list of users who have data within a context.
*
* @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
*/
public
static
function
get_users_in_context
(
userlist
$userlist
)
{
$context
=
$userlist
->
get_context
();
if
(
$context
instanceof
\context_system
)
{
$sql
=
"SELECT userid
FROM
{
tool_lifecycle_action_log
}
"
;
$userlist
->
add_from_sql
(
'userid'
,
$sql
,
array
());
}
}
/**
* Delete multiple users within a single context.
*
* @param approved_userlist $userlist The approved context and user information to delete information for.
*/
public
static
function
delete_data_for_users
(
approved_userlist
$userlist
)
{
global
$DB
;
$context
=
$userlist
->
get_context
();
if
(
$context
instanceof
\context_system
)
{
list
(
$insql
,
$params
)
=
$DB
->
get_in_or_equal
(
$userlist
->
get_userids
());
$sql
=
"UPDATE
{
tool_lifecycle_action_log
}
SET userid = -1
WHERE
$insql
"
;
$DB
->
execute
(
$sql
,
$params
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment