ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilPDFCompInstaller.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
26  private const PURPOSE_CONF_TABLE = "pdfgen_conf";
27  private const PURPOSE_MAP_TABLE = "pdfgen_map";
28  private const PURPOSE_PURPOSES_TABLE = "pdfgen_purposes";
29  private const RENDERER_TABLE = "pdfgen_renderer";
30  private const RENDERER_AVAIL_TABLE = "pdfgen_renderer_avail";
31 
32  public static function registerPurpose(string $service, string $purpose, string $preferred): void
33  {
34  self::addPurpose($service, $purpose);
35  self::addPreferred($service, $purpose, $preferred);
36  }
37 
38  protected static function addPurpose(string $service, string $purpose): void
39  {
40  global $DIC;
41  $ilDB = $DIC->database();
42 
43  $ilDB->insert(
44  self::PURPOSE_PURPOSES_TABLE,
45  [
46  'purpose_id' => ['int', $ilDB->nextId(self::PURPOSE_PURPOSES_TABLE)],
47  'service' => ['text', $service],
48  'purpose' => ['text', $purpose],
49  ]
50  );
51  }
52 
53  protected static function addPreferred(string $service, string $purpose, string $preferred): void
54  {
55  global $DIC;
56  $ilDB = $DIC->database();
57  $ilDB->insert(
58  self::PURPOSE_MAP_TABLE,
59  [
60  'map_id' => ['int', $ilDB->nextId(self::PURPOSE_MAP_TABLE)],
61  'service' => ['text', $service],
62  'purpose' => ['text', $purpose],
63  'preferred' => ['text', $preferred],
64  'selected' => ['text', $preferred]
65  ]
66  );
67  }
68 
69  public static function unregisterPurpose(string $service, string $purpose): void
70  {
71  global $DIC;
72  $ilDB = $DIC->database();
73 
74  $ilDB->manipulate("DELETE FROM " . self::PURPOSE_PURPOSES_TABLE .
75  " WHERE service = " . $ilDB->quote($service, "text") . " AND purpose = " . $ilDB->quote($purpose, "text"));
76  }
77 
78  public static function unregisterPreferred(string $service, string $purpose, string $preferred): void
79  {
80  global $DIC;
81  $ilDB = $DIC->database();
82 
83  $ilDB->manipulate("DELETE FROM " . self::PURPOSE_MAP_TABLE .
84  " WHERE service = " . $ilDB->quote($service, "text") . " AND purpose = " . $ilDB->quote($purpose, "text") .
85  " AND preferred = " . $ilDB->quote($preferred, "text"));
86  }
87 
88  public static function flushPurposes(string $service): void
89  {
90  global $DIC;
91  $ilDB = $DIC->database();
92 
93  $ilDB->manipulate("DELETE FROM " . self::PURPOSE_PURPOSES_TABLE . " WHERE service = " . $ilDB->quote(
94  $service,
95  "text"
96  ));
97  }
98 
99  public static function isPurposeRegistered(string $service, string $purpose): bool
100  {
101  global $DIC;
102  $ilDB = $DIC->database();
103 
104  $query = 'SELECT count(*) num FROM ' . self::PURPOSE_PURPOSES_TABLE . ' WHERE service = '
105  . $ilDB->quote($service, 'text') . ' AND purpose = ' . $ilDB->quote($purpose, 'text');
106  $result = $ilDB->query($query);
107  $row = $ilDB->fetchAssoc($result);
108 
109  return is_array($row) && (int) $row['num'] !== 0;
110  }
111 
116  public static function getPurposesByService(string $service): array
117  {
118  global $DIC;
119  $ilDB = $DIC->database();
120 
121  $query = 'SELECT purpose FROM ' . self::PURPOSE_PURPOSES_TABLE . ' WHERE service = ' . $ilDB->quote(
122  $service,
123  'text'
124  );
125  $result = $ilDB->query($query);
126  $purposes = [];
127  while ($row = $ilDB->fetchAssoc($result)) {
128  $purposes[] = $row['purpose'];
129  }
130  return $purposes;
131  }
132 
136  public static function getServices(): array
137  {
138  global $DIC;
139  $ilDB = $DIC->database();
140 
141  $query = 'SELECT service FROM ' . self::PURPOSE_PURPOSES_TABLE . ' GROUP BY service';
142  $result = $ilDB->query($query);
143  $services = [];
144  while ($row = $ilDB->fetchAssoc($result)) {
145  $services[] = $row['service'];
146  }
147  return $services;
148  }
149 
150  public static function checkForMultipleServiceAndPurposeCombination(): bool
151  {
152  global $DIC;
153  $ilDB = $DIC->database();
154  $query = 'SELECT service, purpose FROM ' . self::PURPOSE_PURPOSES_TABLE . ' GROUP BY service, purpose having count(*) > 1';
155  $result = $ilDB->query($query);
156  $row = $ilDB->fetchAssoc($result);
157 
158  return is_array($row) && !empty($row);
159  }
160 
161  public static function doCleanUp(): void
162  {
163  global $DIC;
164  $ilDB = $DIC->database();
165  $query = 'SELECT service, purpose FROM ' . self::PURPOSE_PURPOSES_TABLE . ' GROUP BY service, purpose having count(*) > 1';
166  $result = $ilDB->query($query);
167  while ($row = $ilDB->fetchAssoc($result)) {
168  self::unregisterPurpose($row['service'], $row['purpose']);
169  self::addPurpose($row['service'], $row['purpose']);
170  }
171 
172  $query = 'SELECT service, purpose, preferred FROM ' . self::PURPOSE_MAP_TABLE . ' GROUP BY service, purpose, preferred having count(*) > 1';
173 
174  $result = $ilDB->query($query);
175  while ($row = $ilDB->fetchAssoc($result)) {
176  self::unregisterPreferred($row['service'], $row['purpose'], $row['preferred']);
177  self::addPreferred($row['service'], $row['purpose'], $row['preferred']);
178  }
179  }
180 
181  public static function updateFromXML(string $service, string $purpose, string $preferred): void
182  {
183  $parts = explode('/', $service);
184  $service = $parts[1];
185 
186  if (!self::isPurposeRegistered($service, $purpose)) {
187  self::registerPurpose($service, $purpose, $preferred);
188  }
189  }
190 
191  public static function registerRenderer(string $renderer, string $path): void
192  {
193  global $DIC;
194  $ilDB = $DIC->database();
195 
196  $ilDB->insert(
197  self::RENDERER_TABLE,
198  [
199  'renderer_id' => ['int', $ilDB->nextId(self::RENDERER_TABLE)],
200  'renderer' => ['text', $renderer],
201  'path' => ['text', $path]
202  ]
203  );
204  }
205 
206  public static function registerRendererAvailability(string $renderer, string $service, string $purpose): void
207  {
208  global $DIC;
209  $ilDB = $DIC->database();
210 
211  $ilDB->insert(
212  self::RENDERER_AVAIL_TABLE,
213  [
214  'availability_id' => ['int', $ilDB->nextId(self::RENDERER_AVAIL_TABLE)],
215  'service' => ['text', $service],
216  'purpose' => ['text', $purpose],
217  'renderer' => ['text', $renderer]
218  ]
219  );
220  }
221 }
static registerRenderer(string $renderer, string $path)
static unregisterPurpose(string $service, string $purpose)
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:64
static registerPurpose(string $service, string $purpose, string $preferred)
static unregisterPreferred(string $service, string $purpose, string $preferred)
static flushPurposes(string $service)
static getPurposesByService(string $service)
static updateFromXML(string $service, string $purpose, string $preferred)
$path
Definition: ltiservices.php:32
global $DIC
Definition: feed.php:28
static addPreferred(string $service, string $purpose, string $preferred)
$query
static addPurpose(string $service, string $purpose)
static registerRendererAvailability(string $renderer, string $service, string $purpose)
static isPurposeRegistered(string $service, string $purpose)
$service
Definition: ltiservices.php:43
static checkForMultipleServiceAndPurposeCombination()