ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLuceneHighlighterResultParser.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 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 
35 {
36  private $result_string = '';
37  private $result = array();
38 
43  public function __construct()
44  {
45 
46  }
47 
53  public function setResultString($a_res)
54  {
55  $this->result_string = $a_res;
56  }
57 
63  public function getResultString()
64  {
65  return $this->result_string;
66  }
67 
72  public function parse()
73  {
74  if(!strlen($this->getResultString()))
75  {
76  return false;
77  }
78  $root = new SimpleXMLElement($this->getResultString());
79  foreach($root->children() as $object)
80  {
81  $obj_id = (string) $object['id'];
82  foreach($object->children() as $item)
83  {
84  $sub_id = (string) $item['id'];
85  foreach($item->children() as $field)
86  {
87  $name = (string) $field['name'];
88  $this->result[$obj_id][$sub_id][$name] = (string) $field;
89  }
90  }
91  }
92  return true;
93  }
94 
101  public function getTitle($a_obj_id,$a_sub_id)
102  {
103  return isset($this->result[$a_obj_id][$a_sub_id]['title']) ? $this->result[$a_obj_id][$a_sub_id]['title'] : null;
104  }
105 
112  public function getDescription($a_obj_id,$a_sub_id)
113  {
114  return isset($this->result[$a_obj_id][$a_sub_id]['description']) ? $this->result[$a_obj_id][$a_sub_id]['description'] : null;
115  }
116 
123  public function getContent($a_obj_id,$a_sub_id)
124  {
125  return isset($this->result[$a_obj_id][$a_sub_id]['content']) ? $this->result[$a_obj_id][$a_sub_id]['content'] : null;
126  }
127 
133  public function getSubItemIds($a_obj_id)
134  {
135  $sub_item_ids = array();
136  if(!isset($this->result[$a_obj_id]))
137  {
138  return array();
139  }
140  foreach($this->result[$a_obj_id] as $sub_item_id => $data)
141  {
142  if($sub_item_id)
143  {
144  $sub_item_ids[] = $sub_item_id;
145  }
146  }
147  return $sub_item_ids ? $sub_item_ids : array();
148  }
149 }
150 ?>