ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilShopResultPresentationGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once 'Services/Payment/classes/class.ilPaymentPrices.php';
5 include_once 'Services/Payment/classes/class.ilPaymentObject.php';
6 include_once 'Services/Payment/classes/class.ilFileDataShop.php';
7 
17 {
18  protected $search_cache = null;
19 
20  var $tpl;
21  var $lng;
22 
23  var $result = 0;
24 
25 
26  private $sort_field = '';
27  private $sort_direction = '';
28 
30  {
31  global $tpl,$lng,$ilCtrl,$ilUser;
32 
33  $this->lng = $lng;
34 
35  $this->result = $result;
36 
37  $this->type_ordering = array(
38  "cat", "crs", "grp", "lres",
39  "glo", "webr", "file",'mcst', "exc",
40  "tst", "svy", "sess","mep", "qpl", "spl");
41 
42  $this->ctrl = $ilCtrl;
43 
44  include_once('Services/Search/classes/class.ilUserSearchCache.php');
45  $this->search_cache = ilUserSearchCache::_getInstance($ilUser->getId());
46 
47  }
48 
49  function showResults()
50  {
51  // Get results
52  $results = $this->result->getResultsForPresentation();
53 
54  return $html = $this->renderItemList($results);
55  }
56 
57  public function setTypeOrdering($a_type_ordering_array)
58  {
59  $this->type_ordering = $a_type_ordering_array;
60  }
61  public function getTypeOrdering()
62  {
63  return $this->type_ordering;
64  }
65  public function setSortField($a_sort_field)
66  {
67  $this->sort_field = $a_sort_field;
68  }
69  public function getSortField()
70  {
71  return $this->sort_field;
72  }
73  public function setSortDirection($a_sort_direction)
74  {
75  $this->sort_direction = $a_sort_direction;
76  }
77  public function getSortDirection()
78  {
79  return $this->sort_direction;
80  }
81 
82  public function sortResult($result)
83  {
84  if ($this->sort_direction != '' && $this->sort_field != '')
85  {
86  switch ($this->sort_field)
87  {
88  case 'price':
89  $numeric_sort = true;
90  break;
91  default:
92  $numeric_sort = false;
93  break;
94  }
95 
96  $result = ilUtil::sortArray($result, $this->sort_field, $this->sort_direction, $numeric_sort);
97  }
98 
99  return $result;
100  }
101 
102  private function renderItems($oContainerTpl, $results, $topic)
103  {
104  global $ilUser;
105 
106  $items_counter = 0;
107 
108  $cur_obj_type = '';
109  $tpl = $this->newBlockTemplate();
110  $first = true;
111 
112  foreach($this->type_ordering as $act_type)
113  {
114  $item_html = array();
115 
116  if(count($results[$topic['id']][$act_type]))
117  {
118  foreach($results[$topic['id']][$act_type] as $key => $item)
119  {
120  $oPaymentObject =
121  new ilPaymentObject($ilUser, ilPaymentObject::_lookupPobjectId($item['ref_id']));
122  $oPrice = new ilPaymentPrices($oPaymentObject->getPobjectId());
123  $lowest_price = $oPrice->getLowestPrice();
124 
125  $results[$topic['id']][$act_type][$key]['price'] = $lowest_price['price'];
126 
127  $results[$topic['id']][$act_type][$key]['price_string'] =
128  ($oPrice->getNumberOfPrices() > 1 ? $this->lng->txt('price_from').' ' : '').
129  ilPaymentPrices::_formatPriceToString($lowest_price['price']);
130  // TODO: CURRENCY ilPaymentPrices::_formatPriceToString($lowest_price['price'], $lowest_price['currency']);
131  // authors
132  include_once 'Services/MetaData/classes/class.ilMD.php';
133  $md_obj = new ilMD($item['obj_id'], 0, $item['type']);
134  if(is_object($md_section = $md_obj->getLifecycle()))
135  {
136  $sep = $ent_str = "";
137  foreach(($ids = $md_section->getContributeIds()) as $con_id)
138  {
139  $md_con = $md_section->getContribute($con_id);
140  if ($md_con->getRole() == "Author")
141  {
142  foreach($ent_ids = $md_con->getEntityIds() as $ent_id)
143  {
144  $md_ent = $md_con->getEntity($ent_id);
145  $ent_str = $ent_str.$sep.$md_ent->getEntity();
146  $sep = ", ";
147  }
148  }
149  }
150  $results[$topic['id']][$act_type][$key]['author'] = $ent_str;
151  }
152  }
153 
154  $results[$topic['id']][$act_type] = $this->sortResult($results[$topic['id']][$act_type]);
155 
156  foreach($results[$topic['id']][$act_type] as $key => $item)
157  {
158  // get list gui class for each object type
159  if ($cur_obj_type != $item['type'])
160  {
161  include_once 'Services/Object/classes/class.ilObjectListGUIFactory.php';
162  $item_list_gui = ilObjectListGUIFactory::_getListGUIByType($item['type']);
163  }
164 
165  $item_list_gui->enableDelete(false);
166  $item_list_gui->enableCut(false);
167  $item_list_gui->enableCopy(false);
168  $item_list_gui->enableLink(false);
169  $item_list_gui->enableSubscribe(false);
170 
171  $item_list_gui->enablePayment(true);
172  $item_list_gui->enableCommands(false);
173  $item_list_gui->enablePath(false);
174  $item_list_gui->insertCommands();
175 
176  $item_list_gui->enableInfoScreen(false);
177  $item_list_gui->enableSubstitutions(false);
178  $item_list_gui->enableNoticeProperties(false);
179  $item_list_gui->enablePreconditions(false);
180  $item_list_gui->enableProperties(false);
181  $item_list_gui->setBoldTitle(true);
182 
183  if(ilPaymentObject::_hasAccess($item['ref_id']))
184  {
185 
186  $item_list_gui->enableInfoScreen(true);
187  $item_list_gui->enableCommands(true);
188  }
189 
190  $tpl_pinfo = new ilTemplate ('tpl.shop_item_info.html', true, true, 'Services/Payment');
191  if($item['price_string'] != '')
192  {
193  $tpl_pinfo->setCurrentBlock('ploop');
194  $tpl_pinfo->setVariable('PROPERTY', $this->lng->txt('price_a'));
195  $tpl_pinfo->setVariable('VALUE', $item['price_string']);
196  $tpl_pinfo->parseCurrentBlock();
197  }
198  if($item['author'] != '')
199  {
200  $tpl_pinfo->setCurrentBlock('ploop');
201  $tpl_pinfo->setVariable('PROPERTY', $this->lng->txt('author'));
202  $tpl_pinfo->setVariable('VALUE', $item['author']);
203  $tpl_pinfo->parseCurrentBlock();
204  }
205  $oFile = new ilFileDataShop(ilPaymentObject::_lookupPobjectId($item['ref_id']));
206  if(($webpath_file = $oFile->getCurrentImageWebPath()) !== false)
207  {
208  $tpl_pinfo->setCurrentBlock('image');
209  $tpl_pinfo->setVariable('SRC', $webpath_file);
210  $tpl_pinfo->setVariable('ALT', $item['title']);
211  $tpl_pinfo->parseCurrentBlock();
212  }
213 
214  $item_list_gui->addSubItemHTML($tpl_pinfo->get());
215 
216  $html = $item_list_gui->getListItemHTML(
217  $item['ref_id'],
218  $item['obj_id'],
219  $item['title'],
220  $item['description']
221  );
222 
223  if($html)
224  {
225  $html = $this->__appendChildLinks($html, $item, $item_list_gui);
226  $item_html[$item['ref_id']] = $html;
227  }
228  }
229 
230  // output block for resource type
231  if(count($item_html) > 0)
232  {
233  // separator row
234  if (!$first)
235  {
236  $this->addSeparatorRow($tpl);
237  }
238  $first = false;
239 
240  // add a header for each resource type
241  $this->addHeaderRow($tpl, $act_type);
242  $this->resetRowType();
243 
244  // content row
245  foreach($item_html as $ref_id => $html)
246  {
247  $this->addStandardRow($tpl, $html, $ref_id);
248  }
249 
250  ++$items_counter;
251  }
252  }
253  }
254 
255  if($items_counter > 0)
256  {
257  $oContainerTpl->setCurrentBlock('loop');
258  $oContainerTpl->setVariable('TOPIC_TITLE', $topic['title']);
259  $oContainerTpl->setVariable('COTAINER_LIST_BLOCK', $tpl->get());
260  $oContainerTpl->parseCurrentBlock();
261  }
262  }
263 
264  public function renderItemList($results)
265  {
266  global $ilUser;
267 
268  $oContainerTpl = new ilTemplate ('tpl.shop_container.html', true, true, 'Services/Payment');
269 
270  foreach($this->result->getTopics() as $oTopic)
271  {
272  $this->renderItems($oContainerTpl, $results, array('id' => $oTopic->getId(), 'title' => $oTopic->getTitle()));
273  }
274  $this->renderItems($oContainerTpl, $results, array('id' => 0, 'title' => $this->lng->txt('payment_no_topic')));
275 
276  return $oContainerTpl->get();
277  }
278 
286  function addStandardRow($a_tpl, $a_html,$a_ref_id)
287  {
288  $this->cur_row_type = ($this->cur_row_type == "row_type_1")
289  ? "row_type_2"
290  : "row_type_1";
291 
292  $a_tpl->touchBlock($this->cur_row_type);
293  $a_tpl->setCurrentBlock("container_standard_row");
294  $a_tpl->setVariable("BLOCK_ROW_CONTENT", $a_html);
295 
296  // add checkbox for saving results
297  #$a_tpl->setVariable("BLOCK_ROW_CHECK",ilUtil::formCheckbox(0,'result[]',$a_ref_id));
298  #$a_tpl->setVariable("ITEM_ID",$a_ref_id);
299  $a_tpl->parseCurrentBlock();
300  $a_tpl->touchBlock("container_row");
301  }
302 
309  function newBlockTemplate()
310  {
311  $tpl = new ilTemplate ("tpl.container_list_block.html",true, true,
312  "Services/Container");
313  $this->cur_row_type = "row_type_1";
314 
315  return $tpl;
316  }
317 
325  function addHeaderRow(&$a_tpl, $a_type)
326  {
327  if ($a_type != "lres")
328  {
329  $icon = ilUtil::getImagePath("icon_".$a_type.".gif");
330  $title = $this->lng->txt("objs_".$a_type);
331  }
332  else
333  {
334  $icon = ilUtil::getImagePath("icon_lm.gif");
335  $title = $this->lng->txt("learning_resources");
336  }
337 
338  $a_tpl->setCurrentBlock("container_header_row_image");
339  $a_tpl->setVariable("HEADER_IMG", $icon);
340  $a_tpl->setVariable("HEADER_ALT", $title);
341  $a_tpl->setVariable("BLOCK_HEADER_CONTENT", $title);
342  $a_tpl->parseCurrentBlock();
343 
344 
345  #$a_tpl->setCurrentBlock("container_header_row");
346  #$a_tpl->parseCurrentBlock();
347  #$a_tpl->touchBlock("container_row");
348  }
349 
350  function addSeparatorRow(&$a_tpl)
351  {
352  $a_tpl->touchBlock("separator_row");
353  $a_tpl->touchBlock("container_row");
354  }
355 
356 
357  function __appendChildLinks($html,$item,&$item_list_gui)
358  {
359  if(!count($item['child']))
360  {
361  return $html;
362  }
363  $tpl = new ilTemplate('tpl.detail_links.html',true,true,'Services/Search');
364  $tpl->setVariable("HITS",$this->lng->txt('search_hits'));
365 
366  switch($item['type'])
367  {
368  case 'lm':
369  include_once 'Modules/LearningModule/classes/class.ilLMObject.php';
370  foreach($item['child'] as $child)
371  {
372  $tpl->setCurrentBlock("link_row");
373 
374  switch(ilLMObject::_lookupType($child))
375  {
376  case 'pg':
377  $tpl->setVariable("CHAPTER_PAGE",$this->lng->txt('obj_pg'));
378  break;
379  case 'st':
380  $tpl->setVariable("CHAPTER_PAGE",$this->lng->txt('obj_st'));
381  break;
382  }
383  $item_list_gui->setChildId($child);
384  $tpl->setVariable("SEPERATOR",' -> ');
385  $tpl->setVariable("LINK",$item_list_gui->getCommandLink('page'));
386  $tpl->setVariable("TARGET",$item_list_gui->getCommandFrame('page'));
387  $tpl->setVariable("TITLE",ilLMObject::_lookupTitle($child));
388  $tpl->parseCurrentBlock();
389  }
390  break;
391 
392  case 'glo':
393  include_once './Modules/Glossary/classes/class.ilGlossaryTerm.php';
394 
395  $this->lng->loadLanguageModule('content');
396  foreach($item['child'] as $child)
397  {
398  $tpl->setCurrentBlock("link_row");
399  $tpl->setVariable("CHAPTER_PAGE",$this->lng->txt('cont_term'));
400  $tpl->setVariable("SEPERATOR",': ');
401  $tpl->setVariable("LINK",ilLink::_getLink($item['ref_id'],'git',array('target' => 'git_'.$child.'_'.$item['ref_id'])));
402  $tpl->setVariable("TITLE",ilGlossaryTerm::_lookGlossaryTerm($child));
403  $tpl->parseCurrentBlock();
404  }
405  break;
406 
407  case 'mcst':
408  include_once("./Services/News/classes/class.ilNewsItem.php");
409 
410  foreach($item['child'] as $child)
411  {
412  $tpl->setCurrentBlock("link_row");
413  //$tpl->setVariable("CHAPTER_PAGE",$this->lng->txt('item'));
414 
415  $item_list_gui->setChildId($child);
416  //$tpl->setVariable("SEPERATOR",': ');
417  $tpl->setVariable("LINK", $item_list_gui->getCommandLink('listItems'));
418  $tpl->setVariable("TARGET", $item_list_gui->getCommandFrame(''));
419  $tpl->setVariable("TITLE", ilNewsItem::_lookupTitle($child));
420  $tpl->parseCurrentBlock();
421  }
422  break;
423 
424  default:
425  ;
426  }
427 
428  return $html . $tpl->get();
429  }
430 
431  function resetRowType()
432  {
433  $this->cur_row_type = "";
434  }
435 }
436 
437 ?>