ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
class.ilPortfolioPage.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 include_once("./Services/COPage/classes/class.ilPageObject.php");
5 include_once("./Modules/Portfolio/classes/class.ilObjPortfolio.php");
6 
16 {
17  protected $portfolio_id;
18  protected $type = 1;
19  protected $title;
20  protected $order_nr;
21 
22  const TYPE_PAGE = 1;
23  const TYPE_BLOG = 2;
24 
30  function getParentType()
31  {
32  return "prtf";
33  }
34 
40  function setPortfolioId($a_val)
41  {
42  $this->portfolio_id = $a_val;
43  }
44 
50  function getPortfolioId()
51  {
52  return $this->portfolio_id;
53  }
54 
60  function setType($a_val)
61  {
62  $this->type = $a_val;
63  }
64 
70  function getType()
71  {
72  return $this->type;
73  }
74 
80  function setTitle($a_title)
81  {
82  $this->title = $a_title;
83  }
84 
90  function getTitle()
91  {
92  global $lng;
93 
94  // because of migration of extended user profiles
95  if($this->title == "###-")
96  {
97  return $lng->txt("profile");
98  }
99 
100  return $this->title;
101  }
102 
108  function setOrderNr($a_val)
109  {
110  $this->order_nr = (int)$a_val;
111  }
112 
118  function getOrderNr()
119  {
120  return $this->order_nr;
121  }
122 
129  static function lookupMaxOrderNr($a_portfolio_id)
130  {
131  global $ilDB;
132 
133  $set = $ilDB->query("SELECT MAX(order_nr) m FROM usr_portfolio_page".
134  " WHERE portfolio_id = ".$ilDB->quote($a_portfolio_id, "integer"));
135  $rec = $ilDB->fetchAssoc($set);
136  return (int) $rec["m"];
137  }
138 
144  protected function getPropertiesForDB()
145  {
146  $fields = array("portfolio_id" => array("integer", $this->portfolio_id),
147  "type" => array("integer", $this->getType()),
148  "title" => array("text", $this->getTitle()),
149  "order_nr" => array("integer", $this->getOrderNr()));
150 
151  return $fields;
152  }
153 
157  function create($a_import = false)
158  {
159  global $ilDB;
160 
161  if(!$a_import)
162  {
163  $this->setOrderNr(self::lookupMaxOrderNr($this->portfolio_id) + 10);
164  }
165 
166  $id = $ilDB->nextId("usr_portfolio_page");
167  $this->setId($id);
168 
169  $fields = $this->getPropertiesForDB();
170  $fields["id"] = array("integer", $id);
171 
172  $ilDB->insert("usr_portfolio_page", $fields);
173 
174  if(!$a_import)
175  {
176  parent::create();
177  // $this->saveInternalLinks($this->getDomDoc());
178  }
179  }
180 
186  function update($a_validate = true, $a_no_history = false)
187  {
188  global $ilDB;
189 
190  $id = $this->getId();
191  if($id)
192  {
193  $fields = $this->getPropertiesForDB();
194  $ilDB->update("usr_portfolio_page", $fields,
195  array("id"=>array("integer", $id)));
196 
197  parent::update($a_validate, $a_no_history);
198  return true;
199  }
200  return false;
201  }
202 
206  function read()
207  {
208  global $ilDB;
209 
210  $query = "SELECT * FROM usr_portfolio_page".
211  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
212  $set = $ilDB->query($query);
213  $rec = $ilDB->fetchAssoc($set);
214 
215  $this->setPortfolioId($rec["portfolio_id"]);
216  $this->setType($rec["type"]);
217  $this->setTitle($rec["title"]);
218  $this->setOrderNr($rec["order_nr"]);
219 
220  // get co page
221  parent::read();
222  }
223 
227  function delete()
228  {
229  global $ilDB;
230 
231  $id = $this->getId();
232  if($id)
233  {
234  // delete internal links information to this page
235  include_once("./Services/Link/classes/class.ilInternalLink.php");
237 
238  // delete record of table usr_portfolio_page
239  $query = "DELETE FROM usr_portfolio_page".
240  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
241  $ilDB->manipulate($query);
242 
243  // delete co page
244  parent::delete();
245  }
246  }
247 
255  protected static function lookupProperty($a_id, $a_prop)
256  {
257  global $ilDB;
258 
259  $set = $ilDB->query("SELECT ".$a_prop.
260  " FROM usr_portfolio_page".
261  " WHERE id = ".$ilDB->quote($a_id, "integer"));
262  $rec = $ilDB->fetchAssoc($set);
263  return $rec[$a_prop];
264  }
265 
271  static function lookupTitle($a_page_id)
272  {
273  return self::lookupProperty($a_page_id, "title");
274  }
275 
282  static function getAllPages($a_portfolio_id)
283  {
284  global $ilDB, $lng;
285 
286  $set = $ilDB->query("SELECT * FROM usr_portfolio_page".
287  " WHERE portfolio_id = ".$ilDB->quote($a_portfolio_id, "integer").
288  " ORDER BY order_nr");
289  $pages = array();
290  while ($rec = $ilDB->fetchAssoc($set))
291  {
292  // because of migration of extended user profiles
293  if($rec["title"] == "###-")
294  {
295  $rec["title"] = $lng->txt("profile");
296  }
297 
298  $pages[] = $rec;
299  }
300  return $pages;
301  }
302 
308  public static function fixOrdering($a_portfolio_id)
309  {
310  global $ilDB;
311 
312  $pages = self::getAllPages($a_portfolio_id);
313  $cnt = 10;
314  foreach ($pages as $p)
315  {
316  $ilDB->manipulate("UPDATE usr_portfolio_page SET ".
317  " order_nr = ".$ilDB->quote($cnt, "integer").
318  " WHERE id = ".$ilDB->quote($p["id"], "integer")
319  );
320  $cnt+= 10;
321  }
322  }
323 
330  public static function findPortfolioForPage($a_page_id)
331  {
332  return self::lookupProperty($a_page_id, "portfolio_id");
333  }
334 }
335 ?>
static lookupProperty($a_id, $a_prop)
Lookup portfolio page property.
setTitle($a_title)
Set Title.
setPortfolioId($a_val)
Set portfolio id.
getPropertiesForDB()
Get properties for insert/update statements.
read()
Read page data.
static findPortfolioForPage($a_page_id)
Get portfolio id of page id.
create($a_import=false)
Create new portfolio page.
static fixOrdering($a_portfolio_id)
Fix ordering.
getParentType()
Get parent type.
getOrderNr()
Get order nr.
static lookupTitle($a_page_id)
Lookup title.
update($a_validate=true, $a_no_history=false)
Update page.
Class ilPageObject.
Page for user portfolio.
setId($a_id)
set id
static lookupMaxOrderNr($a_portfolio_id)
Lookup max order nr for portfolio.
static getAllPages($a_portfolio_id)
Get pages of portfolio.
getPortfolioId()
Get portfolio id.
global $lng
Definition: privfeed.php:40
global $ilDB
setOrderNr($a_val)
Set order nr.
setType($a_val)
Set type.