ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilObjPortfolio.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
11{
12 protected $default; // [bool]
13
14 public function initType()
15 {
16 $this->type = "prtf";
17 }
18
19 //
20 // PROPERTIES
21 //
22
28 public function setDefault($a_value)
29 {
30 $this->default = (bool) $a_value;
31 }
32
38 public function isDefault()
39 {
40 return $this->default;
41 }
42
43
44 //
45 // CRUD
46 //
47
48 protected function doReadCustom(array $a_row)
49 {
50 $this->setDefault((bool) $a_row["is_default"]);
51 }
52
53 protected function doUpdate()
54 {
55 // must be online to be default
56 if (!$this->isOnline() && $this->isDefault()) {
57 $this->setDefault(false);
58 }
59
60 parent::doUpdate();
61 }
62
63 protected function doUpdateCustom(array &$a_fields)
64 {
65 $a_fields["is_default"] = array("integer", $this->isDefault());
66 }
67
68 protected function deleteAllPages()
69 {
70 // delete pages
71 $pages = ilPortfolioPage::getAllPortfolioPages($this->id);
72 foreach ($pages as $page) {
73 $page_obj = new ilPortfolioPage($page["id"]);
74 $page_obj->setPortfolioId($this->id);
75 $page_obj->delete();
76 }
77 }
78
79
80 //
81 // HELPER
82 //
83
90 public static function setUserDefault($a_user_id, $a_portfolio_id = null)
91 {
92 global $DIC;
93
94 $ilDB = $DIC->database();
95
96 $all = array();
97 foreach (self::getPortfoliosOfUser($a_user_id) as $item) {
98 $all[] = $item["id"];
99 }
100 if ($all) {
101 $ilDB->manipulate("UPDATE usr_portfolio" .
102 " SET is_default = " . $ilDB->quote(false, "integer") .
103 " WHERE " . $ilDB->in("id", $all, "", "integer"));
104 }
105
106 if ($a_portfolio_id) {
107 $ilDB->manipulate("UPDATE usr_portfolio" .
108 " SET is_default = " . $ilDB->quote(true, "integer") .
109 " WHERE id = " . $ilDB->quote($a_portfolio_id, "integer"));
110 }
111 }
112
119 public static function getPortfoliosOfUser($a_user_id)
120 {
121 global $DIC;
122
123 $ilDB = $DIC->database();
124
125 $set = $ilDB->query("SELECT up.*,od.title,od.description" .
126 " FROM usr_portfolio up" .
127 " JOIN object_data od ON (up.id = od.obj_id)" .
128 " WHERE od.owner = " . $ilDB->quote($a_user_id, "integer") .
129 " AND od.type = " . $ilDB->quote("prtf", "text") .
130 " ORDER BY od.title");
131 $res = array();
132 while ($rec = $ilDB->fetchAssoc($set)) {
133 $res[] = $rec;
134 }
135 return $res;
136 }
137
144 public static function getDefaultPortfolio($a_user_id)
145 {
146 global $DIC;
147
148 $ilDB = $DIC->database();
149 $ilSetting = $DIC->settings();
150
151 if (!$ilSetting->get('user_portfolios')) {
152 return;
153 }
154
155 $set = $ilDB->query("SELECT up.id FROM usr_portfolio up" .
156 " JOIN object_data od ON (up.id = od.obj_id)" .
157 " WHERE od.owner = " . $ilDB->quote($a_user_id, "integer") .
158 " AND up.is_default = " . $ilDB->quote(1, "integer"));
159 $res = $ilDB->fetchAssoc($set);
160 if ($res["id"]) {
161 return $res["id"];
162 }
163 }
164
170 public static function deleteUserPortfolios($a_user_id)
171 {
172 $all = self::getPortfoliosOfUser($a_user_id);
173 if ($all) {
174 $access_handler = new ilPortfolioAccessHandler();
175
176 foreach ($all as $item) {
177 $access_handler->removePermission($item["id"]);
178
179 $portfolio = new self($item["id"], false);
180 $portfolio->delete();
181 }
182 }
183 }
184
185 public function deleteImage()
186 {
187 if ($this->id) {
188 parent::deleteImage();
189 $this->handleQuotaUpdate();
190 }
191 }
192
193 public function uploadImage(array $a_upload)
194 {
195 if (parent::uploadImage($a_upload)) {
196 $this->handleQuotaUpdate();
197 return true;
198 }
199 return false;
200 }
201
202 protected function handleQuotaUpdate()
203 {
205 $this->getType(),
206 $this->getId(),
207 ilUtil::dirsize($this->initStorage($this->getId())),
208 array($this->getId()),
209 true
210 );
211 }
212
213 public static function getAvailablePortfolioLinksForUserIds(array $a_owner_ids, $a_back_url = null)
214 {
215 $res = array();
216
217 $access_handler = new ilPortfolioAccessHandler();
218
219 $params = null;
220 if ($a_back_url) {
221 $params = array("back_url" => rawurlencode($a_back_url));
222 }
223
224 foreach ($access_handler->getShardObjectsDataForUserIds($a_owner_ids) as $owner_id => $items) {
225 foreach ($items as $id => $title) {
226 $url = ilLink::_getLink($id, 'prtf', $params);
227 $res[$owner_id][$url] = $title;
228 }
229 }
230
231 return $res;
232 }
233}
An exception for terminatinating execution or to throw for unit testing.
static handleUpdatedSourceObject($a_src_obj_type, $a_src_obj_id, $a_src_filesize, $a_owner_obj_ids=null, $a_is_prtf=false)
Find and update/create all related entries for source object.
static initStorage($a_id, $a_subdir=null)
Init file system storage.
static setUserDefault($a_user_id, $a_portfolio_id=null)
Set the user default portfolio.
uploadImage(array $a_upload)
Upload new image file.
setDefault($a_value)
Set default.
static getDefaultPortfolio($a_user_id)
Get default portfolio of user.
doReadCustom(array $a_row)
static deleteUserPortfolios($a_user_id)
Delete all portfolio data for user.
static getPortfoliosOfUser($a_user_id)
Get views of user.
deleteImage()
remove existing file
static getAvailablePortfolioLinksForUserIds(array $a_owner_ids, $a_back_url=null)
doUpdateCustom(array &$a_fields)
isDefault()
Is default?
getType()
get object type @access public
getId()
get object id @access public
Access handler for portfolio.
Page for user portfolio.
static getAllPortfolioPages($a_portfolio_id)
Get pages of portfolio.
static dirsize($directory)
get size of a directory or a file.
global $ilSetting
Definition: privfeed.php:17
$url
foreach($_POST as $key=> $value) $res
global $ilDB
$DIC
Definition: xapitoken.php:46