ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
class.ilObjBlog.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
24class ilObjBlog extends ilObject2
25{
26 public const NAV_MODE_LIST = 1;
27 public const NAV_MODE_MONTH = 2;
29 public const ABSTRACT_DEFAULT_IMAGE_WIDTH = 144;
32 protected \ILIAS\Blog\Posting\PostingManager $posting_manager;
33 protected ?Settings $blog_settings = null;
35 protected \ILIAS\Style\Content\DomainService $content_style_domain;
36 protected \ILIAS\Notes\Service $notes_service;
37
38 protected bool $notes = false;
39 protected bool $style = false;
40
41 public function __construct(
42 int $a_id = 0,
43 bool $a_reference = true
44 ) {
45 global $DIC;
46
47 $service = $DIC->blog()->internal();
48 $this->notes_service = $DIC->notes();
49 $this->settings_manager = $service->domain()->blogSettings();
50
51 parent::__construct($a_id, $a_reference);
52 $this->rbac_review = $DIC->rbac()->review();
53
54 $this->content_style_domain = $DIC
55 ->contentStyle()
56 ->domain();
57
58 if ($this->getId() > 0) {
59 $this->blog_settings = $this->settings_manager->getByObjId($this->getId());
60 }
61 $this->posting_manager = $service->domain()->posting();
62 }
63
64 protected function initType(): void
65 {
66 $this->type = "blog";
67 }
68
69 protected function doRead(): void
70 {
71 // #14661
72 $this->setNotesStatus(
73 $this->notes_service->domain()->commentsActive($this->id)
74 );
75 $this->blog_settings = $this->settings_manager->getByObjId($this->getId());
76 }
77
78 protected function doCreate(bool $clone_mode = false): void
79 {
81
82 $this->createMetaData();
83
84 $ilDB->manipulate("INSERT INTO il_blog (id,ppic,rss_active,approval" .
85 ",abs_shorten,abs_shorten_len,abs_image,abs_img_width,abs_img_height" .
86 ",keywords,authors,nav_mode,nav_list_mon_with_post,ov_post,nav_list_mon) VALUES (" .
87 $ilDB->quote($this->id, "integer") . "," .
88 $ilDB->quote(true, "integer") . "," .
89 $ilDB->quote(true, "integer") . "," .
90 $ilDB->quote(false, "integer") . "," .
91 $ilDB->quote(false, "integer") . "," .
92 $ilDB->quote(0, "integer") . "," .
93 $ilDB->quote(false, "integer") . "," .
94 $ilDB->quote(0, "integer") . "," .
95 $ilDB->quote(0, "integer") . "," .
96 $ilDB->quote(true, "integer") . "," .
97 $ilDB->quote(false, "integer") . "," .
98 $ilDB->quote(self::NAV_MODE_LIST, "integer") . "," .
99 $ilDB->quote(5, "integer") . "," .
100 $ilDB->quote(5, "integer") . "," .
101 $ilDB->quote(5, "integer") .
102 ")");
103
104 // #14661
105 $this->notes_service->domain()->activateComments($this->id);
106 }
107
108 protected function doDelete(): void
109 {
111
112 $this->deleteMetaData();
113
114 $this->posting_manager->deleteAllByBlog($this->id);
115
116 // remove all notifications
118
119 $ilDB->manipulate("DELETE FROM il_blog" .
120 " WHERE id = " . $ilDB->quote($this->id, "integer"));
121 }
122
123 protected function doUpdate(): void
124 {
125 $this->updateMetaData();
126
127 if ($this->id) {
128 // #14661
129 $this->notes_service->domain()->activateComments(
130 $this->id,
131 $this->getNotesStatus()
132 );
133 }
134 }
135
136 protected function doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id = null): void
137 {
138 assert($new_obj instanceof ilObjBlog);
139
140 $new_obj->setNotesStatus($this->getNotesStatus());
141 $new_obj->update();
142
143 $this->settings_manager->clone($this->getId(), $new_obj->getId());
144
145 // set/copy stylesheet
146 $this->content_style_domain->styleForObjId($this->getId())->cloneTo($new_obj->getId());
147
148 $this->cloneMetaData($new_obj);
149 }
150
151 public function getNotesStatus(): bool
152 {
153 return $this->notes;
154 }
155
156 public function setNotesStatus(bool $a_status): void
157 {
158 $this->notes = $a_status;
159 }
160
161 public function initDefaultRoles(): void
162 {
164 'il_blog_contributor_' . $this->getRefId(),
165 "Contributor of blog obj_no." . $this->getId(),
166 'il_blog_contributor',
167 $this->getRefId()
168 );
169
171 'il_blog_editor_' . $this->getRefId(),
172 "Editor of blog obj_no." . $this->getId(),
173 'il_blog_editor',
174 $this->getRefId()
175 );
176 }
177
178 public function getLocalContributorRole(int $a_node_id): int
179 {
180 foreach ($this->rbac_review->getLocalRoles($a_node_id) as $role_id) {
181 if (str_starts_with(ilObject::_lookupTitle($role_id), "il_blog_contributor")) {
182 return $role_id;
183 }
184 }
185 return 0;
186 }
187
188 public function getLocalEditorRole(int $a_node_id): int
189 {
190 foreach ($this->rbac_review->getLocalRoles($a_node_id) as $role_id) {
191 if (strpos(ilObject::_lookupTitle($role_id), "il_blog_editor") === 0) {
192 return $role_id;
193 }
194 }
195 return 0;
196 }
197
198 public function getAllLocalRoles(int $a_node_id): array
199 {
200 $res = array();
201 foreach ($this->rbac_review->getLocalRoles($a_node_id) as $role_id) {
203 }
204
205 asort($res);
206 return $res;
207 }
208
209 public function getRolesWithContributeOrRedact(int $a_node_id): array
210 {
211 $contr_op_id = ilRbacReview::_getOperationIdByName("contribute");
212 $redact_op_id = ilRbacReview::_getOperationIdByName("redact");
213 $contr_role_id = $this->getLocalContributorRole($a_node_id);
214 $editor_role_id = $this->getLocalEditorRole($a_node_id);
215
216 $res = array();
217 foreach ($this->rbac_review->getParentRoleIds($a_node_id) as $role_id => $role) {
218 if ($role_id != $contr_role_id &&
219 $role_id != $editor_role_id) {
220 $all_ops = $this->rbac_review->getActiveOperationsOfRole($a_node_id, $role_id);
221 if (in_array($contr_op_id, $all_ops) ||
222 in_array($redact_op_id, $all_ops)) {
223 $res[$role_id] = ilObjRole::_getTranslation($role["title"]);
224 }
225 }
226 }
227
228 return $res;
229 }
230}
static removeForObject(int $type, int $id)
Remove all notifications for given object.
getRolesWithContributeOrRedact(int $a_node_id)
Settings $blog_settings
getLocalEditorRole(int $a_node_id)
getAllLocalRoles(int $a_node_id)
SettingsManager $settings_manager
ILIAS Blog Posting PostingManager $posting_manager
setNotesStatus(bool $a_status)
doCloneObject(ilObject2 $new_obj, int $a_target_id, ?int $a_copy_id=null)
const NAV_MODE_MONTH
ILIAS Style Content DomainService $content_style_domain
__construct(int $a_id=0, bool $a_reference=true)
Constructor.
doCreate(bool $clone_mode=false)
const NAV_MODE_LIST
initDefaultRoles()
init default roles settings Purpose of this function is to create a local role folder and local roles...
getLocalContributorRole(int $a_node_id)
const ABSTRACT_DEFAULT_SHORTEN_LENGTH
const ABSTRACT_DEFAULT_IMAGE_WIDTH
const NAV_MODE_LIST_DEFAULT_POSTINGS
ILIAS Notes Service $notes_service
const ABSTRACT_DEFAULT_IMAGE_HEIGHT
static createDefaultRole(string $a_title, string $a_description, string $a_tpl_name, int $a_ref_id)
static _getTranslation(string $a_role_title)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
cloneMetaData(ilObject $target_obj)
Copy meta data.
static _lookupTitle(int $obj_id)
ilDBInterface $db
static _getOperationIdByName(string $a_operation)
get operation id by name of operation
$service
Definition: ltiresult.php:44
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
foreach($_POST as $key=> $value) $res
global $DIC
Definition: shib_login.php:26