Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
moodle-mod_pdfannotator
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elc
moodle-mod_pdfannotator
Commits
09d4eed3
Commit
09d4eed3
authored
2 years ago
by
Matthew Hilton
Committed by
Anisa
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[#84] Fix userlist provider sql
parent
1c499352
Branches
Branches containing commit
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
+112
-0
112 additions, 0 deletions
classes/privacy/provider.php
with
112 additions
and
0 deletions
classes/privacy/provider.php
+
112
−
0
View file @
09d4eed3
...
@@ -440,4 +440,116 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
...
@@ -440,4 +440,116 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
}
}
}
}
/**
* Finds the users in the given userlists's context.
* @param userlist $userlist
*/
public
static
function
get_users_in_context
(
userlist
$userlist
)
{
$context
=
$userlist
->
get_context
();
if
(
!
$context
instanceof
\context_module
)
{
return
;
}
$params
=
[
'contextid'
=>
$context
->
instanceid
,
'modulename'
=>
'pdfannotator'
,
];
// Comments.
$sql
=
"SELECT ac.userid
FROM
{
course_modules
}
cm
JOIN
{
modules
}
m ON m.id = cm.module AND m.name = :modulename
JOIN
{
pdfannotator
}
a ON a.id = cm.instance
JOIN
{
pdfannotator_comments
}
ac ON ac.pdfannotatorid = a.id
WHERE cm.id = :contextid"
;
$userlist
->
add_from_sql
(
'userid'
,
$sql
,
$params
);
// Reports.
$sql
=
"SELECT ar.userid
FROM
{
course_modules
}
cm
JOIN
{
modules
}
m ON m.id = cm.module AND m.name = :modulename
JOIN
{
pdfannotator
}
a ON a.id = cm.instance
JOIN
{
pdfannotator_reports
}
ar ON ar.pdfannotatorid = a.id
WHERE cm.id = :contextid"
;
$userlist
->
add_from_sql
(
'userid'
,
$sql
,
$params
);
// Annotations.
$sql
=
"SELECT ats.userid
FROM
{
course_modules
}
cm
JOIN
{
modules
}
m ON m.id = cm.module AND m.name = :modulename
JOIN
{
pdfannotator
}
a ON a.id = cm.instance
JOIN
{
pdfannotator_annotations
}
ats ON ats.pdfannotatorid = a.id
WHERE cm.id = :contextid"
;
$userlist
->
add_from_sql
(
'userid'
,
$sql
,
$params
);
// Votes.
$sql
=
"SELECT v.userid
FROM
{
course_modules
}
cm
JOIN
{
modules
}
m ON m.id = cm.module AND m.name = :modulename
JOIN
{
pdfannotator
}
a ON a.id = cm.instance
JOIN
{
pdfannotator_comments
}
ac ON ac.pdfannotatorid = a.id
JOIN
{
pdfannotator_votes
}
v ON v.commentid = ac.id
WHERE cm.id = :contextid"
;
$userlist
->
add_from_sql
(
'userid'
,
$sql
,
$params
);
// Subscriptions
$sql
=
"SELECT asub.userid
FROM
{
course_modules
}
cm
JOIN
{
modules
}
m ON m.id = cm.module AND m.name = :modulename
JOIN
{
pdfannotator
}
a ON a.id = cm.instance
JOIN
{
pdfannotator_annotations
}
ats ON ats.pdfannotatorid = a.id
JOIN
{
pdfannotator_subscriptions
}
asub ON a.id = asub.annotationid
WHERE cm.id = :contextid"
;
$userlist
->
add_from_sql
(
'userid'
,
$sql
,
$params
);
}
/**
* Deletes data for users in given userlist's context.
* @param approved_userlist $userlist
*/
public
static
function
delete_data_for_users
(
approved_userlist
$userlist
)
{
global
$DB
;
$context
=
$userlist
->
get_context
();
if
(
!
$context
instanceof
\context_module
)
{
return
;
}
list
(
$userinsql
,
$userinparams
)
=
$DB
->
get_in_or_equal
(
$userlist
->
get_userids
(),
SQL_PARAMS_NAMED
);
// Find the instance.
$annotationinstance
=
get_coursemodule_from_id
(
'pdfannotator'
,
$context
->
instanceid
);
$annotatorid
=
$annotationinstance
->
id
;
// Combine instance + user sql.
$params
=
array_merge
([
'pdfannotatorid'
=>
$annotatorid
],
$userinparams
);
$sql
=
"pdfannotatorid = :pdfannotatorid AND userid
{
$userinsql
}
"
;
// Delete subscriptions.
$annotations
=
$DB
->
get_records
(
'pdfannotator_annotations'
,
[
'pdfannotatorid'
=>
$annotatorid
]);
$annotationids
=
array_column
(
$annotations
,
'id'
);
list
(
$subinsql
,
$subinparams
)
=
$DB
->
get_in_or_equal
(
$annotationids
,
SQL_PARAMS_NAMED
);
$DB
->
execute
(
"DELETE FROM
{
pdfannotator_subscriptions
}
sub
WHERE sub.userid
{
$userinsql
}
AND sub.annotationid
{
$subinsql
}
"
,
array_merge
(
$userinparams
,
$subinparams
));
// Delete votes.
$comments
=
$DB
->
get_records
(
'pdfannotator_comments'
,
[
'pdfannotatorid'
=>
$annotatorid
]);
$commentsids
=
array_column
(
$comments
,
'id'
);
list
(
$commentinsql
,
$commentinparams
)
=
$DB
->
get_in_or_equal
(
$commentsids
,
SQL_PARAMS_NAMED
);
$DB
->
execute
(
"DELETE FORM
{
pdfannotator_votes
}
votes
WHERE vote.userid
{
$userinsql
}
AND vote.commentid
{
$commentinsql
}
"
,
array_merge
(
$userinparams
,
$commentinparams
));
// Delete rest of data.
$DB
->
delete_records_select
(
'pdfannotator_annotations'
,
$sql
,
$params
);
$DB
->
delete_records_select
(
'pdfannotator_reports'
,
$sql
,
$params
);
$DB
->
delete_records_select
(
'pdfannotator_comments'
,
$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