ILIAS  release_4-3 Revision
 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 include_once 'Services/Payment/classes/class.ilShopUtils.php';
8 
18 {
19  protected $search_cache = null;
20 
21  public $tpl;
22  public $lng;
23 
24  public $result = 0;
25 
26 
27  private $sort_field = '';
28  private $sort_direction = '';
29 
31  {
32  global $lng,$ilCtrl,$ilUser;
33 
34  $this->lng = $lng;
35 
36  $this->result = $result;
37 
38  $this->type_ordering = array(
39  "cat", "crs", "grp", "chat", "frm", "wiki", "lres",
40  "glo", "webr", "lm", "sahs", "htlm", "file",'mcst', "exc",
41  "tst", "svy", "sess","mep", "qpl", "spl");
42 
43  $this->ctrl = $ilCtrl;
44 
45  include_once('Services/Search/classes/class.ilUserSearchCache.php');
46  $this->search_cache = ilUserSearchCache::_getInstance($ilUser->getId());
47 
48  }
49 
50  public function showResults()
51  {
52  // Get results
53  $results = $this->result->getResultsForPresentation();
54  $html = $this->renderItemList($results);
55  return $html;
56  }
57 
58  public function showSpecials()
59  {
60  // Get specials
61 
62  $oContainerTpl = new ilTemplate ('tpl.shop_container.html', true, true, 'Services/Payment');
63  include_once './Services/Payment/classes/class.ilShopTopic.php';
64  include_once './Services/Payment/classes/class.ilShopTopics.php';
66 
67  ilShopTopics::_getInstance()->setIdFilter(false);
69 
70  if(count($topics = ilShopTopics::_getInstance()->getTopics()))
71  {
72  foreach($topics as $oTopic)
73  {
74  $this->renderItems($oContainerTpl, $results, array('id' => $oTopic->getId(), 'title' => $oTopic->getTitle()));
75  }
76  $this->renderItems($oContainerTpl, $results, array('id' => 0, 'title' => $this->lng->txt('payment_no_topic')));
77  }
78  else
79  {
80  $this->renderItems($oContainerTpl, $results, array('id' => 0, 'title' => $this->lng->txt('payment_no_topic')));
81  }
82 
83  $html = $oContainerTpl->get();
84 
85  return $html;
86  }
87 
88  public function setTypeOrdering($a_type_ordering_array)
89  {
90  $this->type_ordering = $a_type_ordering_array;
91  }
92  public function getTypeOrdering()
93  {
94  return $this->type_ordering;
95  }
96  public function setSortField($a_sort_field)
97  {
98  $this->sort_field = $a_sort_field;
99  }
100  public function getSortField()
101  {
102  return $this->sort_field;
103  }
104  public function setSortDirection($a_sort_direction)
105  {
106  $this->sort_direction = $a_sort_direction;
107  }
108  public function getSortDirection()
109  {
110  return $this->sort_direction;
111  }
112 
113  public function sortResult($result)
114  {
115  if ($this->sort_direction != '' && $this->sort_field != '')
116  {
117  switch ($this->sort_field)
118  {
119  case 'price':
120  $numeric_sort = true;
121  break;
122  default:
123  $numeric_sort = false;
124  break;
125  }
126 
127  $result = ilUtil::sortArray($result, $this->sort_field, $this->sort_direction, $numeric_sort);
128  }
129 
130  return $result;
131  }
132 
133  private function renderItems($oContainerTpl, $results, $topic)
134  {
135  // main shop_content
136  global $ilUser;
137 
138  $items_counter = 0;
139 
140  $cur_obj_type = '';
141  $tpl = $this->newBlockTemplate();
142  $first = true;
143 
144  foreach($this->type_ordering as $act_type)
145  {
146  $item_html = array();
147 
148  if(count($results[$topic['id']][$act_type]))
149  {
150  foreach($results[$topic['id']][$act_type] as $key => $item)
151  {
152  // price presentation
153  $oPaymentObject =
154  new ilPaymentObject($ilUser, ilPaymentObject::_lookupPobjectId($item['ref_id']));
155  $oPrice = new ilPaymentPrices((int)$oPaymentObject->getPobjectId());
156  $lowest_price = $oPrice->getLowestPrice();
157 
158  $special_icon = ' ';
159  if($oPaymentObject->getSpecial() == '1')
160  {
161  $special_icon = ilShopUtils::_getSpecialObjectSymbol();
162  }
163  $results[$topic['id']][$act_type][$key]['title'] = $item['title'].' '.
164  //special icon
165  $results[$topic['id']][$act_type][$key]['special_icon'] = $special_icon;
166 
167  $results[$topic['id']][$act_type][$key]['price'] = $lowest_price['price'];
168 
169  $paymethod_icon = ilShopUtils::_getPaymethodSymbol($oPaymentObject->getPayMethod());
170 // if(!ilPaymentObject::_hasAccess($item['ref_id']))
171 // {
172  $shoppingcart_icon = ilShopUtils::_addToShoppingCartSymbol($act_type, $item['ref_id']);
173 // }
174 // else $shoppingcart_icon = '';
175 
176  $results[$topic['id']][$act_type][$key]['price_string'] =
177  ($oPrice->getNumberOfPrices() > 1 ? $this->lng->txt('price_from').' ' : '').
178  ilPaymentPrices::_formatPriceToString($lowest_price['price']).' '.
179 
180  //shoppingcart icon
181  $results[$topic['id']][$act_type][$key]['shoppingcart_icon'] = $shoppingcart_icon.' '.
182  // paymethod icon
183  $results[$topic['id']][$act_type][$key]['paymethod_icon'] = $paymethod_icon;
184 
185  // authors
186  include_once 'Services/MetaData/classes/class.ilMD.php';
187  $md_obj = new ilMD($item['obj_id'], 0, $item['type']);
188  if(is_object($md_section = $md_obj->getLifecycle()))
189  {
190  $sep = $ent_str = "";
191  foreach(($ids = $md_section->getContributeIds()) as $con_id)
192  {
193  $md_con = $md_section->getContribute($con_id);
194  if ($md_con->getRole() == "Author")
195  {
196  foreach($ent_ids = $md_con->getEntityIds() as $ent_id)
197  {
198  $md_ent = $md_con->getEntity($ent_id);
199  $ent_str = $ent_str.$sep.$md_ent->getEntity();
200  $sep = ", ";
201  }
202  }
203  }
204  $results[$topic['id']][$act_type][$key]['author'] = $ent_str;
205  }
206  }
207 
208  $results[$topic['id']][$act_type] = $this->sortResult($results[$topic['id']][$act_type]);
209 
210  foreach($results[$topic['id']][$act_type] as $key => $item)
211  {
212  // get list gui class for each object type
213  if ($cur_obj_type != $item['type'])
214  {
215  include_once 'Services/Object/classes/class.ilObjectListGUIFactory.php';
216  $item_list_gui = ilObjectListGUIFactory::_getListGUIByType($item['type']);
217  }
218  $item_list_gui->initItem(
219  $item['ref_id'],
220  $item['obj_id'],
221  $item['title'],
222  $item['description'],
224  );
225  $item_list_gui->enableDelete(false);
226  $item_list_gui->enableCut(false);
227  $item_list_gui->enableCopy(false);
228  $item_list_gui->enableLink(false);
229  $item_list_gui->enableSubscribe(false);
230 
231  $item_list_gui->enablePayment(true);
232  $item_list_gui->enableCommands(true);
233  $item_list_gui->enablePath(false);
234  $item_list_gui->insertCommands();
235 
236  $item_list_gui->enableInfoScreen(false);
237  $item_list_gui->enableSubstitutions(false);
238  $item_list_gui->enableNoticeProperties(false);
239  $item_list_gui->enablePreconditions(false);
240  $item_list_gui->enableProperties(false);
241  $item_list_gui->setBoldTitle(true);
242 
243  if(ilPaymentObject::_hasAccess($item['ref_id']))
244  {
245 
246  $item_list_gui->enableInfoScreen(true);
247  $item_list_gui->enableCommands(true);
248  }
249  else
250  {
251  switch ($item['type'])
252  {
253  case 'sahs':
254  $demo_link = 'ilias.php?baseClass=ilSAHSPresentationGUI&ref_id='.$item['ref_id'].'&purchasetype=demo';
255  break;
256 
257  case 'lm':
258  $demo_link = 'ilias.php?baseClass=ilLMPresentationGUI&ref_id='.$item['ref_id'].'&purchasetype=demo';
259  break;
260 
261  case 'exc':
262  $demo_link = $this->ctrl->getLinkTargetByClass('ilshoppurchasegui', 'showDemoVersion').'&purchasetype=demo&ref_id='.$item["ref_id"];
263  break;
264 
265  default:
266  $demo_link = $this->ctrl->getLinkTargetByClass('ilshoppurchasegui', 'showDemoVersion').'&purchasetype=demo&ref_id='.$item["ref_id"];
267  break;
268  }
269 
270  $item['title'] = '<a href="'.$demo_link.'">'.$item["title"].'</a>';
271  }
272 
273  $tpl_pinfo = new ilTemplate ('tpl.shop_item_info.html', true, true, 'Services/Payment');
274  if($item['price_string'] != '')
275  {
276  $tpl_pinfo->setCurrentBlock('ploop');
277  $tpl_pinfo->setVariable('PROPERTY', $this->lng->txt('price_a'));
278  $tpl_pinfo->setVariable('VALUE', $item['price_string']);
279  $tpl_pinfo->parseCurrentBlock();
280  }
281  if($item['author'] != '')
282  {
283  $tpl_pinfo->setCurrentBlock('ploop');
284  $tpl_pinfo->setVariable('PROPERTY', $this->lng->txt('author'));
285  $tpl_pinfo->setVariable('VALUE', $item['author']);
286  $tpl_pinfo->parseCurrentBlock();
287  }
288  $oFile = new ilFileDataShop(ilPaymentObject::_lookupPobjectId($item['ref_id']));
289  if(($webpath_file = $oFile->getCurrentImageWebPath()) !== false)
290  {
291  $tpl_pinfo->setCurrentBlock('image');
292  $tpl_pinfo->setVariable('SRC', $webpath_file);
293  $tpl_pinfo->setVariable('ALT', strip_tags($item['title']));
294  $tpl_pinfo->parseCurrentBlock();
295  }
296 
297  $item_list_gui->addSubItemHTML($tpl_pinfo->get());
298 
299  $html = $item_list_gui->getListItemHTML(
300  $item['ref_id'],
301  $item['obj_id'],
302  $item['title'],
303  $item['description'],
304  false, false, "",
306  );
307 
308  if($html)
309  {
310  $html = $this->__appendChildLinks($html, $item, $item_list_gui);
311  $item_html[$item['ref_id']] = $html;
312  }
313  }
314 
315  // output block for resource type
316  if(count($item_html) > 0)
317  {
318  // separator row
319  if (!$first)
320  {
321  $this->addSeparatorRow($tpl);
322  }
323  $first = false;
324 
325  // add a header for each resource type
326  $this->addHeaderRow($tpl, $act_type);
327  $this->resetRowType();
328 
329  // content row
330  foreach($item_html as $ref_id => $html)
331  {
332  $this->addStandardRow($tpl, $html, $ref_id);
333  }
334 
335  ++$items_counter;
336  }
337  }
338  }
339  if($items_counter > 0)
340  {
341  $oContainerTpl->setCurrentBlock('loop');
342  $oContainerTpl->setVariable('TOPIC_TITLE', $topic['title']);
343  $oContainerTpl->setVariable('COTAINER_LIST_BLOCK', $tpl->get());
344  $oContainerTpl->parseCurrentBlock();
345 
346  global $tpl;
347  $tpl->setContent($oContainerTpl->get());
348  }
349  }
350 
351  public function renderItemList($results)
352  {
353  $oContainerTpl = new ilTemplate ('tpl.shop_container.html', true, true, 'Services/Payment');
354 
355  foreach($this->result->getTopics() as $oTopic)
356  {
357  $this->renderItems($oContainerTpl, $results, array('id' => $oTopic->getId(), 'title' => $oTopic->getTitle()));
358  }
359  $this->renderItems($oContainerTpl, $results, array('id' => 0, 'title' => $this->lng->txt('payment_no_topic')));
360 
361  return $oContainerTpl->get();
362  }
363 
369  public function addStandardRow($a_tpl, $a_html,$a_ref_id)
370  {
371  $this->cur_row_type = ($this->cur_row_type == "row_type_1")
372  ? "row_type_2"
373  : "row_type_1";
374 
375  $a_tpl->touchBlock($this->cur_row_type);
376  $a_tpl->setCurrentBlock("container_standard_row");
377  $a_tpl->setVariable("BLOCK_ROW_CONTENT", $a_html);
378 
379  // add checkbox for saving results
380  #$a_tpl->setVariable("BLOCK_ROW_CHECK",ilUtil::formCheckbox(0,'result[]',$a_ref_id));
381  #$a_tpl->setVariable("ITEM_ID",$a_ref_id);
382  $a_tpl->parseCurrentBlock();
383  $a_tpl->touchBlock("container_row");
384  }
385 
392  public function newBlockTemplate()
393  {
394  $tpl = new ilTemplate ("tpl.container_list_block.html",true, true,
395  "Services/Container");
396  $this->cur_row_type = "row_type_1";
397 
398  return $tpl;
399  }
400 
408  public function addHeaderRow(&$a_tpl, $a_type)
409  {
410  if ($a_type != "lres")
411  {
412  $icon = ilUtil::getImagePath("icon_".$a_type.".png");
413  $title = $this->lng->txt("objs_".$a_type);
414  }
415  else
416  {
417  $icon = ilUtil::getImagePath("icon_lm.png");
418  $title = $this->lng->txt("learning_resources");
419  }
420 
421  $a_tpl->setCurrentBlock("container_header_row_image");
422  $a_tpl->setVariable("HEADER_IMG", $icon);
423  $a_tpl->setVariable("HEADER_ALT", $title);
424  $a_tpl->setVariable("BLOCK_HEADER_CONTENT", $title);
425  $a_tpl->parseCurrentBlock();
426 
427 
428  #$a_tpl->setCurrentBlock("container_header_row");
429  #$a_tpl->parseCurrentBlock();
430  #$a_tpl->touchBlock("container_row");
431  }
432 
433  public function addSeparatorRow(&$a_tpl)
434  {
435  $a_tpl->touchBlock("separator_row");
436  $a_tpl->touchBlock("container_row");
437  }
438 
439 
440  public function __appendChildLinks($html,$item,&$item_list_gui)
441  {
442  if(!count($item['child']))
443  {
444  return $html;
445  }
446  $tpl = new ilTemplate('tpl.detail_links.html',true,true,'Services/Search');
447 
448  switch($item['type'])
449  {
450  case 'lm':
451  $tpl->setVariable("HITS",$this->lng->txt('search_hits'));
452  include_once 'Modules/LearningModule/classes/class.ilLMObject.php';
453  foreach($item['child'] as $child)
454  {
455  $tpl->setCurrentBlock("link_row");
456 
457  switch(ilLMObject::_lookupType($child))
458  {
459  case 'pg':
460  $tpl->setVariable("CHAPTER_PAGE",$this->lng->txt('obj_pg'));
461  break;
462  case 'st':
463  $tpl->setVariable("CHAPTER_PAGE",$this->lng->txt('obj_st'));
464  break;
465  }
466  $item_list_gui->setChildId($child);
467  $tpl->setVariable("SEPERATOR",' -> ');
468  $tpl->setVariable("LINK",$item_list_gui->getCommandLink('page'));
469  $tpl->setVariable("TARGET",$item_list_gui->getCommandFrame('page'));
470  $tpl->setVariable("TITLE",ilLMObject::_lookupTitle($child));
471  $tpl->parseCurrentBlock();
472  }
473  break;
474 
475  case 'frm':
476  $tpl->setVariable("HITS",$this->lng->txt('search_hits'));
477  include_once './Modules/Forum/classes/class.ilObjForum.php';
478 
479  foreach($item['child'] as $child)
480  {
481  $thread_post = explode('_',$child);
482 
483  $tpl->setCurrentBlock("link_row");
484  $tpl->setVariable("CHAPTER_PAGE",$this->lng->txt('thread'));
485 
486  $item_list_gui->setChildId($thread_post);
487  $tpl->setVariable("SEPERATOR",': ');
488  $tpl->setVariable("LINK",$item_list_gui->getCommandLink('posting'));
489  $tpl->setVariable("TARGET",$item_list_gui->getCommandFrame(''));
490  $tpl->setVariable("TITLE",ilObjForum::_lookupThreadSubject($thread_post[0]));
491  $tpl->parseCurrentBlock();
492  }
493  break;
494 
495  case 'glo':
496  $tpl->setVariable("HITS",$this->lng->txt('search_hits'));
497  include_once './Modules/Glossary/classes/class.ilGlossaryTerm.php';
498 
499  $this->lng->loadLanguageModule('content');
500  foreach($item['child'] as $child)
501  {
502  $tpl->setCurrentBlock("link_row");
503  $tpl->setVariable("CHAPTER_PAGE",$this->lng->txt('cont_term'));
504  $tpl->setVariable("SEPERATOR",': ');
505  $tpl->setVariable("LINK",ilLink::_getLink($item['ref_id'],'git',array('target' => 'git_'.$child.'_'.$item['ref_id'])));
506  $tpl->setVariable("TITLE",ilGlossaryTerm::_lookGlossaryTerm($child));
507  $tpl->parseCurrentBlock();
508  }
509  break;
510 
511  case 'wiki':
512  $tpl->setVariable("HITS",$this->lng->txt('search_hits'));
513  include_once './Modules/Wiki/classes/class.ilWikiPage.php';
514  include_once './Modules/Wiki/classes/class.ilWikiUtil.php';
515 
516  $this->lng->loadLanguageModule('wiki');
517  foreach($item['child'] as $child)
518  {
519  $page_title = ilWikiPage::lookupTitle($child);
520  $tpl->setCurrentBlock("link_row");
521  $tpl->setVariable("CHAPTER_PAGE",$this->lng->txt('wiki_page'));
522  $tpl->setVariable("SEPERATOR",': ');
523  $tpl->setVariable("LINK",ilLink::_getLink($item['ref_id'],'wiki',array(), "_".
524  ilWikiUtil::makeUrlTitle($page_title)));
525  $tpl->setVariable("TITLE", $page_title);
526  $tpl->parseCurrentBlock();
527  }
528  break;
529 
530  case 'mcst':
531  $tpl->setVariable("HITS",$this->lng->txt('search_hits'));
532  include_once("./Services/News/classes/class.ilNewsItem.php");
533 
534  foreach($item['child'] as $child)
535  {
536  $tpl->setCurrentBlock("link_row");
537  //$tpl->setVariable("CHAPTER_PAGE",$this->lng->txt('item'));
538 
539  $item_list_gui->setChildId($child);
540  //$tpl->setVariable("SEPERATOR",': ');
541  $tpl->setVariable("LINK", $item_list_gui->getCommandLink('listItems'));
542  $tpl->setVariable("TARGET", $item_list_gui->getCommandFrame(''));
543  $tpl->setVariable("TITLE", ilNewsItem::_lookupTitle($child));
544  $tpl->parseCurrentBlock();
545  }
546  break;
547 
548  default:
549  ;
550  }
551 
552  return $html . $tpl->get();
553  }
554 
555  public function resetRowType()
556  {
557  $this->cur_row_type = "";
558  }
559 }