ILIAS  Release_3_10_x_branch Revision 61812
 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-2008 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 create()
158  {
159  global $ilDB;
160 
161  parent::create();
162 
163  $query = "INSERT INTO il_wiki_data (".
164  " id".
165  ", online".
166  ", startpage".
167  ", short".
168  ", rating".
169  ", introduction".
170  " ) VALUES (".
171  $ilDB->quote($this->getId())
172  .",".$ilDB->quote($this->getOnline())
173  .",".$ilDB->quote($this->getStartPage())
174  .",".$ilDB->quote($this->getShortTitle())
175  .",".$ilDB->quote($this->getRating())
176  .",".$ilDB->quote($this->getIntroduction())
177  .")";
178  $ilDB->query($query);
179 
180  // create start page
181  if ($this->getStartPage() != "")
182  {
183  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
184  $start_page = new ilWikiPage();
185  $start_page->setWikiId($this->getId());
186  $start_page->setTitle($this->getStartPage());
187  $start_page->create();
188  }
189 
190  }
191 
198  function update()
199  {
200  global $ilDB;
201 
202  if (!parent::update())
203  {
204  return false;
205  }
206 
207  // update wiki data
208  $st = $ilDB->prepareManip("UPDATE il_wiki_data SET ".
209  " online = ?, startpage = ?, short = ?, ".
210  " rating = ?, introduction = ? ".
211  " WHERE id = ?",
212  array("boolean","text","text","boolean","text","integer"));
213  $ilDB->execute($st, array(
214  $this->getOnline(),
215  $this->getStartPage(),
216  $this->getShortTitle(),
217  $this->getRating(),
218  $this->getIntroduction(),
219  $this->getId()));
220 
221  // check whether start page exists
222  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
223  if (!ilWikiPage::exists($this->getId(), $this->getStartPage()))
224  {
225  $start_page = new ilWikiPage();
226  $start_page->setWikiId($this->getId());
227  $start_page->setTitle($this->getStartPage());
228  $start_page->create();
229  }
230 
231  return true;
232  }
233 
237  function read()
238  {
239  global $ilDB;
240 
241  parent::read();
242 
243  $query = "SELECT * FROM il_wiki_data WHERE id = ".
244  $ilDB->quote($this->getId());
245  $set = $ilDB->query($query);
246  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
247 
248  $this->setOnline($rec["online"]);
249  $this->setStartPage($rec["startpage"]);
250  $this->setShortTitle($rec["short"]);
251  $this->setRating($rec["rating"]);
252  $this->setIntroduction($rec["introduction"]);
253 
254  }
255 
256 
263  function delete()
264  {
265  global $ilDB;
266 
267  // always call parent delete function first!!
268  if (!parent::delete())
269  {
270  return false;
271  }
272 
273  // delete record of table il_wiki_data
274  $query = "DELETE FROM il_wiki_data".
275  " WHERE id = ".$ilDB->quote($this->getId());
276  $ilDB->query($query);
277 
278  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
280 
281  return true;
282  }
283 
287  static function checkShortTitleAvailability($a_short_title)
288  {
289  global $ilDB;
290 
291  $st = $ilDB->prepare("SELECT * FROM il_wiki_data WHERE short = ?",
292  array("text"));
293  $res = $ilDB->execute($st, 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 * FROM il_wiki_data WHERE id = ".
419  $ilDB->quote($a_wiki_id);
420  $set = $ilDB->query($query);
421  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
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 ?>