ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilRepositoryObjectSearchGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
35 {
36  protected ilLanguage $lng;
37  protected ilCtrl $ctrl;
38  protected ilAccess $access;
41  private int $ref_id;
42  private ilObject $object;
43  private object $parent_obj;
44  private string $parent_cmd;
45 
47  protected Factory $refinery;
48 
49 
50 
51 
52 
53  public function __construct(int $a_ref_id, object $a_parent_obj, string $a_parent_cmd)
54  {
55  global $DIC;
56 
57  $this->lng = $DIC->language();
58  $this->ctrl = $DIC->ctrl();
59  $this->access = $DIC->access();
60  $this->tpl = $DIC->ui()->mainTemplate();
61  $this->obj_definition = $DIC['objDefinition'];
62 
63  $this->ref_id = $a_ref_id;
64  $this->http = $DIC->http();
65  $this->refinery = $DIC->refinery();
66 
67  try {
68  $repo_object = ilObjectFactory::getInstanceByRefId($this->getRefId());
69  if ($repo_object instanceof ilObject) {
70  $this->object = $repo_object;
71  }
72  } catch (ilObjectNotFoundException $e) {
73  throw $e;
74  }
75  $this->parent_obj = $a_parent_obj;
76  $this->parent_cmd = $a_parent_cmd;
77  }
78 
79  public static function getSearchBlockHTML(string $a_title): string
80  {
81  $block = new ilRepositoryObjectSearchBlockGUI($a_title);
82  return $block->getHTML();
83  }
84 
85  public function executeCommand(): void
86  {
87  if (!$this->access->checkAccess('read', '', $this->getObject()->getRefId())) {
88  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("permission_denied"), true);
89  $this->getCtrl()->returnToParent($this->getParentGUI());
90  }
91 
92  $next_class = $this->getCtrl()->getNextClass();
93  $cmd = $this->getCtrl()->getCmd();
94 
95 
96  switch ($next_class) {
97  default:
98  $this->$cmd();
99  break;
100  }
101  }
102 
103  public function getLang(): ilLanguage
104  {
105  return $this->lng;
106  }
107 
108  public function getCtrl(): ilCtrl
109  {
110  return $this->ctrl;
111  }
112 
113 
114  public function getRefId(): int
115  {
116  return $this->ref_id;
117  }
118 
119  public function getObject(): ilObject
120  {
121  return $this->object;
122  }
123 
124  public function getParentGUI(): object
125  {
126  return $this->parent_obj;
127  }
128 
129  public function getParentCmd(): string
130  {
131  return $this->parent_cmd;
132  }
133 
137  protected function performSearch(): bool
138  {
139  try {
141 
142  $search_term = '';
143  if ($this->http->wrapper()->post()->has('search_term')) {
144  $search_term = $this->http->wrapper()->post()->retrieve(
145  'search_term',
146  $this->refinery->kindlyTo()->string()
147  );
148  }
149  $search->setQueryString($search_term);
150  $result = $search->performSearch();
151  } catch (Exception $e) {
152  $this->tpl->setOnScreenMessage('failure', $e->getMessage(), true);
153  $this->getCtrl()->returnToParent($this);
154  return false;
155  }
156  // @todo: add a factory to allow overwriting of search result presentation
157  $result_table = $this->getResultTableInstance();
158  $result_table->setSearchTerm($search_term);
159  $result_table->setResults($result);
160 
161  $result_table->init();
162  $result_table->parse();
163 
164  $this->tpl->setContent($result_table->getHTML());
165  return true;
166  }
167 
168  public function getResultTableInstance(): ?object
169  {
170  $class = $this->obj_definition->getClassName($this->getObject()->getType());
171  $full_class = "ilObj" . $class . "SearchResultTableGUI";
172 
173  if (class_exists($full_class)) {
174  return new $full_class(
175  $this,
176  'performSearch',
177  $this->getRefId()
178  );
179  }
180  return null;
181  }
182 }
__construct(int $a_ref_id, object $a_parent_obj, string $a_parent_cmd)
static _lookupObjId(int $ref_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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
global $DIC
Definition: shib_login.php:26