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