ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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("./Services/Portfolio/classes/class.ilObjPortfolio.php");
6 
16 {
17  protected $portfolio_id;
18  protected $type;
19  protected $title;
20  protected $order_nr;
21 
22  const TYPE_PAGE = 1;
23  const TYPE_BLOG = 2;
24 
32  function __construct($a_portfolio_id, $a_id = 0, $a_old_nr = 0)
33  {
34  $this->portfolio_id = (int)$a_portfolio_id;
35  $this->type = self::TYPE_PAGE;
36 
37  parent::__construct("prtf", $a_id, $a_old_nr);
38  }
39 
45  function setType($a_val)
46  {
47  $this->type = $a_val;
48  }
49 
55  function getType()
56  {
57  return $this->type;
58  }
59 
65  function setTitle($a_title)
66  {
67  $this->title = $a_title;
68  }
69 
75  function getTitle()
76  {
77  global $lng;
78 
79  // because of migration of extended user profiles
80  if($this->title == "###-")
81  {
82  return $lng->txt("profile");
83  }
84 
85  return $this->title;
86  }
87 
93  function setOrderNr($a_val)
94  {
95  $this->order_nr = (int)$a_val;
96  }
97 
103  function getOrderNr()
104  {
105  return $this->order_nr;
106  }
107 
114  static function lookupMaxOrderNr($a_portfolio_id)
115  {
116  global $ilDB;
117 
118  $set = $ilDB->query("SELECT MAX(order_nr) m FROM usr_portfolio_page".
119  " WHERE portfolio_id = ".$ilDB->quote($a_portfolio_id, "integer"));
120  $rec = $ilDB->fetchAssoc($set);
121  return (int) $rec["m"];
122  }
123 
129  protected function getPropertiesForDB()
130  {
131  $fields = array("portfolio_id" => array("integer", $this->portfolio_id),
132  "type" => array("integer", $this->getType()),
133  "title" => array("text", $this->getTitle()),
134  "order_nr" => array("integer", $this->getOrderNr()));
135 
136  return $fields;
137  }
138 
142  function create()
143  {
144  global $ilDB;
145 
146  $this->setOrderNr(self::lookupMaxOrderNr($this->portfolio_id) + 10);
147 
148  $id = $ilDB->nextId("usr_portfolio_page");
149  $this->setId($id);
150 
151  $fields = $this->getPropertiesForDB();
152  $fields["id"] = array("integer", $id);
153 
154  $ilDB->insert("usr_portfolio_page", $fields);
155 
156  parent::create();
157  $this->saveInternalLinks($this->getXMLContent());
158  }
159 
165  function update($a_validate = true, $a_no_history = false)
166  {
167  global $ilDB;
168 
169  $id = $this->getId();
170  if($id)
171  {
172  $fields = $this->getPropertiesForDB();
173  $ilDB->update("usr_portfolio_page", $fields,
174  array("id"=>array("integer", $id)));
175 
176  parent::update($a_validate, $a_no_history);
177  return true;
178  }
179  return false;
180  }
181 
185  function read()
186  {
187  global $ilDB;
188 
189  $query = "SELECT * FROM usr_portfolio_page".
190  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
191  $set = $ilDB->query($query);
192  $rec = $ilDB->fetchAssoc($set);
193 
194  $this->setType($rec["type"]);
195  $this->setTitle($rec["title"]);
196  $this->setOrderNr($rec["order_nr"]);
197 
198  // get co page
199  parent::read();
200  }
201 
205  function delete()
206  {
207  global $ilDB;
208 
209  $id = $this->getId();
210  if($id)
211  {
212  // delete internal links information to this page
213  include_once("./Services/COPage/classes/class.ilInternalLink.php");
215 
216  // delete record of table usr_portfolio_page
217  $query = "DELETE FROM usr_portfolio_page".
218  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
219  $ilDB->manipulate($query);
220 
221  // delete co page
222  parent::delete();
223  }
224  }
225 
233  protected static function lookupProperty($a_id, $a_prop)
234  {
235  global $ilDB;
236 
237  $set = $ilDB->query("SELECT ".$a_prop.
238  " FROM usr_portfolio_page".
239  " WHERE id = ".$ilDB->quote($a_id, "integer"));
240  $rec = $ilDB->fetchAssoc($set);
241  return $rec[$a_prop];
242  }
243 
249  static function lookupTitle($a_page_id)
250  {
251  return self::lookupProperty($a_page_id, "title");
252  }
253 
260  static function getAllPages($a_portfolio_id)
261  {
262  global $ilDB, $lng;
263 
264  $set = $ilDB->query("SELECT * FROM usr_portfolio_page".
265  " WHERE portfolio_id = ".$ilDB->quote($a_portfolio_id, "integer").
266  " ORDER BY order_nr");
267  $pages = array();
268  while ($rec = $ilDB->fetchAssoc($set))
269  {
270  // because of migration of extended user profiles
271  if($rec["title"] == "###-")
272  {
273  $rec["title"] = $lng->txt("profile");
274  }
275 
276  $pages[] = $rec;
277  }
278  return $pages;
279  }
280 
286  public static function fixOrdering($a_portfolio_id)
287  {
288  global $ilDB;
289 
290  $pages = self::getAllPages($a_portfolio_id);
291  $cnt = 10;
292  foreach ($pages as $p)
293  {
294  $ilDB->manipulate("UPDATE usr_portfolio_page SET ".
295  " order_nr = ".$ilDB->quote($cnt, "integer").
296  " WHERE id = ".$ilDB->quote($p["id"], "integer")
297  );
298  $cnt+= 10;
299  }
300  }
301 
308  public static function findPortfolioForPage($a_page_id)
309  {
310  return self::lookupProperty($a_page_id, "portfolio_id");
311  }
312 }
313 ?>