ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.AccessManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Notes;
22
27{
28 protected \ilAccessHandler $access;
29 protected \ilSetting $settings;
30 protected int $user_id;
34
35 public function __construct(
39 ) {
40 $this->data = $data;
41 $this->repo = $repo;
42 $this->domain = $domain;
43 $this->user_id = $domain->user()->getId();
44 $this->settings = $domain->settings();
45 $this->access = $domain->access();
46 }
47
48 public function canEdit(
49 Note $note,
50 int $user_id = 0
51 ): bool {
52 if ($user_id === 0) {
54 }
55 return $user_id !== ANONYMOUS_USER_ID && $note->getAuthor() === $user_id;
56 }
57
58 public function canDelete(
59 Note $note,
60 int $user_id = 0,
61 $public_deletion_enabled = false
62 ): bool {
63 if ($user_id === 0) {
65 }
66 $settings = $this->settings;
67 $access = $this->access;
68 $user_can_delete_their_comments = (bool) $settings->get("comments_del_user", '0');
69 $tutor_can_delete_comments = (bool) $settings->get("comments_del_tutor", '1');
70
72 return false;
73 }
74
75 $is_author = ($note->getAuthor() === $user_id);
76
77 if ($is_author && $note->getType() === Note::PRIVATE) {
78 return true;
79 }
80
81 if ($public_deletion_enabled && $note->getType() === Note::PUBLIC) {
82 return true;
83 }
84
85 if ($is_author && $user_can_delete_their_comments && $note->getType() === Note::PUBLIC) {
86 return true;
87 }
88
89 // this logic has been set from pdnotes
90 if ($tutor_can_delete_comments) {
91 foreach (\ilObject::_getAllReferences($note->getContext()->getObjId()) as $ref_id) {
92 if ($access->checkAccess("write", "", $ref_id)) {
93 return true;
94 }
95 }
96 }
97 return false;
98 }
99}
__construct(InternalDataService $data, InternalRepoService $repo, InternalDomainService $domain)
InternalDomainService $domain
canDelete(Note $note, int $user_id=0, $public_deletion_enabled=false)
canEdit(Note $note, int $user_id=0)
static _getAllReferences(int $id)
get all reference ids for object ID
const ANONYMOUS_USER_ID
Definition: constants.php:27
$ref_id
Definition: ltiauth.php:66
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))