ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSearchResultPresentationGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 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 
24 include_once('classes/class.ilLink.php');
25 
38 {
39  protected $search_cache = null;
40 
41  var $tpl;
42  var $lng;
43 
44  var $result = 0;
45 
47  {
48  global $tpl,$lng,$ilCtrl,$ilUser;
49 
50  $this->lng =& $lng;
51 
52  $this->result =& $result;
53 
54  $this->type_ordering = array(
55  "cat", "crs", "grp", "chat", "frm", "wiki", "lres",
56  "glo", "webr", "file",'mcst', "exc",
57  "tst", "svy", "sess","mep", "qpl", "spl");
58 
59  $this->ctrl =& $ilCtrl;
60 
61  include_once('Services/Search/classes/class.ilUserSearchCache.php');
62  $this->search_cache = ilUserSearchCache::_getInstance($ilUser->getId());
63  }
64 
65  function &showResults()
66  {
67  // Get results
68  $results = $this->result->getResultsForPresentation();
69 
70  return $html =& $this->renderItemList($results);
71 
72 
73  }
74 
76  {
77  global $objDefinition;
78 
79  $html = '';
80 
81  $cur_obj_type = "";
82  $tpl =& $this->newBlockTemplate();
83  $first = true;
84 
85  foreach($this->type_ordering as $act_type)
86  {
87  $item_html = array();
88 
89  if (is_array($results[$act_type]))
90  {
91  foreach($results[$act_type] as $key => $item)
92  {
93  // get list gui class for each object type
94  if ($cur_obj_type != $item["type"])
95  {
96  include_once 'Services/Search/classes/class.ilSearchObjectListFactory.php';
97 
98  $item_list_gui = ilSearchObjectListFactory::_getInstance($item['type']);
99  }
100 
101  $html = $item_list_gui->getListItemHTML(
102  $item["ref_id"],
103  $item["obj_id"],
104  $item["title"],
105  $item["description"]);
106 
107  if($html)
108  {
109  $html = $this->__appendChildLinks($html,$item,$item_list_gui);
110  $item_html[$item["ref_id"]] = $html;
111  }
112  }
113  // output block for resource type
114  if(count($item_html) > 0)
115  {
116  // separator row
117  if (!$first)
118  {
119  $this->addSeparatorRow($tpl);
120  }
121  $first = false;
122 
123  // add a header for each resource type
124  $this->addHeaderRow($tpl, $act_type);
125  $this->resetRowType();
126 
127  // content row
128  foreach($item_html as $ref_id => $html)
129  {
130  $this->addStandardRow($tpl, $html, $ref_id);
131  }
132  }
133  }
134  }
135 
136 
137  return $tpl->get();
138  }
139 
147  function addHeaderRow(&$a_tpl, $a_type)
148  {
149  if ($a_type != "lres")
150  {
151  $icon = ilUtil::getImagePath("icon_".$a_type.".gif");
152  $title = $this->lng->txt("objs_".$a_type);
153  }
154  else
155  {
156  $icon = ilUtil::getImagePath("icon_lm.gif");
157  $title = $this->lng->txt("learning_resources");
158  }
159 
160  $a_tpl->setCurrentBlock("container_header_row_image");
161  $a_tpl->setVariable("HEADER_IMG", $icon);
162  $a_tpl->setVariable("HEADER_ALT", $title);
163  $a_tpl->setVariable("BLOCK_HEADER_CONTENT", $title);
164  $a_tpl->parseCurrentBlock();
165 
166 
167  #$a_tpl->setCurrentBlock("container_header_row");
168  #$a_tpl->parseCurrentBlock();
169  #$a_tpl->touchBlock("container_row");
170  }
171 
172  function resetRowType()
173  {
174  $this->cur_row_type = "";
175  }
176 
184  function addStandardRow(&$a_tpl, $a_html,$a_ref_id)
185  {
186  $this->cur_row_type = ($this->cur_row_type == "row_type_1")
187  ? "row_type_2"
188  : "row_type_1";
189 
190  $a_tpl->touchBlock($this->cur_row_type);
191  $a_tpl->setCurrentBlock("container_standard_row");
192  $a_tpl->setVariable("BLOCK_ROW_CONTENT", $a_html);
193 
194  // add checkbox for saving results
195  $a_tpl->setVariable("BLOCK_ROW_CHECK",ilUtil::formCheckbox(0,'result[]',$a_ref_id));
196  $a_tpl->setVariable("ITEM_ID",$a_ref_id);
197  $a_tpl->parseCurrentBlock();
198  $a_tpl->touchBlock("container_row");
199  }
200 
207  function &newBlockTemplate()
208  {
209  $tpl =& new ilTemplate ("tpl.container_list_block.html",true, true,
210  "Services/Container");
211  $this->cur_row_type = "row_type_1";
212 
213  return $tpl;
214  }
215 
216  function addSeparatorRow(&$a_tpl)
217  {
218  $a_tpl->touchBlock("separator_row");
219  $a_tpl->touchBlock("container_row");
220  }
221 
222  function __appendChildLinks($html,$item,&$item_list_gui)
223  {
224  if(!count($item['child']))
225  {
226  return $html;
227  }
228  $tpl = new ilTemplate('tpl.detail_links.html',true,true,'Services/Search');
229  $tpl->setVariable("HITS",$this->lng->txt('search_hits'));
230 
231  switch($item['type'])
232  {
233  case 'lm':
234  include_once 'Modules/LearningModule/classes/class.ilLMObject.php';
235  foreach($item['child'] as $child)
236  {
237  $tpl->setCurrentBlock("link_row");
238 
239  switch(ilLMObject::_lookupType($child))
240  {
241  case 'pg':
242  $tpl->setVariable("CHAPTER_PAGE",$this->lng->txt('obj_pg'));
243  break;
244  case 'st':
245  $tpl->setVariable("CHAPTER_PAGE",$this->lng->txt('obj_st'));
246  break;
247  }
248  $item_list_gui->setChildId($child);
249  $tpl->setVariable("SEPERATOR",' -> ');
250  $tpl->setVariable("LINK",$item_list_gui->getCommandLink('page'));
251  $tpl->setVariable("TARGET",$item_list_gui->getCommandFrame('page'));
252  $tpl->setVariable("TITLE",ilLMObject::_lookupTitle($child));
253  $tpl->parseCurrentBlock();
254  }
255  break;
256 
257  case 'frm':
258  include_once './Modules/Forum/classes/class.ilObjForum.php';
259 
260  foreach($item['child'] as $child)
261  {
262  $thread_post = explode('_',$child);
263 
264  $tpl->setCurrentBlock("link_row");
265  $tpl->setVariable("CHAPTER_PAGE",$this->lng->txt('thread'));
266 
267  $item_list_gui->setChildId($thread_post);
268  $tpl->setVariable("SEPERATOR",': ');
269  $tpl->setVariable("LINK",$item_list_gui->getCommandLink('posting'));
270  $tpl->setVariable("TARGET",$item_list_gui->getCommandFrame(''));
271  $tpl->setVariable("TITLE",ilObjForum::_lookupThreadSubject($thread_post[0]));
272  $tpl->parseCurrentBlock();
273  }
274  break;
275 
276  case 'glo':
277  include_once './Modules/Glossary/classes/class.ilGlossaryTerm.php';
278 
279  $this->lng->loadLanguageModule('content');
280  foreach($item['child'] as $child)
281  {
282  $tpl->setCurrentBlock("link_row");
283  $tpl->setVariable("CHAPTER_PAGE",$this->lng->txt('cont_term'));
284  $tpl->setVariable("SEPERATOR",': ');
285  $tpl->setVariable("LINK",ilLink::_getLink($item['ref_id'],'git',array('target' => 'git_'.$child.'_'.$item['ref_id'])));
286  $tpl->setVariable("TITLE",ilGlossaryTerm::_lookGlossaryTerm($child));
287  $tpl->parseCurrentBlock();
288  }
289  break;
290 
291  case 'wiki':
292  include_once './Modules/Wiki/classes/class.ilWikiPage.php';
293  include_once './Modules/Wiki/classes/class.ilWikiUtil.php';
294 
295  $this->lng->loadLanguageModule('wiki');
296  foreach($item['child'] as $child)
297  {
298  $page_title = ilWikiPage::lookupTitle($child);
299  $tpl->setCurrentBlock("link_row");
300  $tpl->setVariable("CHAPTER_PAGE",$this->lng->txt('wiki_page'));
301  $tpl->setVariable("SEPERATOR",': ');
302  $tpl->setVariable("LINK",ilLink::_getLink($item['ref_id'],'wiki',array(), "_".
303  ilWikiUtil::makeUrlTitle($page_title)));
304  $tpl->setVariable("TITLE", $page_title);
305  $tpl->parseCurrentBlock();
306  }
307  break;
308 
309  case 'mcst':
310  include_once("./Services/News/classes/class.ilNewsItem.php");
311 
312  foreach($item['child'] as $child)
313  {
314  $tpl->setCurrentBlock("link_row");
315  //$tpl->setVariable("CHAPTER_PAGE",$this->lng->txt('item'));
316 
317  $item_list_gui->setChildId($child);
318  //$tpl->setVariable("SEPERATOR",': ');
319  $tpl->setVariable("LINK", $item_list_gui->getCommandLink('listItems'));
320  $tpl->setVariable("TARGET", $item_list_gui->getCommandFrame(''));
321  $tpl->setVariable("TITLE", ilNewsItem::_lookupTitle($child));
322  $tpl->parseCurrentBlock();
323  }
324  break;
325 
326  default:
327  ;
328  }
329  return $html . $tpl->get();
330  }
331 
332 
333 }
334 
335 ?>