ILIAS  Release_4_1_x_branch Revision 61804
 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-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
8 include_once "./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 
29  function ilObjWiki($a_id = 0,$a_call_by_reference = true)
30  {
31  $this->type = "wiki";
32  $this->ilObject($a_id,$a_call_by_reference);
33  }
34 
40  function setOnline($a_online)
41  {
42  $this->online = $a_online;
43  }
44 
50  function getOnline()
51  {
52  return $this->online;
53  }
54 
60  function setRating($a_rating)
61  {
62  $this->rating = $a_rating;
63  }
64 
70  function getRating()
71  {
72  return $this->rating;
73  }
74 
80  function setStartPage($a_startpage)
81  {
82  $this->startpage = ilWikiUtil::makeDbTitle($a_startpage);
83  }
84 
90  function getStartPage()
91  {
92  return $this->startpage;
93  }
94 
100  function setShortTitle($a_shorttitle)
101  {
102  $this->shorttitle = $a_shorttitle;
103  }
104 
110  function getShortTitle()
111  {
112  return $this->shorttitle;
113  }
114 
120  function setIntroduction($a_introduction)
121  {
122  $this->introduction = $a_introduction;
123  }
124 
130  function getIntroduction()
131  {
132  return $this->introduction;
133  }
134 
138  function getStyleSheetId()
139  {
140  return $this->style_id;
141  }
142 
146  function setStyleSheetId($a_style_id)
147  {
148  $this->style_id = $a_style_id;
149  }
150 
154  function create($a_prevent_start_page_creation = false)
155  {
156  global $ilDB;
157 
158  parent::create();
159 
160  $ilDB->insert("il_wiki_data", array(
161  "id" => array("integer", $this->getId()),
162  "is_online" => array("integer", (int) $this->getOnline()),
163  "startpage" => array("text", $this->getStartPage()),
164  "short" => array("text", $this->getShortTitle()),
165  "rating" => array("integer", (int) $this->getRating()),
166  "introduction" => array("clob", $this->getIntroduction())
167  ));
168 
169  // create start page
170  if ($this->getStartPage() != "" && !$a_prevent_start_page_creation)
171  {
172  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
173  $start_page = new ilWikiPage();
174  $start_page->setWikiId($this->getId());
175  $start_page->setTitle($this->getStartPage());
176  $start_page->create();
177  }
178 
179  if (((int) $this->getStyleSheetId()) > 0)
180  {
181  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
183  }
184  }
185 
192  function update($a_prevent_start_page_creation = false)
193  {
194  global $ilDB;
195 
196  if (!parent::update())
197  {
198  return false;
199  }
200 
201  $ilDB->update("il_wiki_data", array(
202  "is_online" => array("integer", $this->getOnline()),
203  "startpage" => array("text", $this->getStartPage()),
204  "short" => array("text", $this->getShortTitle()),
205  "rating" => array("integer", $this->getRating()),
206  "introduction" => array("clob", $this->getIntroduction())
207  ), array(
208  "id" => array("integer", $this->getId())
209  ));
210 
211  // check whether start page exists
212  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
213  if (!ilWikiPage::exists($this->getId(), $this->getStartPage())
214  && !$a_prevent_start_page_creation)
215  {
216  $start_page = new ilWikiPage();
217  $start_page->setWikiId($this->getId());
218  $start_page->setTitle($this->getStartPage());
219  $start_page->create();
220  }
221 
222  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
224 
225  return true;
226  }
227 
231  function read()
232  {
233  global $ilDB;
234 
235  parent::read();
236 
237  $query = "SELECT * FROM il_wiki_data WHERE id = ".
238  $ilDB->quote($this->getId(), "integer");
239  $set = $ilDB->query($query);
240  $rec = $ilDB->fetchAssoc($set);
241 
242  $this->setOnline($rec["is_online"]);
243  $this->setStartPage($rec["startpage"]);
244  $this->setShortTitle($rec["short"]);
245  $this->setRating($rec["rating"]);
246  $this->setIntroduction($rec["introduction"]);
247 
248  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
250 
251  }
252 
253 
260  function delete()
261  {
262  global $ilDB;
263 
264  // always call parent delete function first!!
265  if (!parent::delete())
266  {
267  return false;
268  }
269 
270  // delete record of table il_wiki_data
271  $query = "DELETE FROM il_wiki_data".
272  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
273  $ilDB->manipulate($query);
274 
275  // remove all notifications
276  include_once "./Services/Notification/classes/class.ilNotification.php";
278 
279  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
281 
282  return true;
283  }
284 
288  static function checkShortTitleAvailability($a_short_title)
289  {
290  global $ilDB;
291 
292  $res = $ilDB->queryF("SELECT id FROM il_wiki_data WHERE short = %s",
293  array("text"), array($a_short_title));
294  if ($ilDB->fetchAssoc($res))
295  {
296  return false;
297  }
298 
299  return true;
300  }
301 
311  function initDefaultRoles()
312  {
313  global $rbacadmin;
314 
315  // create a local role folder
316  //$rfoldObj = $this->createRoleFolder("Local roles","Role Folder of forum obj_no.".$this->getId());
317 
318  // create moderator role and assign role to rolefolder...
319  //$roleObj = $rfoldObj->createRole("Moderator","Moderator of forum obj_no.".$this->getId());
320  //$roles[] = $roleObj->getId();
321 
322  //unset($rfoldObj);
323  //unset($roleObj);
324 
325  return $roles ? $roles : array();
326  }
327 
341  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
342  {
343  global $tree;
344 
345  switch ($a_event)
346  {
347  case "link":
348 
349  //var_dump("<pre>",$a_params,"</pre>");
350  //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
351  //exit;
352  break;
353 
354  case "cut":
355 
356  //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
357  //exit;
358  break;
359 
360  case "copy":
361 
362  //var_dump("<pre>",$a_params,"</pre>");
363  //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
364  //exit;
365  break;
366 
367  case "paste":
368 
369  //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
370  //exit;
371  break;
372 
373  case "new":
374 
375  //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
376  //exit;
377  break;
378  }
379 
380  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
381  if ($a_node_id==$_GET["ref_id"])
382  {
383  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
384  $parent_type = $parent_obj->getType();
385  if($parent_type == $this->getType())
386  {
387  $a_node_id = (int) $tree->getParentId($a_node_id);
388  }
389  }
390 
391  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
392  }
393 
401  static function _lookupRating($a_wiki_id)
402  {
403  return ilObjWiki::_lookup($a_wiki_id, "rating");
404  }
405 
414  private static function _lookup($a_wiki_id, $a_field)
415  {
416  global $ilDB;
417 
418  $query = "SELECT $a_field FROM il_wiki_data WHERE id = ".
419  $ilDB->quote($a_wiki_id, "integer");
420  $set = $ilDB->query($query);
421  $rec = $ilDB->fetchAssoc($set);
422  return $rec[$a_field];
423  }
424 
432  static function _lookupStartPage($a_wiki_id)
433  {
434  return ilObjWiki::_lookup($a_wiki_id, "startpage");
435  }
436 
440  static function _performSearch($a_wiki_id, $a_searchterm)
441  {
442  // query parser
443  include_once 'Services/Search/classes/class.ilQueryParser.php';
444 
445  $query_parser = new ilQueryParser($a_searchterm);
446  $query_parser->setCombination("or");
447  $query_parser->parse();
448 
449  include_once 'Services/Search/classes/class.ilSearchResult.php';
450  $search_result = new ilSearchResult();
451  if($query_parser->validate())
452  {
453 
454  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
455  $wiki_search =& ilObjectSearchFactory::_getWikiContentSearchInstance($query_parser);
456  $wiki_search->setFilter(array('wpg'));
457  $search_result->mergeEntries($wiki_search->performSearch());
458  }
459 
460  $entries = $search_result->getEntries();
461 
462  $found_pages = array();
463  foreach($entries as $entry)
464  {
465  if ($entry["obj_id"] == $a_wiki_id && is_array($entry["child"]))
466  {
467  foreach($entry["child"] as $child)
468  {
469  $found_pages[] = $child;
470  }
471  }
472  }
473 
474  return $found_pages;
475  }
476 
477 } // END class.ilObjWiki
478 ?>