ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.NewsAccess.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24{
25 protected int $current_user_id;
26 protected \ilAccessHandler $access;
27 protected int $ref_id;
28
29 public function __construct(int $ref_id)
30 {
31 global $DIC;
32
33 $this->current_user_id = $DIC->user()->getId();
34 $this->ref_id = $ref_id;
35 $this->access = $DIC->access();
36 }
37
38 protected function getUserId(int $user_id = 0): int
39 {
40 return ($user_id > 0)
41 ? $user_id
43 }
44
45 public function canAdd($user_id = 0): bool
46 {
47 return $this->access->checkAccessOfUser(
48 $this->getUserId($user_id),
49 "news_add_news",
50 "",
51 $this->ref_id
52 )
53 || $this->canEditAll($user_id);
54 }
55
59 public function canAccessManageOverview($user_id = 0): bool
60 {
61 return $this->canAdd($user_id);
62 }
63
64 public function canEditSettings($user_id = 0): bool
65 {
66 return $this->access->checkAccessOfUser(
67 $this->getUserId($user_id),
68 'write',
69 '',
70 $this->ref_id
71 );
72 }
73
74 public function canEditAll($user_id = 0): bool
75 {
76 return $this->access->checkAccessOfUser(
77 $this->getUserId($user_id),
78 'write',
79 '',
80 $this->ref_id
81 );
82 }
83
84 public function canEdit(\ilNewsItem $i, $user_id = 0): bool
85 {
86 return (
87 $i->getPriority() === 1 &&
88 ($i->getUserId() === $this->getUserId($user_id) || $this->canEditAll($user_id))
89 );
90 }
91
92 public function canDelete(\ilNewsItem $i, $user_id = 0): bool
93 {
94 return $this->canEdit($i, $user_id);
95 }
96}
canDelete(\ilNewsItem $i, $user_id=0)
canEdit(\ilNewsItem $i, $user_id=0)
canAccessManageOverview($user_id=0)
List of news of the news block.
A news item can be created by different sources.
global $DIC
Definition: shib_login.php:26