ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjWiki.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
8 include_once "./Services/Object/classes/class.ilObject.php";
9 include_once ("./Modules/Wiki/classes/class.ilWikiUtil.php");
10 
19 class ilObjWiki extends ilObject
20 {
21  protected $online = false;
22  protected $public_notes = true;
23 
30  function ilObjWiki($a_id = 0,$a_call_by_reference = true)
31  {
32  $this->type = "wiki";
33  $this->ilObject($a_id,$a_call_by_reference);
34  }
35 
41  function setOnline($a_online)
42  {
43  $this->online = $a_online;
44  }
45 
51  function getOnline()
52  {
53  return $this->online;
54  }
55 
61  function setRatingOverall($a_rating)
62  {
63  $this->rating_overall = (bool)$a_rating;
64  }
65 
71  function getRatingOverall()
72  {
73  return $this->rating_overall;
74  }
75 
81  function setRating($a_rating)
82  {
83  $this->rating = (bool)$a_rating;
84  }
85 
91  function getRating()
92  {
93  return $this->rating;
94  }
95 
101  function setRatingAsBlock($a_rating)
102  {
103  $this->rating_block = (bool)$a_rating;
104  }
105 
111  function getRatingAsBlock()
112  {
113  return $this->rating_block;
114  }
115 
121  function setRatingForNewPages($a_rating)
122  {
123  $this->rating_new_pages = (bool)$a_rating;
124  }
125 
132  {
133  return $this->rating_new_pages;
134  }
135 
141  function setRatingCategories($a_rating)
142  {
143  $this->rating_categories = (bool)$a_rating;
144  }
145 
152  {
153  return $this->rating_categories;
154  }
155 
159  public function setPublicNotes($a_val)
160  {
161  $this->public_notes = $a_val;
162  }
163 
167  public function getPublicNotes()
168  {
169  return $this->public_notes;
170  }
171 
177  public function setImportantPages($a_val)
178  {
179  $this->imp_pages = $a_val;
180  }
181 
187  public function getImportantPages()
188  {
189  return $this->imp_pages;
190  }
191 
197  function setStartPage($a_startpage)
198  {
199  $this->startpage = ilWikiUtil::makeDbTitle($a_startpage);
200  }
201 
207  function getStartPage()
208  {
209  return $this->startpage;
210  }
211 
217  function setShortTitle($a_shorttitle)
218  {
219  $this->shorttitle = $a_shorttitle;
220  }
221 
227  function getShortTitle()
228  {
229  return $this->shorttitle;
230  }
231 
237  function setIntroduction($a_introduction)
238  {
239  $this->introduction = $a_introduction;
240  }
241 
247  function getIntroduction()
248  {
249  return $this->introduction;
250  }
251 
255  function getStyleSheetId()
256  {
257  return $this->style_id;
258  }
259 
263  function setStyleSheetId($a_style_id)
264  {
265  $this->style_id = $a_style_id;
266  }
267 
273  public function setPageToc($a_val)
274  {
275  $this->page_toc = $a_val;
276  }
277 
283  public function getPageToc()
284  {
285  return $this->page_toc;
286  }
287 
293  static function isOnlineHelpWiki($a_ref_id)
294  {
295  if ($a_ref_id > 0 && $a_ref_id == OH_REF_ID)
296  {
297 // return true;
298  }
299  return false;
300  }
301 
305  function create($a_prevent_start_page_creation = false)
306  {
307  global $ilDB;
308 
309  parent::create();
310 
311  $ilDB->insert("il_wiki_data", array(
312  "id" => array("integer", $this->getId()),
313  "is_online" => array("integer", (int) $this->getOnline()),
314  "startpage" => array("text", $this->getStartPage()),
315  "short" => array("text", $this->getShortTitle()),
316  "rating" => array("integer", (int) $this->getRating()),
317  "public_notes" => array("integer", (int) $this->getPublicNotes()),
318  "introduction" => array("clob", $this->getIntroduction())
319  ));
320 
321  // create start page
322  if ($this->getStartPage() != "" && !$a_prevent_start_page_creation)
323  {
324  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
325  $start_page = new ilWikiPage();
326  $start_page->setWikiId($this->getId());
327  $start_page->setTitle($this->getStartPage());
328  $start_page->create();
329  }
330 
331  if (((int) $this->getStyleSheetId()) > 0)
332  {
333  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
335  }
336  }
337 
344  function update($a_prevent_start_page_creation = false)
345  {
346  global $ilDB;
347 
348  if (!parent::update())
349  {
350  return false;
351  }
352 
353  $ilDB->update("il_wiki_data", array(
354  "is_online" => array("integer", $this->getOnline()),
355  "startpage" => array("text", $this->getStartPage()),
356  "short" => array("text", $this->getShortTitle()),
357  "rating_overall" => array("integer", $this->getRatingOverall()),
358  "rating" => array("integer", $this->getRating()),
359  "rating_side" => array("integer", (bool)$this->getRatingAsBlock()), // #13455
360  "rating_new" => array("integer", $this->getRatingForNewPages()),
361  "rating_ext" => array("integer", $this->getRatingCategories()),
362  "public_notes" => array("integer", $this->getPublicNotes()),
363  "introduction" => array("clob", $this->getIntroduction()),
364  "imp_pages" => array("integer", $this->getImportantPages()),
365  "page_toc" => array("integer", $this->getPageToc())
366  ), array(
367  "id" => array("integer", $this->getId())
368  ));
369 
370  // check whether start page exists
371  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
372  if (!ilWikiPage::exists($this->getId(), $this->getStartPage())
373  && !$a_prevent_start_page_creation)
374  {
375  $start_page = new ilWikiPage();
376  $start_page->setWikiId($this->getId());
377  $start_page->setTitle($this->getStartPage());
378  $start_page->create();
379  }
380 
381  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
383 
384  return true;
385  }
386 
390  function read()
391  {
392  global $ilDB;
393 
394  parent::read();
395 
396  $query = "SELECT * FROM il_wiki_data WHERE id = ".
397  $ilDB->quote($this->getId(), "integer");
398  $set = $ilDB->query($query);
399  $rec = $ilDB->fetchAssoc($set);
400 
401  $this->setOnline($rec["is_online"]);
402  $this->setStartPage($rec["startpage"]);
403  $this->setShortTitle($rec["short"]);
404  $this->setRatingOverall($rec["rating_overall"]);
405  $this->setRating($rec["rating"]);
406  $this->setRatingAsBlock($rec["rating_side"]);
407  $this->setRatingForNewPages($rec["rating_new"]);
408  $this->setRatingCategories($rec["rating_ext"]);
409  $this->setPublicNotes($rec["public_notes"]);
410  $this->setIntroduction($rec["introduction"]);
411  $this->setImportantPages($rec["imp_pages"]);
412  $this->setPageToc($rec["page_toc"]);
413 
414  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
416 
417  }
418 
419 
426  function delete()
427  {
428  global $ilDB;
429 
430  // always call parent delete function first!!
431  if (!parent::delete())
432  {
433  return false;
434  }
435 
436  // delete record of table il_wiki_data
437  $query = "DELETE FROM il_wiki_data".
438  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
439  $ilDB->manipulate($query);
440 
441  // remove all notifications
442  include_once "./Services/Notification/classes/class.ilNotification.php";
444 
445  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
447 
448  return true;
449  }
450 
454  static function checkShortTitleAvailability($a_short_title)
455  {
456  global $ilDB;
457 
458  $res = $ilDB->queryF("SELECT id FROM il_wiki_data WHERE short = %s",
459  array("text"), array($a_short_title));
460  if ($ilDB->fetchAssoc($res))
461  {
462  return false;
463  }
464 
465  return true;
466  }
467 
477  function initDefaultRoles()
478  {
479  global $rbacadmin;
480 
481  // create a local role folder
482  //$rfoldObj = $this->createRoleFolder("Local roles","Role Folder of forum obj_no.".$this->getId());
483 
484  // create moderator role and assign role to rolefolder...
485  //$roleObj = $rfoldObj->createRole("Moderator","Moderator of forum obj_no.".$this->getId());
486  //$roles[] = $roleObj->getId();
487 
488  //unset($rfoldObj);
489  //unset($roleObj);
490 
491  return $roles ? $roles : array();
492  }
493 
507  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
508  {
509  global $tree;
510 
511  switch ($a_event)
512  {
513  case "link":
514 
515  //var_dump("<pre>",$a_params,"</pre>");
516  //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
517  //exit;
518  break;
519 
520  case "cut":
521 
522  //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
523  //exit;
524  break;
525 
526  case "copy":
527 
528  //var_dump("<pre>",$a_params,"</pre>");
529  //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
530  //exit;
531  break;
532 
533  case "paste":
534 
535  //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
536  //exit;
537  break;
538 
539  case "new":
540 
541  //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
542  //exit;
543  break;
544  }
545 
546  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
547  if ($a_node_id==$_GET["ref_id"])
548  {
549  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
550  $parent_type = $parent_obj->getType();
551  if($parent_type == $this->getType())
552  {
553  $a_node_id = (int) $tree->getParentId($a_node_id);
554  }
555  }
556 
557  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
558  }
559 
567  static function _lookupRatingOverall($a_wiki_id)
568  {
569  return ilObjWiki::_lookup($a_wiki_id, "rating_overall");
570  }
571 
579  static function _lookupRating($a_wiki_id)
580  {
581  return ilObjWiki::_lookup($a_wiki_id, "rating");
582  }
583 
591  static function _lookupRatingCategories($a_wiki_id)
592  {
593  return ilObjWiki::_lookup($a_wiki_id, "rating_ext");
594  }
595 
603  static function _lookupRatingAsBlock($a_wiki_id)
604  {
605  return ilObjWiki::_lookup($a_wiki_id, "rating_side");
606  }
607 
615  static function _lookupPublicNotes($a_wiki_id)
616  {
617  return ilObjWiki::_lookup($a_wiki_id, "public_notes");
618  }
619 
628  private static function _lookup($a_wiki_id, $a_field)
629  {
630  global $ilDB;
631 
632  $query = "SELECT $a_field FROM il_wiki_data WHERE id = ".
633  $ilDB->quote($a_wiki_id, "integer");
634  $set = $ilDB->query($query);
635  $rec = $ilDB->fetchAssoc($set);
636  return $rec[$a_field];
637  }
638 
646  static function _lookupStartPage($a_wiki_id)
647  {
648  return ilObjWiki::_lookup($a_wiki_id, "startpage");
649  }
650 
654  static function writeStartPage($a_id, $a_name)
655  {
656  global $ilDB;
657 
658  include_once("./Modules/Wiki/classes/class.ilWikiUtil.php");
659  $ilDB->manipulate("UPDATE il_wiki_data SET ".
660  " startpage = ".$ilDB->quote(ilWikiUtil::makeDbTitle($a_name), "text").
661  " WHERE id = ".$ilDB->quote($a_id, "integer")
662  );
663  }
664 
668  static function _performSearch($a_wiki_id, $a_searchterm)
669  {
670  // query parser
671  include_once 'Services/Search/classes/class.ilQueryParser.php';
672 
673  $query_parser = new ilQueryParser($a_searchterm);
674  $query_parser->setCombination("or");
675  $query_parser->parse();
676 
677  include_once 'Services/Search/classes/class.ilSearchResult.php';
678  $search_result = new ilSearchResult();
679  if($query_parser->validate())
680  {
681 
682  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
683  $wiki_search =& ilObjectSearchFactory::_getWikiContentSearchInstance($query_parser);
684  $wiki_search->setFilter(array('wpg'));
685  $search_result->mergeEntries($wiki_search->performSearch());
686  }
687 
688  $entries = $search_result->getEntries();
689 
690  $found_pages = array();
691  foreach($entries as $entry)
692  {
693  if ($entry["obj_id"] == $a_wiki_id && is_array($entry["child"]))
694  {
695  foreach($entry["child"] as $child)
696  {
697  $found_pages[] = array("page_id" => $child);
698  }
699  }
700  }
701 
702  return $found_pages;
703  }
704 
705  //
706  // Important pages
707  //
708 
716  static function _lookupImportantPages($a_wiki_id)
717  {
718  return ilObjWiki::_lookup($a_wiki_id, "imp_pages");
719  }
720 
727  static function _lookupImportantPagesList($a_wiki_id)
728  {
729  global $ilDB;
730 
731  $set = $ilDB->query("SELECT * FROM il_wiki_imp_pages WHERE ".
732  " wiki_id = ".$ilDB->quote($a_wiki_id, "integer")." ORDER BY ord ASC "
733  );
734 
735  $imp_pages = array();
736 
737  while ($rec = $ilDB->fetchAssoc($set))
738  {
739  $imp_pages[] = $rec;
740  }
741  return $imp_pages;
742  }
743 
750  static function _lookupMaxOrdNrImportantPages($a_wiki_id)
751  {
752  global $ilDB;
753 
754  $set = $ilDB->query("SELECT MAX(ord) as m FROM il_wiki_imp_pages WHERE ".
755  " wiki_id = ".$ilDB->quote($a_wiki_id, "integer")
756  );
757 
758  $rec = $ilDB->fetchAssoc($set);
759  return (int) $rec["m"];
760  }
761 
762 
768  function addImportantPage($a_page_id, $a_nr = 0, $a_indent = 0)
769  {
770  global $ilDB;
771 
772  if (!$this->isImportantPage($a_page_id))
773  {
774  if ($a_nr == 0)
775  {
776  $a_nr = ilObjWiki::_lookupMaxOrdNrImportantPages($this->getId()) + 10;
777  }
778 
779  $ilDB->manipulate("INSERT INTO il_wiki_imp_pages ".
780  "(wiki_id, ord, indent, page_id) VALUES (".
781  $ilDB->quote($this->getId(), "integer").",".
782  $ilDB->quote($a_nr, "integer").",".
783  $ilDB->quote($a_indent, "integer").",".
784  $ilDB->quote($a_page_id, "integer").
785  ")");
786  }
787  }
788 
795  function isImportantPage($a_page_id)
796  {
797  global $ilDB;
798 
799  $set = $ilDB->query("SELECT * FROM il_wiki_imp_pages WHERE ".
800  " wiki_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
801  " page_id = ".$ilDB->quote($a_page_id, "integer")
802  );
803  if ($rec = $ilDB->fetchAssoc($set))
804  {
805  return true;
806  }
807  return false;
808  }
809 
815  function removeImportantPage($a_id)
816  {
817  global $ilDB;
818 
819  $ilDB->manipulate("DELETE FROM il_wiki_imp_pages WHERE "
820  ." wiki_id = ".$ilDB->quote($this->getId(), "integer")
821  ." AND page_id = ".$ilDB->quote($a_id, "integer")
822  );
823 
825  }
826 
833  function saveOrderingAndIndentation($a_ord, $a_indent)
834  {
835  global $ilDB;
836 
837  $ipages = ilObjWiki::_lookupImportantPagesList($this->getId());
838 
839  foreach ($ipages as $k => $v)
840  {
841  if (isset($a_ord[$v["page_id"]]))
842  {
843  $ipages[$k]["ord"] = (int) $a_ord[$v["page_id"]];
844  }
845  if (isset($a_indent[$v["page_id"]]))
846  {
847  $ipages[$k]["indent"] = (int) $a_indent[$v["page_id"]];
848  }
849  }
850  $ipages = ilUtil::sortArray($ipages, "ord", "asc", true);
851 
852  // fix indentation: no 2 is allowed after a 0
853  $c_indent = 0;
854  $fixed = false;
855  foreach ($ipages as $k => $v)
856  {
857  if ($ipages[$k]["indent"] == 2 && $c_indent == 0)
858  {
859  $ipages[$k]["indent"] = 1;
860  $fixed = true;
861  }
862  $c_indent = $ipages[$k]["indent"];
863  }
864 
865  $ord = 10;
866  reset($ipages);
867  foreach ($ipages as $k => $v)
868  {
869  $ilDB->manipulate($q = "UPDATE il_wiki_imp_pages SET ".
870  " ord = ".$ilDB->quote($ord, "integer").",".
871  " indent = ".$ilDB->quote($v["indent"], "integer").
872  " WHERE wiki_id = ".$ilDB->quote($v["wiki_id"], "integer").
873  " AND page_id = ".$ilDB->quote($v["page_id"], "integer")
874  );
875  $ord+=10;
876  }
877 
878  return $fixed;
879  }
880 
885  {
886  global $ilDB;
887 
888  $ipages = ilObjWiki::_lookupImportantPagesList($this->getId());
889 
890  // fix indentation: no 2 is allowed after a 0
891  $c_indent = 0;
892  $fixed = false;
893  foreach ($ipages as $k => $v)
894  {
895  if ($ipages[$k]["indent"] == 2 && $c_indent == 0)
896  {
897  $ipages[$k]["indent"] = 1;
898  $fixed = true;
899  }
900  $c_indent = $ipages[$k]["indent"];
901  }
902 
903  $ord = 10;
904  foreach ($ipages as $k => $v)
905  {
906  $ilDB->manipulate($q = "UPDATE il_wiki_imp_pages SET ".
907  " ord = ".$ilDB->quote($ord, "integer").
908  ", indent = ".$ilDB->quote($v["indent"], "integer").
909  " WHERE wiki_id = ".$ilDB->quote($v["wiki_id"], "integer").
910  " AND page_id = ".$ilDB->quote($v["page_id"], "integer")
911  );
912  $ord+=10;
913  }
914 
915  }
916 
917  //
918  // Page TOC
919  //
920 
928  static function _lookupPageToc($a_wiki_id)
929  {
930  return ilObjWiki::_lookup($a_wiki_id, "page_toc");
931  }
932 
939  public function cloneObject($a_target_id,$a_copy_id = 0)
940  {
941  global $ilDB, $ilUser, $ilias;
942 
943  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
944 
945  $new_obj->setTitle($this->getTitle());
946  $new_obj->setStartPage($this->getStartPage());
947  $new_obj->setShortTitle($this->getShortTitle());
948  $new_obj->setRatingOverall($this->getRatingOverall());
949  $new_obj->setRating($this->getRating());
950  $new_obj->setRatingAsBlock($this->getRatingAsBlock());
951  $new_obj->setRatingForNewPages($this->getRatingForNewPages());
952  $new_obj->setRatingCategories($this->getRatingCategories());
953  $new_obj->setPublicNotes($this->getPublicNotes());
954  $new_obj->setIntroduction($this->getIntroduction());
955  $new_obj->setImportantPages($this->getImportantPages());
956  $new_obj->setPageToc($this->getPageToc());
957  $new_obj->update();
958 
959  // set/copy stylesheet
960  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
961  $style_id = $this->getStyleSheetId();
962  if ($style_id > 0 && !ilObjStyleSheet::_lookupStandard($style_id))
963  {
964  $style_obj = $ilias->obj_factory->getInstanceByObjId($style_id);
965  $new_id = $style_obj->ilClone();
966  $new_obj->setStyleSheetId($new_id);
967  $new_obj->update();
968  }
969 
970  // copy content
971  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
972  $pages = ilWikiPage::getAllPages($this->getId());
973  if (count($pages) > 0)
974  {
975  // if we have any pages, delete the start page first
976  $pg_id = ilWikiPage::getPageIdForTitle($new_obj->getId(), $new_obj->getStartPage());
977  $start_page = new ilWikiPage($pg_id);
978  $start_page->delete();
979  }
980  $map = array();
981  foreach ($pages as $p)
982  {
983  $page = new ilWikiPage($p["id"]);
984  $new_page = new ilWikiPage();
985  $new_page->setTitle($page->getTitle());
986  $new_page->setWikiId($new_obj->getId());
987  $new_page->setTitle($page->getTitle());
988  $new_page->setBlocked($page->getBlocked());
989  $new_page->setRating($page->getRating());
990  $new_page->create();
991 
992  $page->copy($new_page->getId(), "", 0, true);
993  //$new_page->setXMLContent($page->copyXMLContent(true));
994  //$new_page->buildDom(true);
995  //$new_page->update();
996  $map[$p["id"]] = $new_page->getId();
997  }
998 
999  // copy important pages
1000  foreach (ilObjWiki::_lookupImportantPagesList($this->getId()) as $ip)
1001  {
1002  $new_obj->addImportantPage($map[$ip["page_id"]], $ip["ord"], $ip["indent"]);
1003  }
1004 
1005  // copy rating categories
1006  include_once("./Services/Rating/classes/class.ilRatingCategory.php");
1007  foreach (ilRatingCategory::getAllForObject($this->getId()) as $rc)
1008  {
1009  $new_rc = new ilRatingCategory();
1010  $new_rc->setParentId($new_obj->getId());
1011  $new_rc->setTitle($rc["title"]);
1012  $new_rc->setDescription($rc["description"]);
1013  $new_rc->save();
1014  }
1015 
1016  return $new_obj;
1017  }
1018 
1019 }
1020 ?>