ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilRepositoryObjectSearchGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
5 
8 
20 {
21  protected ilLanguage $lng;
22  protected ilCtrl $ctrl;
23  protected ilAccess $access;
26  private int $ref_id;
27  private ilObject $object;
28  private object $parent_obj;
29  private string $parent_cmd;
30 
32  protected Factory $refinery;
33 
34 
35 
36 
37 
38  public function __construct(int $a_ref_id, object $a_parent_obj, string $a_parent_cmd)
39  {
40  global $DIC;
41 
42  $this->lng = $DIC->language();
43  $this->ctrl = $DIC->ctrl();
44  $this->access = $DIC->access();
45  $this->tpl = $DIC->ui()->mainTemplate();
46  $this->obj_definition = $DIC['objDefinition'];
47 
48  $this->ref_id = $a_ref_id;
49  $this->http = $DIC->http();
50  $this->refinery = $DIC->refinery();
51 
52  try {
53  $repo_object = ilObjectFactory::getInstanceByRefId($this->getRefId());
54  if ($repo_object instanceof ilObject) {
55  $this->object = $repo_object;
56  }
57  } catch (ilObjectNotFoundException $e) {
58  throw $e;
59  }
60  $this->parent_obj = $a_parent_obj;
61  $this->parent_cmd = $a_parent_cmd;
62  }
63 
64  public static function getSearchBlockHTML(string $a_title): string
65  {
66  $block = new ilRepositoryObjectSearchBlockGUI($a_title);
67  return $block->getHTML();
68  }
69 
70  public function executeCommand(): void
71  {
72  if (!$this->access->checkAccess('read', '', $this->getObject()->getRefId())) {
73  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
74  $this->getCtrl()->returnToParent($this->getParentGUI());
75  }
76 
77  $next_class = $this->getCtrl()->getNextClass();
78  $cmd = $this->getCtrl()->getCmd();
79 
80 
81  switch ($next_class) {
82  default:
83  $this->$cmd();
84  break;
85  }
86  }
87 
88  public function getLang(): ilLanguage
89  {
90  return $this->lng;
91  }
92 
93  public function getCtrl(): ilCtrl
94  {
95  return $this->ctrl;
96  }
97 
98 
99  public function getRefId(): int
100  {
101  return $this->ref_id;
102  }
103 
104  public function getObject(): ilObject
105  {
106  return $this->object;
107  }
108 
109  public function getParentGUI(): object
110  {
111  return $this->parent_obj;
112  }
113 
114  public function getParentCmd(): string
115  {
116  return $this->parent_cmd;
117  }
118 
122  protected function performSearch(): bool
123  {
124  try {
126 
127  $search_term = '';
128  if ($this->http->wrapper()->post()->has('search_term')) {
129  $search_term = $this->http->wrapper()->post()->retrieve(
130  'search_term',
131  $this->refinery->kindlyTo()->string()
132  );
133  }
134  $search->setQueryString($search_term);
135  $result = $search->performSearch();
136  } catch (Exception $e) {
137  $this->tpl->setOnScreenMessage('failure', $e->getMessage(), true);
138  $this->getCtrl()->returnToParent($this);
139  return false;
140  }
141  // @todo: add a factory to allow overwriting of search result presentation
142  $result_table = $this->getResultTableInstance();
143  $result_table->setSearchTerm($search_term);
144  $result_table->setResults($result);
145 
146  $result_table->init();
147  $result_table->parse();
148 
149  $this->tpl->setContent($result_table->getHTML());
150  return true;
151  }
152 
153  public function getResultTableInstance(): ?object
154  {
155  $class = $this->obj_definition->getClassName($this->getObject()->getType());
156  $location = $this->obj_definition->getLocation($this->getObject()->getType());
157  $full_class = "ilObj" . $class . "SearchResultTableGUI";
158 
159  if (include_once($location . "/class." . $full_class . ".php")) {
160  return new $full_class(
161  $this,
162  'performSearch',
163  $this->getRefId()
164  );
165  }
166  return null;
167  }
168 }
Interface GlobalHttpState.
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: buildRTE.php:22
__construct(int $a_ref_id, object $a_parent_obj, string $a_parent_cmd)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
parses the objects.xml it handles the xml-description of all ilias objects
static http()
Fetches the global http state from ILIAS.
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id