ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  public function getParentType()
31  {
32  return "prtf";
33  }
34 
40  public function setPortfolioId($a_val)
41  {
42  $this->portfolio_id = $a_val;
43  }
44 
50  public function getPortfolioId()
51  {
52  return $this->portfolio_id;
53  }
54 
60  public function setType($a_val)
61  {
62  $this->type = $a_val;
63  }
64 
70  public function getType()
71  {
72  return $this->type;
73  }
74 
80  public function setTitle($a_title)
81  {
82  $this->title = $a_title;
83  }
84 
90  public function getTitle()
91  {
92  $lng = $this->lng;
93 
94  // because of migration of extended user profiles
95  if ($this->title == "###-") {
96  return $lng->txt("profile");
97  }
98 
99  return $this->title;
100  }
101 
107  public function setOrderNr($a_val)
108  {
109  $this->order_nr = (int) $a_val;
110  }
111 
117  public function getOrderNr()
118  {
119  return $this->order_nr;
120  }
121 
128  public static function lookupMaxOrderNr($a_portfolio_id)
129  {
130  global $DIC;
131 
132  $ilDB = $DIC->database();
133 
134  $set = $ilDB->query("SELECT MAX(order_nr) m FROM usr_portfolio_page" .
135  " WHERE portfolio_id = " . $ilDB->quote($a_portfolio_id, "integer"));
136  $rec = $ilDB->fetchAssoc($set);
137  return (int) $rec["m"];
138  }
139 
145  protected function getPropertiesForDB()
146  {
147  $fields = array("portfolio_id" => array("integer", $this->portfolio_id),
148  "type" => array("integer", $this->getType()),
149  "title" => array("text", $this->getTitle()),
150  "order_nr" => array("integer", $this->getOrderNr()));
151 
152  return $fields;
153  }
154 
158  public function create($a_import = false)
159  {
160  $ilDB = $this->db;
161 
162  if (!$a_import) {
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  parent::create();
176  // $this->saveInternalLinks($this->getDomDoc());
177  }
178  }
179 
185  public function update($a_validate = true, $a_no_history = false)
186  {
187  $ilDB = $this->db;
188 
189  $id = $this->getId();
190  if ($id) {
191  $fields = $this->getPropertiesForDB();
192  $ilDB->update(
193  "usr_portfolio_page",
194  $fields,
195  array("id" => array("integer", $id))
196  );
197 
198  parent::update($a_validate, $a_no_history);
199  return true;
200  }
201  return false;
202  }
203 
207  public function read()
208  {
209  $ilDB = $this->db;
210 
211  $query = "SELECT * FROM usr_portfolio_page" .
212  " WHERE id = " . $ilDB->quote($this->getId(), "integer");
213  $set = $ilDB->query($query);
214  $rec = $ilDB->fetchAssoc($set);
215 
216  $this->setPortfolioId($rec["portfolio_id"]);
217  $this->setType($rec["type"]);
218  $this->setTitle($rec["title"]);
219  $this->setOrderNr($rec["order_nr"]);
220 
221  // get co page
222  parent::read();
223  }
224 
228  public function delete()
229  {
230  $ilDB = $this->db;
231 
232  $id = $this->getId();
233  if ($id) {
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 $DIC;
258 
259  $ilDB = $DIC->database();
260 
261  $set = $ilDB->query("SELECT " . $a_prop .
262  " FROM usr_portfolio_page" .
263  " WHERE id = " . $ilDB->quote($a_id, "integer"));
264  $rec = $ilDB->fetchAssoc($set);
265  return $rec[$a_prop];
266  }
267 
273  public static function lookupTitle($a_page_id)
274  {
275  return self::lookupProperty($a_page_id, "title");
276  }
277 
284  public static function getAllPortfolioPages($a_portfolio_id)
285  {
286  global $DIC;
287 
288  $ilDB = $DIC->database();
289  $lng = $DIC->language();
290 
291  $set = $ilDB->query("SELECT * FROM usr_portfolio_page" .
292  " WHERE portfolio_id = " . $ilDB->quote($a_portfolio_id, "integer") .
293  " ORDER BY order_nr");
294  $pages = array();
295  while ($rec = $ilDB->fetchAssoc($set)) {
296  // because of migration of extended user profiles
297  if ($rec["title"] == "###-") {
298  $rec["title"] = $lng->txt("profile");
299  }
300 
301  $pages[] = $rec;
302  }
303  return $pages;
304  }
305 
311  public static function fixOrdering($a_portfolio_id)
312  {
313  global $DIC;
314 
315  $ilDB = $DIC->database();
316 
317  $pages = self::getAllPortfolioPages($a_portfolio_id);
318  $cnt = 10;
319  foreach ($pages as $p) {
320  $ilDB->manipulate(
321  "UPDATE usr_portfolio_page SET " .
322  " order_nr = " . $ilDB->quote($cnt, "integer") .
323  " WHERE id = " . $ilDB->quote($p["id"], "integer")
324  );
325  $cnt += 10;
326  }
327  }
328 
335  public static function findPortfolioForPage($a_page_id)
336  {
337  return self::lookupProperty($a_page_id, "portfolio_id");
338  }
339 
346  public static function getGotoForPortfolioPageTarget($a_target, $a_offline = false)
347  {
348  global $DIC;
349 
350  $pid = self::findPortfolioForPage((int) $a_target);
352  if ($type == "prtt") {
353  $ctrl = $DIC->ctrl();
354  $ctrl->setParameterByClass("ilobjportfoliotemplategui", "user_page", $a_target);
355  $href = $ctrl->getLinkTargetByClass(array("ilRepositoryGUI", "ilObjPortfolioTemplateGUI", "ilobjportfoliotemplategui"), "preview");
356  } else {
357  if (!$a_offline) {
358  $href = "./goto.php?client_id=" . CLIENT_ID . "&amp;target=prtf_" . $pid . "_" . $a_target;
359  } else {
360  $href = "prtf_" . $a_target . ".html";
361  }
362  }
363  return $href;
364  }
365 
369  public static function updateInternalLinks($a_copied_nodes, ilObjPortfolioBase $a_target_obj)
370  {
371  // var_dump($a_copied_nodes);
372  $all_fixes = array();
373  foreach ($a_copied_nodes as $original_id => $copied_id) {
374  $pid = self::findPortfolioForPage((int) $copied_id);
375 
376  //
377  // 1. Outgoing links from the copied page.
378  //
379  //$targets = ilInternalLink::_getTargetsOfSource($a_parent_type.":pg", $copied_id);
380  if ($a_target_obj->getType() == "prtf") {
381  $tpg = new ilPortfolioPage($copied_id);
382  }
383  if ($a_target_obj->getType() == "prtt") {
384  $tpg = new ilPortfolioTemplatePage($copied_id);
385  }
386  $tpg->buildDom();
387  $il = $tpg->getInternalLinks();
388  // var_dump($il);
389  $targets = array();
390  foreach ($il as $l) {
391  $targets[] = array("type" => ilInternalLink::_extractTypeOfTarget($l["Target"]),
392  "id" => (int) ilInternalLink::_extractObjIdOfTarget($l["Target"]),
393  "inst" => (int) ilInternalLink::_extractInstOfTarget($l["Target"]));
394  }
395  $fix = array();
396  foreach ($targets as $target) {
397  if (($target["inst"] == 0 || $target["inst"] = IL_INST_ID) &&
398  ($target["type"] == "ppage")) {
399  // first check, whether target is also within the copied set
400  if ($a_copied_nodes[$target["id"]] > 0) {
401  $fix[$target["id"]] = $a_copied_nodes[$target["id"]];
402  }
403  }
404  }
405  // var_dump($fix);
406  // outgoing links to be fixed
407  if (count($fix) > 0) {
408  $t = ilObject::_lookupType($pid);
409  if (is_array($all_fixes[$t . ":" . $copied_id])) {
410  $all_fixes[$t . ":" . $copied_id] += $fix;
411  } else {
412  $all_fixes[$t . ":" . $copied_id] = $fix;
413  }
414  }
415  }
416  // var_dump($all_fixes);
417  foreach ($all_fixes as $pg => $fixes) {
418  $pg = explode(":", $pg);
419  include_once("./Services/COPage/classes/class.ilPageObjectFactory.php");
420  $page = ilPageObjectFactory::getInstance($pg[0], $pg[1]);
421  if ($page->moveIntLinks($fixes)) {
422  $page->update(true, true);
423  }
424  }
425  }
426 
427 
431  public function renameLinksOnTitleChange($a_title_changes)
432  {
433  $this->buildDom();
434 
435  $changed = false;
436 
437  // resolve normal internal links
438  $xpc = xpath_new_context($this->dom);
439  $path = "//IntLink";
440  $res = xpath_eval($xpc, $path);
441  for ($i = 0; $i < count($res->nodeset); $i++) {
442  $target = $res->nodeset[$i]->get_attribute("Target");
443  $type = $res->nodeset[$i]->get_attribute("Type");
445  if (isset($a_title_changes[$obj_id]) && is_int(strpos($target, "__"))) {
446  if ($type == "PortfolioPage") {
447  if ($res->nodeset[$i]->get_content() == $a_title_changes[$obj_id]["old"]) {
448  $res->nodeset[$i]->set_content($a_title_changes[$obj_id]["new"]);
449  $changed = true;
450  }
451  }
452  }
453  }
454  unset($xpc);
455 
456  return $changed;
457  }
458 
465  public static function getPagesForBlog($a_blog_id)
466  {
467  global $DIC;
468 
469  $ilDB = $DIC->database();
470 
471  $set = $ilDB->query("SELECT * FROM usr_portfolio_page" .
472  " WHERE title = " . $ilDB->quote($a_blog_id, "text") .
473  " AND type = " . $ilDB->quote(self::TYPE_BLOG, "integer"));
474  $pages = array();
475  while ($rec = $ilDB->fetchAssoc($set)) {
476  $pages[] = new ilPortfolioPage($rec["id"]);
477  }
478  return $pages;
479  }
480 }
static lookupProperty($a_id, $a_prop)
Lookup portfolio page property.
buildDom($a_force=false)
static getAllPortfolioPages($a_portfolio_id)
Get pages of portfolio.
$path
Definition: aliased.php:25
setTitle($a_title)
Set Title.
setPortfolioId($a_val)
Set portfolio id.
getPropertiesForDB()
Get properties for insert/update statements.
xpath_new_context($dom_document)
global $DIC
Definition: saml.php:7
read()
Read page data.
static getGotoForPortfolioPageTarget($a_target, $a_offline=false)
Get goto href for internal wiki page link target.
static findPortfolioForPage($a_page_id)
Get portfolio id of page id.
xpath_eval($xpath_context, $eval_str, $contextnode=null)
create($a_import=false)
Create new portfolio page.
static fixOrdering($a_portfolio_id)
Fix ordering.
getParentType()
Get parent type.
getOrderNr()
Get order nr.
static updateInternalLinks($a_copied_nodes, ilObjPortfolioBase $a_target_obj)
Update internal links, after multiple pages have been copied.
renameLinksOnTitleChange($a_title_changes)
static lookupTitle($a_page_id)
Lookup title.
foreach($_POST as $key=> $value) $res
update($a_validate=true, $a_no_history=false)
Update page.
Class ilPageObject.
Page for user portfolio.
Page for portfolio template.
$query
setId($a_id)
set id
static _lookupType($a_id, $a_reference=false)
lookup object type
static getPagesForBlog($a_blog_id)
Get portfolio pages for blog.
update($pash, $contents, Config $config)
static lookupMaxOrderNr($a_portfolio_id)
Lookup max order nr for portfolio.
static getInstance($a_parent_type, $a_id=0, $a_old_nr=0, $a_lang="-")
Get page object instance.
global $l
Definition: afr.php:30
getPortfolioId()
Get portfolio id.
global $ilDB
$i
Definition: disco.tpl.php:19
setOrderNr($a_val)
Set order nr.
$target
Definition: test.php:19
setType($a_val)
Set type.