ILIAS  Release_4_0_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  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2009 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
27 include_once "./classes/class.ilObject.php";
28 include_once ("./Modules/Wiki/classes/class.ilWikiUtil.php");
29 
38 class ilObjWiki extends ilObject
39 {
40  protected $online = false;
41 
48  function ilObjWiki($a_id = 0,$a_call_by_reference = true)
49  {
50  $this->type = "wiki";
51  $this->ilObject($a_id,$a_call_by_reference);
52  }
53 
59  function setOnline($a_online)
60  {
61  $this->online = $a_online;
62  }
63 
69  function getOnline()
70  {
71  return $this->online;
72  }
73 
79  function setRating($a_rating)
80  {
81  $this->rating = $a_rating;
82  }
83 
89  function getRating()
90  {
91  return $this->rating;
92  }
93 
99  function setStartPage($a_startpage)
100  {
101  $this->startpage = ilWikiUtil::makeDbTitle($a_startpage);
102  }
103 
109  function getStartPage()
110  {
111  return $this->startpage;
112  }
113 
119  function setShortTitle($a_shorttitle)
120  {
121  $this->shorttitle = $a_shorttitle;
122  }
123 
129  function getShortTitle()
130  {
131  return $this->shorttitle;
132  }
133 
139  function setIntroduction($a_introduction)
140  {
141  $this->introduction = $a_introduction;
142  }
143 
149  function getIntroduction()
150  {
151  return $this->introduction;
152  }
153 
157  function getStyleSheetId()
158  {
159  return $this->style_id;
160  }
161 
165  function setStyleSheetId($a_style_id)
166  {
167  $this->style_id = $a_style_id;
168  }
169 
173  function create()
174  {
175  global $ilDB;
176 
177  parent::create();
178 
179  $ilDB->insert("il_wiki_data", array(
180  "id" => array("integer", $this->getId()),
181  "is_online" => array("integer", (int) $this->getOnline()),
182  "startpage" => array("text", $this->getStartPage()),
183  "short" => array("text", $this->getShortTitle()),
184  "rating" => array("integer", (int) $this->getRating()),
185  "introduction" => array("clob", $this->getIntroduction())
186  ));
187 
188  // create start page
189  if ($this->getStartPage() != "")
190  {
191  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
192  $start_page = new ilWikiPage();
193  $start_page->setWikiId($this->getId());
194  $start_page->setTitle($this->getStartPage());
195  $start_page->create();
196  }
197 
198  if (((int) $this->getStyleSheetId()) > 0)
199  {
200  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
202  }
203  }
204 
211  function update()
212  {
213  global $ilDB;
214 
215  if (!parent::update())
216  {
217  return false;
218  }
219 
220  $ilDB->update("il_wiki_data", array(
221  "is_online" => array("integer", $this->getOnline()),
222  "startpage" => array("text", $this->getStartPage()),
223  "short" => array("text", $this->getShortTitle()),
224  "rating" => array("integer", $this->getRating()),
225  "introduction" => array("clob", $this->getIntroduction())
226  ), array(
227  "id" => array("integer", $this->getId())
228  ));
229 
230  // check whether start page exists
231  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
232  if (!ilWikiPage::exists($this->getId(), $this->getStartPage()))
233  {
234  $start_page = new ilWikiPage();
235  $start_page->setWikiId($this->getId());
236  $start_page->setTitle($this->getStartPage());
237  $start_page->create();
238  }
239 
240  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
242 
243  return true;
244  }
245 
249  function read()
250  {
251  global $ilDB;
252 
253  parent::read();
254 
255  $query = "SELECT * FROM il_wiki_data WHERE id = ".
256  $ilDB->quote($this->getId(), "integer");
257  $set = $ilDB->query($query);
258  $rec = $ilDB->fetchAssoc($set);
259 
260  $this->setOnline($rec["is_online"]);
261  $this->setStartPage($rec["startpage"]);
262  $this->setShortTitle($rec["short"]);
263  $this->setRating($rec["rating"]);
264  $this->setIntroduction($rec["introduction"]);
265 
266  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
268 
269  }
270 
271 
278  function delete()
279  {
280  global $ilDB;
281 
282  // always call parent delete function first!!
283  if (!parent::delete())
284  {
285  return false;
286  }
287 
288  // delete record of table il_wiki_data
289  $query = "DELETE FROM il_wiki_data".
290  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
291  $ilDB->manipulate($query);
292 
293  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
295 
296  return true;
297  }
298 
302  static function checkShortTitleAvailability($a_short_title)
303  {
304  global $ilDB;
305 
306  $res = $ilDB->queryF("SELECT id FROM il_wiki_data WHERE short = %s",
307  array("text"), array($a_short_title));
308  if ($ilDB->fetchAssoc($res))
309  {
310  return false;
311  }
312 
313  return true;
314  }
315 
325  function initDefaultRoles()
326  {
327  global $rbacadmin;
328 
329  // create a local role folder
330  //$rfoldObj = $this->createRoleFolder("Local roles","Role Folder of forum obj_no.".$this->getId());
331 
332  // create moderator role and assign role to rolefolder...
333  //$roleObj = $rfoldObj->createRole("Moderator","Moderator of forum obj_no.".$this->getId());
334  //$roles[] = $roleObj->getId();
335 
336  //unset($rfoldObj);
337  //unset($roleObj);
338 
339  return $roles ? $roles : array();
340  }
341 
355  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
356  {
357  global $tree;
358 
359  switch ($a_event)
360  {
361  case "link":
362 
363  //var_dump("<pre>",$a_params,"</pre>");
364  //echo "Module name ".$this->getRefId()." triggered by link event. Objects linked into target object ref_id: ".$a_ref_id;
365  //exit;
366  break;
367 
368  case "cut":
369 
370  //echo "Module name ".$this->getRefId()." triggered by cut event. Objects are removed from target object ref_id: ".$a_ref_id;
371  //exit;
372  break;
373 
374  case "copy":
375 
376  //var_dump("<pre>",$a_params,"</pre>");
377  //echo "Module name ".$this->getRefId()." triggered by copy event. Objects are copied into target object ref_id: ".$a_ref_id;
378  //exit;
379  break;
380 
381  case "paste":
382 
383  //echo "Module name ".$this->getRefId()." triggered by paste (cut) event. Objects are pasted into target object ref_id: ".$a_ref_id;
384  //exit;
385  break;
386 
387  case "new":
388 
389  //echo "Module name ".$this->getRefId()." triggered by paste (new) event. Objects are applied to target object ref_id: ".$a_ref_id;
390  //exit;
391  break;
392  }
393 
394  // At the beginning of the recursive process it avoids second call of the notify function with the same parameter
395  if ($a_node_id==$_GET["ref_id"])
396  {
397  $parent_obj =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
398  $parent_type = $parent_obj->getType();
399  if($parent_type == $this->getType())
400  {
401  $a_node_id = (int) $tree->getParentId($a_node_id);
402  }
403  }
404 
405  parent::notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params);
406  }
407 
415  static function _lookupRating($a_wiki_id)
416  {
417  return ilObjWiki::_lookup($a_wiki_id, "rating");
418  }
419 
428  private static function _lookup($a_wiki_id, $a_field)
429  {
430  global $ilDB;
431 
432  $query = "SELECT $a_field FROM il_wiki_data WHERE id = ".
433  $ilDB->quote($a_wiki_id, "integer");
434  $set = $ilDB->query($query);
435  $rec = $ilDB->fetchAssoc($set);
436  return $rec[$a_field];
437  }
438 
446  static function _lookupStartPage($a_wiki_id)
447  {
448  return ilObjWiki::_lookup($a_wiki_id, "startpage");
449  }
450 
454  static function _performSearch($a_wiki_id, $a_searchterm)
455  {
456  // query parser
457  include_once 'Services/Search/classes/class.ilQueryParser.php';
458 
459  $query_parser = new ilQueryParser($a_searchterm);
460  $query_parser->setCombination("or");
461  $query_parser->parse();
462 
463  include_once 'Services/Search/classes/class.ilSearchResult.php';
464  $search_result = new ilSearchResult();
465  if($query_parser->validate())
466  {
467 
468  include_once 'Services/Search/classes/class.ilObjectSearchFactory.php';
469  $wiki_search =& ilObjectSearchFactory::_getWikiContentSearchInstance($query_parser);
470  $wiki_search->setFilter(array('wpg'));
471  $search_result->mergeEntries($wiki_search->performSearch());
472  }
473 
474  $entries = $search_result->getEntries();
475 
476  $found_pages = array();
477  foreach($entries as $entry)
478  {
479  if ($entry["obj_id"] == $a_wiki_id && is_array($entry["child"]))
480  {
481  foreach($entry["child"] as $child)
482  {
483  $found_pages[] = $child;
484  }
485  }
486  }
487 
488  return $found_pages;
489  }
490 
491 } // END class.ilObjWiki
492 ?>