ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
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 
4 require_once "Modules/Portfolio/classes/class.ilObjPortfolioBase.php";
5 
15 {
16  protected $default; // [bool]
17 
18  function initType()
19  {
20  $this->type = "prtf";
21  }
22 
23  //
24  // PROPERTIES
25  //
26 
32  function setDefault($a_value)
33  {
34  $this->default = (bool)$a_value;
35  }
36 
42  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  {
62  $this->setDefault(false);
63  }
64 
65  parent::doUpdate();
66  }
67 
68  protected function doUpdateCustom(array &$a_fields)
69  {
70  $a_fields["is_default"] = array("integer", $this->isDefault());
71  }
72 
73  protected function deleteAllPages()
74  {
75  // delete pages
76  include_once "Modules/Portfolio/classes/class.ilPortfolioPage.php";
77  $pages = ilPortfolioPage::getAllPages($this->id);
78  foreach($pages as $page)
79  {
80  $page_obj = new ilPortfolioPage($page["id"]);
81  $page_obj->setPortfolioId($this->id);
82  $page_obj->delete();
83  }
84  }
85 
86 
87  //
88  // HELPER
89  //
90 
97  public static function setUserDefault($a_user_id, $a_portfolio_id = null)
98  {
99  global $ilDB;
100 
101  $all = array();
102  foreach(self::getPortfoliosOfUser($a_user_id) as $item)
103  {
104  $all[] = $item["id"];
105  }
106  if($all)
107  {
108  $ilDB->manipulate("UPDATE usr_portfolio".
109  " SET is_default = ".$ilDB->quote(false, "integer").
110  " WHERE ".$ilDB->in("id", $all, "", "integer"));
111  }
112 
113  if($a_portfolio_id)
114  {
115  $ilDB->manipulate("UPDATE usr_portfolio".
116  " SET is_default = ".$ilDB->quote(true, "integer").
117  " WHERE id = ".$ilDB->quote($a_portfolio_id, "integer"));
118  }
119  }
120 
127  static function getPortfoliosOfUser($a_user_id)
128  {
129  global $ilDB;
130 
131  $set = $ilDB->query("SELECT up.*,od.title,od.description".
132  " FROM usr_portfolio up".
133  " JOIN object_data od ON (up.id = od.obj_id)".
134  " WHERE od.owner = ".$ilDB->quote($a_user_id, "integer").
135  " AND od.type = ".$ilDB->quote("prtf", "text").
136  " ORDER BY od.title");
137  $res = array();
138  while ($rec = $ilDB->fetchAssoc($set))
139  {
140  $res[] = $rec;
141  }
142  return $res;
143  }
144 
151  static function getDefaultPortfolio($a_user_id)
152  {
153  global $ilDB, $ilSetting;
154 
155  if(!$ilSetting->get('user_portfolios'))
156  {
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  {
167  return $res["id"];
168  }
169  }
170 
176  public static function deleteUserPortfolios($a_user_id)
177  {
178  $all = self::getPortfoliosOfUser($a_user_id);
179  if($all)
180  {
181  include_once "Modules/Portfolio/classes/class.ilPortfolioAccessHandler.php";
182  $access_handler = new ilPortfolioAccessHandler();
183 
184  foreach($all as $item)
185  {
186  $access_handler->removePermission($item["id"]);
187 
188  $portfolio = new self($item["id"], false);
189  $portfolio->delete();
190  }
191  }
192  }
193 
194  public function deleteImage()
195  {
196  if($this->id)
197  {
198  parent::deleteImage();
199  $this->handleQuotaUpdate();
200  }
201  }
202 
203  function uploadImage(array $a_upload)
204  {
205  if(parent::uploadImage($a_upload))
206  {
207  $this->handleQuotaUpdate();
208  return true;
209  }
210  return false;
211  }
212 
213  protected function handleQuotaUpdate()
214  {
215  include_once "Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
217  $this->getId(),
218  ilUtil::dirsize($this->initStorage($this->getId())),
219  array($this->getId()),
220  true);
221  }
222 
223  public static function getAvailablePortfolioLinksForUserIds(array $a_owner_ids, $a_back_url = null)
224  {
225  $res = array();
226 
227  include_once "Modules/Portfolio/classes/class.ilPortfolioAccessHandler.php";
228  $access_handler = new ilPortfolioAccessHandler();
229 
230  $params = null;
231  if($a_back_url)
232  {
233  $params = array("back_url"=>rawurlencode($a_back_url));
234  }
235 
236  include_once "Services/Link/classes/class.ilLink.php";
237  foreach($access_handler->getShardObjectsDataForUserIds($a_owner_ids) as $owner_id => $items)
238  {
239  foreach($items as $id => $title)
240  {
241  $url = ilLink::_getLink($id, 'prtf', $params);
242  $res[$owner_id][$url] = $title;
243  }
244  }
245 
246  return $res;
247  }
248 }
249 
250 ?>
setDefault($a_value)
Set default.
doReadCustom(array $a_row)
uploadImage(array $a_upload)
doUpdateCustom(array &$a_fields)
static getPortfoliosOfUser($a_user_id)
Get views of user.
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.
Page for user portfolio.
static getAvailablePortfolioLinksForUserIds(array $a_owner_ids, $a_back_url=null)
isDefault()
Is default?
static dirsize($directory)
get size of a directory or a file.
static getAllPages($a_portfolio_id)
Get pages of portfolio.
global $ilSetting
Definition: privfeed.php:40
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.
global $ilDB
Access handler for portfolio.
static getDefaultPortfolio($a_user_id)
Get default portfolio of user.
static deleteUserPortfolios($a_user_id)
Delete all portfolio data for user.