ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
PermissionManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24{
25 protected int $owner;
26 protected int $id_type;
27 protected $access;
28 protected ?int $node_id;
29 protected int $user_id;
30
31 public function __construct(
32 $access_handler,
33 ?int $node_id,
34 int $id_type,
35 int $user_id,
36 int $owner
37 ) {
38 $this->access = $access_handler;
39 $this->node_id = $node_id;
40 $this->id_type = $id_type;
41 $this->user_id = $user_id;
42 $this->owner = $owner;
43 }
44
45 public function canWrite(): bool
46 {
47 return $this->access->checkAccess('write', '', $this->node_id);
48 }
49
50 public function mayContribute(): bool
51 {
52 if ($this->id_type === \ilObject2GUI::WORKSPACE_NODE_ID) {
53 return $this->checkPermissionBool("write");
54 }
55
56 return ($this->checkPermissionBool("redact") ||
57 $this->checkPermissionBool("contribute"));
58 }
59
60 public function mayEditPosting(
61 int $a_posting_id,
62 ?int $a_author_id = null
63 ): bool {
64 // single author blog (owner) in personal workspace
65 if ($this->id_type === \ilObject2GUI::WORKSPACE_NODE_ID) {
66 return $this->checkPermissionBool("write");
67 }
68
69 // repository blogs
70
71 // redact allows to edit all postings
72 if ($this->checkPermissionBool("redact")) {
73 return true;
74 }
75
76 // contribute gives access to own postings
77 if ($this->checkPermissionBool("contribute")) {
78 // check owner of posting
79 if (!$a_author_id) {
80 $post = new \ilBlogPosting($a_posting_id);
81 $a_author_id = $post->getAuthor();
82 }
83 return $this->user_id === $a_author_id;
84 }
85 return false;
86 }
87
88 protected function checkPermissionBool(string $perm): bool
89 {
90 if (!is_null($this->node_id)) {
91 return $this->access->checkAccess($perm, "", $this->node_id);
92 }
93 if ($this->owner === $this->user_id) {
94 return true;
95 }
96 return false;
97 }
98
99
103 public function canManage(): bool
104 {
105 return ($this->checkPermissionBool("redact") ||
106 $this->checkPermissionBool("write"));
107 }
108
109 public function canReadPosting(int $posting_id): bool
110 {
111 return ($this->mayContribute() ||
112 \ilBlogPosting::_lookupActive($posting_id, "blp"));
113 }
114
115 public function isActive(int $posting_id): bool
116 {
117 return (\ilBlogPosting::_lookupActive($posting_id, "blp"));
118 }
119
120}
mayEditPosting(int $a_posting_id, ?int $a_author_id=null)
__construct( $access_handler, ?int $node_id, int $id_type, int $user_id, int $owner)
canManage()
Check if user has admin access (approve, may edit & deactivate all postings)
New implementation of ilObjectGUI.
static _lookupActive(int $a_id, string $a_parent_type, bool $a_check_scheduled_activation=false, string $a_lang="-")
lookup activation status
$post
Definition: ltitoken.php:46
if(!file_exists('../ilias.ini.php'))