ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
SubObjectRetrieval.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
26 
28 {
29  protected \ilLanguage $lng;
30  protected \ILIAS\UI\Factory $f;
31  protected ?array $childs = null;
32 
33  public function __construct(
34  protected \ilLMTree $lm_tree,
35  protected $type = "",
36  protected $current_node = 0,
37  protected $transl = ""
38  ) {
39  global $DIC;
40  $this->f = $DIC->ui()->factory();
41  $this->lng = $DIC->language();
42  }
43 
44  public function getChildTitle(array $child): string
45  {
46  if (!in_array($this->transl, ["-", ""])) {
47  $lmobjtrans = new \ilLMObjTranslation($child["child"], $this->transl);
48  return $lmobjtrans->getTitle();
49  }
50  return $child["title"];
51  }
52 
53  protected function getChilds(): array
54  {
55  $current_node = ($this->current_node > 0)
56  ? $this->current_node
57  : $this->lm_tree->readRootId();
58  if (is_null($this->childs)) {
59  $this->childs = $this->lm_tree->getChildsByType($current_node, $this->type);
60  }
61  return $this->childs;
62  }
63 
64  public function getData(
65  array $fields,
66  ?Range $range = null,
67  ?Order $order = null,
68  array $filter = [],
69  array $parameters = []
70  ): \Generator {
71  foreach ($this->getChilds() as $child) {
72  $active = true;
73  $scheduled = false;
74  $deactivated_elements = false;
75  if ($child["type"] === "pg") {
76  // check activation
77  $lm_set = new \ilSetting("lm");
78  $active = \ilLMPage::_lookupActive(
79  $child["obj_id"],
80  "lm",
81  (bool) $lm_set->get("time_scheduled_page_activation")
82  );
83 
84  // is page scheduled?
85  $scheduled = ((bool) $lm_set->get("time_scheduled_page_activation") &&
86  \ilLMPage::_isScheduledActivation($child["obj_id"], "lm"));
87  if ($active) {
88  $deactivated_elements = (\ilLMPage::_lookupContainsDeactivatedElements(
89  $child["obj_id"],
90  "lm"
91  ));
92  }
93  }
94  $trans_title = "";
95  if (!in_array($this->transl, ["-", ""])) {
96  $trans_title = $this->getChildTitle($child);
97  }
98  yield [
99  "id" => $child["child"],
100  "deactivated_elements" => $deactivated_elements,
101  "active" => $active,
102  "scheduled" => $scheduled,
103  "type" => $child["type"],
104  "title" => $child["title"],
105  "trans_title" => $trans_title
106  ];
107  }
108  }
109 
110  public function count(
111  array $filter = [],
112  array $parameters = []
113  ): int {
114  return count($this->getChilds());
115  }
116 
117  public function isFieldNumeric(string $field): bool
118  {
119  return $field === "id";
120  }
121 }
static _lookupActive(int $a_id, string $a_parent_type, bool $a_check_scheduled_activation=false, string $a_lang="-")
lookup activation status
static _isScheduledActivation(int $a_id, string $a_parent_type, string $a_lang="-")
Check whether page is activated by time schedule.
__construct(protected \ilLMTree $lm_tree, protected $type="", protected $current_node=0, protected $transl="")
getData(array $fields, ?Range $range=null, ?Order $order=null, array $filter=[], array $parameters=[])
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Both the subject and the direction need to be specified when expressing an order. ...
Definition: Order.php:28
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static _lookupContainsDeactivatedElements(int $a_id, string $a_parent_type, string $a_lang="-")
lookup whether page contains deactivated elements
count(array $filter=[], array $parameters=[])
global $DIC
Definition: shib_login.php:26
$lm_set
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:28