ILIAS  release_8 Revision v8.24
class.ilObjPortfolio.php
Go to the documentation of this file.
1<?php
2
24{
25 protected bool $default = false;
26
27 protected function initType(): void
28 {
29 $this->type = "prtf";
30 }
31
32 //
33 // PROPERTIES
34 //
35
36 public function setDefault(bool $a_value): void
37 {
38 $this->default = $a_value;
39 }
40
41 public function isDefault(): bool
42 {
43 return $this->default;
44 }
45
46
47 //
48 // CRUD
49 //
50
51 protected function doReadCustom(array $a_row): void
52 {
53 $this->setDefault((bool) $a_row["is_default"]);
54 }
55
56 protected function doUpdate(): void
57 {
58 // must be online to be default
59 if (!$this->isOnline() && $this->isDefault()) {
60 $this->setDefault(false);
61 }
62
63 parent::doUpdate();
64 }
65
66 protected function doUpdateCustom(array &$a_fields): void
67 {
68 $a_fields["is_default"] = array("integer", $this->isDefault());
69 }
70
71 protected function deleteAllPages(): void
72 {
73 // delete pages
74 $pages = ilPortfolioPage::getAllPortfolioPages($this->id);
75 foreach ($pages as $page) {
76 $page_obj = new ilPortfolioPage($page["id"]);
77 $page_obj->setPortfolioId($this->id);
78 $page_obj->delete();
79 }
80 }
81
82
83 //
84 // HELPER
85 //
86
90 public static function setUserDefault(
91 int $a_user_id,
92 ?int $a_portfolio_id = null
93 ): void {
94 global $DIC;
95
96 $ilDB = $DIC->database();
97
98 $all = array();
99 foreach (self::getPortfoliosOfUser($a_user_id) as $item) {
100 $all[] = $item["id"];
101 }
102 if ($all) {
103 $ilDB->manipulate("UPDATE usr_portfolio" .
104 " SET is_default = " . $ilDB->quote(false, "integer") .
105 " WHERE " . $ilDB->in("id", $all, "", "integer"));
106 }
107
108 if ($a_portfolio_id) {
109 $ilDB->manipulate("UPDATE usr_portfolio" .
110 " SET is_default = " . $ilDB->quote(true, "integer") .
111 " WHERE id = " . $ilDB->quote($a_portfolio_id, "integer"));
112 }
113 }
114
119 public static function getPortfoliosOfUser(
120 int $a_user_id
121 ): array {
122 global $DIC;
123
124 $ilDB = $DIC->database();
125
126 $set = $ilDB->query("SELECT up.*,od.title,od.description" .
127 " FROM usr_portfolio up" .
128 " JOIN object_data od ON (up.id = od.obj_id)" .
129 " WHERE od.owner = " . $ilDB->quote($a_user_id, "integer") .
130 " AND od.type = " . $ilDB->quote("prtf", "text") .
131 " ORDER BY od.title");
132 $res = array();
133 while ($rec = $ilDB->fetchAssoc($set)) {
134 $res[] = $rec;
135 }
136 return $res;
137 }
138
142 public static function getDefaultPortfolio(int $a_user_id): ?int
143 {
144 global $DIC;
145
146 $ilDB = $DIC->database();
147 $ilSetting = $DIC->settings();
148
149 if (!$ilSetting->get('user_portfolios')) {
150 return null;
151 }
152
153 $set = $ilDB->query("SELECT up.id FROM usr_portfolio up" .
154 " JOIN object_data od ON (up.id = od.obj_id)" .
155 " WHERE od.owner = " . $ilDB->quote($a_user_id, "integer") .
156 " AND up.is_default = " . $ilDB->quote(1, "integer"));
157 $res = $ilDB->fetchAssoc($set);
158 if ($res && $res["id"]) {
159 return (int) $res["id"];
160 }
161 return null;
162 }
163
167 public static function deleteUserPortfolios(int $a_user_id): void
168 {
169 $all = self::getPortfoliosOfUser($a_user_id);
170 if ($all) {
171 $access_handler = new ilPortfolioAccessHandler();
172
173 foreach ($all as $item) {
174 $access_handler->removePermission($item["id"]);
175
176 $portfolio = new self($item["id"], false);
177 $portfolio->delete();
178 }
179 }
180 }
181
182 public function deleteImage(): void
183 {
184 if ($this->id) {
185 parent::deleteImage();
186 $this->handleQuotaUpdate();
187 }
188 }
189
190 public function uploadImage(array $a_upload): bool
191 {
192 if (parent::uploadImage($a_upload)) {
193 $this->handleQuotaUpdate();
194 return true;
195 }
196 return false;
197 }
198
199 protected function handleQuotaUpdate(): void
200 {
201 }
202
204 array $a_owner_ids,
205 ?string $a_back_url = null
206 ): array {
207 $res = array();
208
209 $access_handler = new ilPortfolioAccessHandler();
210
211 $params = null;
212 if ($a_back_url) {
213 $params = array("back_url" => rawurlencode($a_back_url));
214 }
215
216 foreach ($access_handler->getShardObjectsDataForUserIds($a_owner_ids) as $owner_id => $items) {
217 foreach ($items as $id => $title) {
218 $url = ilLink::_getLink($id, 'prtf', $params);
219 $res[$owner_id][$url] = $title;
220 }
221 }
222
223 return $res;
224 }
225
229 public function isCommentsExportPossible(): bool
230 {
231 $setting = $this->setting;
233 if ($setting->get("disable_comments")) {
234 return false;
235 }
236 if (!$this->notes->domain()->commentsActive($this->id)) {
237 return false;
238 }
239 if (!$privacy->enabledCommentsExport()) {
240 return false;
241 }
242 return true;
243 }
244
245 public static function getAdvMDSubItemTitle(int $a_obj_id, string $a_sub_type, int $a_sub_id): string
246 {
247 return \ilPortfolioPage::lookupTitle($a_sub_id);
248 }
249}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getPortfoliosOfUser(int $a_user_id)
Get portfolios of user.
uploadImage(array $a_upload)
Upload new image file.
setDefault(bool $a_value)
isCommentsExportPossible()
Is export possible.
doReadCustom(array $a_row)
May be overwritten by derived classes.
static deleteUserPortfolios(int $a_user_id)
Delete all portfolio data for user.
static getDefaultPortfolio(int $a_user_id)
Get default portfolio of user.
deleteImage()
remove existing file
static getAvailablePortfolioLinksForUserIds(array $a_owner_ids, ?string $a_back_url=null)
static setUserDefault(int $a_user_id, ?int $a_portfolio_id=null)
Set the user default portfolio.
static getAdvMDSubItemTitle(int $a_obj_id, string $a_sub_type, int $a_sub_id)
doUpdateCustom(array &$a_fields)
May be overwritte by derived classes.
Access handler for portfolio NOTE: This file needs to stay in the classes directory,...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getAllPortfolioPages(int $a_portfolio_id)
Get pages of portfolio.
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
$res
Definition: ltiservices.php:69
global $ilSetting
Definition: privfeed.php:17
$url