ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.AccessManager.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
21 namespace ILIAS\Notes;
22 
27 {
28  protected \ilAccessHandler $access;
29  protected \ilSetting $settings;
30  protected int $user_id;
34 
35  public function __construct(
36  InternalDataService $data,
37  InternalRepoService $repo,
38  InternalDomainService $domain
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) {
53  $user_id = $this->user_id;
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) {
64  $user_id = $this->user_id;
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 
71  if ($user_id === ANONYMOUS_USER_ID) {
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 }
canDelete(Note $note, int $user_id=0, $public_deletion_enabled=false)
const ANONYMOUS_USER_ID
Definition: constants.php:27
static _getAllReferences(int $id)
get all reference ids for object ID
Repository internal data service.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:67
canEdit(Note $note, int $user_id=0)
InternalDomainService $domain
__construct(InternalDataService $data, InternalRepoService $repo, InternalDomainService $domain)