ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilObjPortfolio.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once "Modules/Portfolio/classes/class.ilObjPortfolioBase.php";
5
15{
16 protected $default; // [bool]
17
18 public function initType()
19 {
20 $this->type = "prtf";
21 }
22
23 //
24 // PROPERTIES
25 //
26
32 public function setDefault($a_value)
33 {
34 $this->default = (bool) $a_value;
35 }
36
42 public function isDefault()
43 {
44 return $this->default;
45 }
46
47
48 //
49 // CRUD
50 //
51
52 protected function doReadCustom(array $a_row)
53 {
54 $this->setDefault((bool) $a_row["is_default"]);
55 }
56
57 protected function doUpdate()
58 {
59 // must be online to be default
60 if (!$this->isOnline() && $this->isDefault()) {
61 $this->setDefault(false);
62 }
63
64 parent::doUpdate();
65 }
66
67 protected function doUpdateCustom(array &$a_fields)
68 {
69 $a_fields["is_default"] = array("integer", $this->isDefault());
70 }
71
72 protected function deleteAllPages()
73 {
74 // delete pages
75 include_once "Modules/Portfolio/classes/class.ilPortfolioPage.php";
76 $pages = ilPortfolioPage::getAllPortfolioPages($this->id);
77 foreach ($pages as $page) {
78 $page_obj = new ilPortfolioPage($page["id"]);
79 $page_obj->setPortfolioId($this->id);
80 $page_obj->delete();
81 }
82 }
83
84
85 //
86 // HELPER
87 //
88
95 public static function setUserDefault($a_user_id, $a_portfolio_id = null)
96 {
97 global $DIC;
98
99 $ilDB = $DIC->database();
100
101 $all = array();
102 foreach (self::getPortfoliosOfUser($a_user_id) as $item) {
103 $all[] = $item["id"];
104 }
105 if ($all) {
106 $ilDB->manipulate("UPDATE usr_portfolio" .
107 " SET is_default = " . $ilDB->quote(false, "integer") .
108 " WHERE " . $ilDB->in("id", $all, "", "integer"));
109 }
110
111 if ($a_portfolio_id) {
112 $ilDB->manipulate("UPDATE usr_portfolio" .
113 " SET is_default = " . $ilDB->quote(true, "integer") .
114 " WHERE id = " . $ilDB->quote($a_portfolio_id, "integer"));
115 }
116 }
117
124 public static function getPortfoliosOfUser($a_user_id)
125 {
126 global $DIC;
127
128 $ilDB = $DIC->database();
129
130 $set = $ilDB->query("SELECT up.*,od.title,od.description" .
131 " FROM usr_portfolio up" .
132 " JOIN object_data od ON (up.id = od.obj_id)" .
133 " WHERE od.owner = " . $ilDB->quote($a_user_id, "integer") .
134 " AND od.type = " . $ilDB->quote("prtf", "text") .
135 " ORDER BY od.title");
136 $res = array();
137 while ($rec = $ilDB->fetchAssoc($set)) {
138 $res[] = $rec;
139 }
140 return $res;
141 }
142
149 public static function getDefaultPortfolio($a_user_id)
150 {
151 global $DIC;
152
153 $ilDB = $DIC->database();
154 $ilSetting = $DIC->settings();
155
156 if (!$ilSetting->get('user_portfolios')) {
157 return;
158 }
159
160 $set = $ilDB->query("SELECT up.id FROM usr_portfolio up" .
161 " JOIN object_data od ON (up.id = od.obj_id)" .
162 " WHERE od.owner = " . $ilDB->quote($a_user_id, "integer") .
163 " AND up.is_default = " . $ilDB->quote(1, "integer"));
164 $res = $ilDB->fetchAssoc($set);
165 if ($res["id"]) {
166 return $res["id"];
167 }
168 }
169
175 public static function deleteUserPortfolios($a_user_id)
176 {
177 $all = self::getPortfoliosOfUser($a_user_id);
178 if ($all) {
179 include_once "Modules/Portfolio/classes/class.ilPortfolioAccessHandler.php";
180 $access_handler = new ilPortfolioAccessHandler();
181
182 foreach ($all as $item) {
183 $access_handler->removePermission($item["id"]);
184
185 $portfolio = new self($item["id"], false);
186 $portfolio->delete();
187 }
188 }
189 }
190
191 public function deleteImage()
192 {
193 if ($this->id) {
194 parent::deleteImage();
195 $this->handleQuotaUpdate();
196 }
197 }
198
199 public function uploadImage(array $a_upload)
200 {
201 if (parent::uploadImage($a_upload)) {
202 $this->handleQuotaUpdate();
203 return true;
204 }
205 return false;
206 }
207
208 protected function handleQuotaUpdate()
209 {
210 include_once "Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
212 $this->getType(),
213 $this->getId(),
214 ilUtil::dirsize($this->initStorage($this->getId())),
215 array($this->getId()),
216 true
217 );
218 }
219
220 public static function getAvailablePortfolioLinksForUserIds(array $a_owner_ids, $a_back_url = null)
221 {
222 $res = array();
223
224 include_once "Modules/Portfolio/classes/class.ilPortfolioAccessHandler.php";
225 $access_handler = new ilPortfolioAccessHandler();
226
227 $params = null;
228 if ($a_back_url) {
229 $params = array("back_url" => rawurlencode($a_back_url));
230 }
231
232 include_once "Services/Link/classes/class.ilLink.php";
233 foreach ($access_handler->getShardObjectsDataForUserIds($a_owner_ids) as $owner_id => $items) {
234 foreach ($items as $id => $title) {
235 $url = ilLink::_getLink($id, 'prtf', $params);
236 $res[$owner_id][$url] = $title;
237 }
238 }
239
240 return $res;
241 }
242}
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
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB