ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilExportLimitation.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
26 {
27  protected const SET_LIMIT_NUMBER = "rep_export_limit_number";
28  protected const SET_LIMITATION = "rep_export_limitation";
29  public const SET_EXPORT_DISABLED = 1;
30  public const SET_EXPORT_LIMITED = 0;
31 
32  protected ilTree $tree;
33  protected ilSetting $settings;
34  protected ilLanguage $lng;
35 
36  public function __construct()
37  {
38  global $DIC;
39 
40  $this->tree = $DIC->repositoryTree();
41  $this->settings = $DIC->settings();
42  $this->lng = $DIC->language();
43  }
44 
45  public function getLimitationMode(): int
46  {
47  return (int) $this->settings->get(self::SET_LIMITATION);
48  }
49 
50  public function getLimitationNumber(): int
51  {
52  return (int) $this->settings->get(self::SET_LIMIT_NUMBER);
53  }
54 
55  public function checkLimitation(int $ref_id, array $options): void
56  {
57  $max = (int) $this->settings->get(self::SET_LIMIT_NUMBER);
58 
59  if ($this->getLimitationMode() == self::SET_EXPORT_DISABLED) {
61  $this->lng->txt("exp_error_disabled")
62  );
63  }
64 
65  $cnt = 0;
66  foreach ($this->tree->getSubTree($root = $this->tree->getNodeData($ref_id)) as $node) {
67  if (isset($options[$node["child"]]) && (in_array((int) $options[$node["child"]]["type"], [1, 2]))) {
68  $cnt++;
69  }
70  }
71  if ($max > 0 && $cnt > $max) {
72  throw new ilExportLimitationExceptionException(str_replace(
73  "%1",
74  (string) $max,
75  $this->lng->txt("exp_error_too_many_objects")
76  ));
77  }
78  }
79 }
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkLimitation(int $ref_id, array $options)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...