ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilCertificateTemplateRepository Class Reference
+ Collaboration diagram for ilCertificateTemplateRepository:

Public Member Functions

 __construct (\ilDBInterface $database, \ilLogger $logger=null, \ilObjectDataCache $objectDataCache=null)
 
 save (ilCertificateTemplate $certificateTemplate)
 
 updateActivity (ilCertificateTemplate $certificateTemplate, bool $currentlyActive)
 
 fetchTemplate (int $templateId)
 
 fetchCertificateTemplatesByObjId (int $objId)
 
 fetchCurrentlyUsedCertificate (int $objId)
 
 fetchCurrentlyActiveCertificate (int $objId)
 
 fetchPreviousCertificate (int $objId)
 Fetch latest created certificate EVEN IF it is deleted. More...
 
 deleteTemplate (int $templateId, int $objectId)
 
 fetchActiveTemplatesByType (string $type)
 
 fetchFirstCreatedTemplate (int $objId)
 

Private Member Functions

 deactivatePreviousTemplates (int $objId)
 
 createCertificateTemplate (array $row)
 

Private Attributes

 $database
 
 $logger
 
 $objectDataCache
 

Detailed Description

Author
Niels Theen nthee.nosp@m.n@da.nosp@m.tabay.nosp@m..de

Repository that allows interaction with the database in the context of certificate templates.

Definition at line 10 of file class.ilCertificateTemplateRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ilCertificateTemplateRepository::__construct ( \ilDBInterface  $database,
\ilLogger  $logger = null,
\ilObjectDataCache  $objectDataCache = null 
)
Parameters
\ilDBInterface$database
\ilLogger$logger
\ilObjectDataCache | null$objectDataCache

Definition at line 32 of file class.ilCertificateTemplateRepository.php.

References $database, $DIC, $logger, and $objectDataCache.

36  {
37  $this->database = $database;
38 
39  if (null === $logger) {
40  global $DIC;
41  $logger = $logger = $DIC->logger()->cert();
42  }
43  $this->logger = $logger;
44 
45  if (null === $objectDataCache) {
46  global $DIC;
47  $objectDataCache = $DIC['ilObjDataCache'];
48  }
49  $this->objectDataCache = $objectDataCache;
50  }
global $DIC
Definition: saml.php:7

Member Function Documentation

◆ createCertificateTemplate()

ilCertificateTemplateRepository::createCertificateTemplate ( array  $row)
private
Parameters
array$row
Returns
ilCertificateTemplate

Definition at line 373 of file class.ilCertificateTemplateRepository.php.

Referenced by fetchActiveTemplatesByType(), fetchCertificateTemplatesByObjId(), fetchCurrentlyActiveCertificate(), fetchCurrentlyUsedCertificate(), fetchFirstCreatedTemplate(), and fetchTemplate().

374  {
375  return new ilCertificateTemplate(
376  $row['obj_id'],
377  $row['obj_type'],
378  $row['certificate_content'],
379  $row['certificate_hash'],
380  $row['template_values'],
381  $row['version'],
382  $row['ilias_version'],
383  $row['created_timestamp'],
384  (boolean) $row['currently_active'],
385  $row['background_image_path'],
386  $row['thumbnail_image_path'],
387  $row['id']
388  );
389  }
$row
+ Here is the caller graph for this function:

◆ deactivatePreviousTemplates()

ilCertificateTemplateRepository::deactivatePreviousTemplates ( int  $objId)
private
Parameters
int$objId
Exceptions
ilDatabaseException

Definition at line 355 of file class.ilCertificateTemplateRepository.php.

Referenced by save().

356  {
357  $this->logger->info(sprintf('START - Deactivate previous certificate template for object: "%s"', $objId));
358 
359  $sql = '
360 UPDATE il_cert_template
361 SET currently_active = 0
362 WHERE obj_id = ' . $this->database->quote($objId, 'integer');
363 
364  $this->database->manipulate($sql);
365 
366  $this->logger->info(sprintf('END - Certificate template deactivated for object: "%s"', $objId));
367  }
+ Here is the caller graph for this function:

◆ deleteTemplate()

ilCertificateTemplateRepository::deleteTemplate ( int  $templateId,
int  $objectId 
)
Parameters
int$templateId
int$objectId
Exceptions
ilDatabaseException

Definition at line 256 of file class.ilCertificateTemplateRepository.php.

References $certificate, $certificates, and fetchCertificateTemplatesByObjId().

257  {
258  $this->logger->info(sprintf('START - Set deleted flag for certificate template("%s") for object: "%s"', $templateId, $objectId));
259 
260  $sql = '
261 UPDATE il_cert_template
262 SET deleted = 1, currently_active = 0
263 WHERE id = ' . $this->database->quote($templateId, 'integer') . '
264 AND obj_id = ' . $this->database->quote($objectId, 'integer');
265 
266  $this->database->manipulate($sql);
267 
268  $this->logger->info(sprintf('END - Deleted flag set fo certificate template("%s") for object: "%s"', $templateId, $objectId));
269  }
+ Here is the call graph for this function:

◆ fetchActiveTemplatesByType()

ilCertificateTemplateRepository::fetchActiveTemplatesByType ( string  $type)
Parameters
string$type
Returns
ilCertificateTemplate[]

Definition at line 307 of file class.ilCertificateTemplateRepository.php.

References $query, $result, $row, and createCertificateTemplate().

307  : array
308  {
309  $this->logger->info(sprintf('START - Fetch all active certificate templates for object type: "%s"', $type));
310 
311  $sql = 'SELECT * FROM il_cert_template WHERE obj_type = ' . $this->database->quote($type, 'text') . '
312 AND currently_active = 1';
313  $query = $this->database->query($sql);
314 
315  $result = array();
316  while ($row = $this->database->fetchAssoc($query)) {
318  }
319 
320  $this->logger->info(sprintf('END - All certificate templates for object type: "%s": "%s"', $type, json_encode($result)));
321 
322  return $result;
323  }
$result
$type
$query
$row
+ Here is the call graph for this function:

◆ fetchCertificateTemplatesByObjId()

ilCertificateTemplateRepository::fetchCertificateTemplatesByObjId ( int  $objId)
Parameters
int$objId
Returns
[]

Definition at line 119 of file class.ilCertificateTemplateRepository.php.

References $query, $result, $row, and createCertificateTemplate().

Referenced by deleteTemplate(), and fetchPreviousCertificate().

119  : array
120  {
121  $this->logger->info(sprintf('START - Fetch multiple certificate templates for object: "%s"', $objId));
122 
123  $result = array();
124 
125  $sql = '
126 SELECT * FROM
127 il_cert_template
128 WHERE obj_id = ' . $this->database->quote($objId, 'integer') . '
129 AND deleted = 0
130 ORDER BY version ASC';
131 
132  $query = $this->database->query($sql);
133 
134  while ($row = $this->database->fetchAssoc($query)) {
136  }
137 
138  $this->logger->info(sprintf('END - Fetching of certificate templates for object: "%s" with "%s" results', $objId, count($result)));
139 
140  return $result;
141  }
$result
$query
$row
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fetchCurrentlyActiveCertificate()

ilCertificateTemplateRepository::fetchCurrentlyActiveCertificate ( int  $objId)
Parameters
int$objId
Returns
Exceptions
ilException

Definition at line 190 of file class.ilCertificateTemplateRepository.php.

References $query, $row, and createCertificateTemplate().

191  {
192  $this->logger->info(sprintf('START - Fetch currently active certificate template for object: "%s"', $objId));
193 
194  $sql = '
195 SELECT * FROM il_cert_template
196 WHERE obj_id = ' . $this->database->quote($objId, 'integer') . '
197 AND deleted = 0
198 AND currently_active = 1
199 ';
200 
201  $query = $this->database->query($sql);
202 
203  while ($row = $this->database->fetchAssoc($query)) {
204  $this->logger->info(sprintf('END - Found active certificate for: "%s"', $objId));
205 
206  return $this->createCertificateTemplate($row);
207  }
208 
209  throw new ilException((sprintf('NO active certificate template found for: "%s"', $objId)));
210  }
$query
$row
+ Here is the call graph for this function:

◆ fetchCurrentlyUsedCertificate()

ilCertificateTemplateRepository::fetchCurrentlyUsedCertificate ( int  $objId)
Parameters
int$objId
Returns

Definition at line 147 of file class.ilCertificateTemplateRepository.php.

References $query, $row, and createCertificateTemplate().

148  {
149  $this->logger->info(sprintf('START - Fetch currently active certificate template for object: "%s"', $objId));
150 
151  $this->database->setLimit(1);
152 
153  $sql = '
154 SELECT * FROM il_cert_template
155 WHERE obj_id = ' . $this->database->quote($objId, 'integer') . '
156 AND deleted = 0
157 ORDER BY id DESC
158 ';
159 
160  $query = $this->database->query($sql);
161 
162  while ($row = $this->database->fetchAssoc($query)) {
163  $this->logger->info(sprintf('END - Found active certificate for: "%s"', $objId));
164 
165  return $this->createCertificateTemplate($row);
166  }
167 
168  $this->logger->info(sprintf('END - Found NO active certificate for: "%s"', $objId));
169 
170  return new ilCertificateTemplate(
171  $objId,
172  $this->objectDataCache->lookUpType($objId),
173  '',
174  '',
175  '',
176  0,
177  0,
178  0,
179  false,
180  '',
181  ''
182  );
183  }
$query
$row
+ Here is the call graph for this function:

◆ fetchFirstCreatedTemplate()

ilCertificateTemplateRepository::fetchFirstCreatedTemplate ( int  $objId)
Parameters
int$objId
Returns
Exceptions

Definition at line 330 of file class.ilCertificateTemplateRepository.php.

References $query, $row, and createCertificateTemplate().

331  {
332  $this->logger->info(sprintf('START - Fetch first create certificate template for object: "%s"', $objId));
333 
334  $this->database->setLimit(1, 0);
335 
336  $sql = 'SELECT * FROM il_cert_template
337 WHERE obj_id = ' . $this->database->quote($objId, 'integer') . '
338 ORDER BY id ASC ';
339 
340  $query = $this->database->query($sql);
341 
342  while ($row = $this->database->fetchAssoc($query)) {
343  $this->logger->info(sprintf('END - Found first create certificate template for object: "%s"', $objId));
344 
345  return $this->createCertificateTemplate($row);
346  }
347 
348  throw new ilException('No matching template found. MAY missing DBUpdate. Please check if the correct version is installed.');
349  }
$query
$row
+ Here is the call graph for this function:

◆ fetchPreviousCertificate()

ilCertificateTemplateRepository::fetchPreviousCertificate ( int  $objId)

Fetch latest created certificate EVEN IF it is deleted.

Parameters
int$objId
Returns

Definition at line 218 of file class.ilCertificateTemplateRepository.php.

References $template, $version, fetchCertificateTemplatesByObjId(), and ilCertificateTemplate\getVersion().

219  {
220  $this->logger->info(sprintf('START - Fetch previous active certificate template for object: "%s"', $objId));
221 
222  $templates = $this->fetchCertificateTemplatesByObjId($objId);
223 
224  $resultTemplate = new ilCertificateTemplate(
225  $objId,
226  $this->objectDataCache->lookUpType($objId),
227  '',
228  '',
229  '',
230  0,
231  0,
232  0,
233  true,
234  '',
235  ''
236  );
237 
238  $version = 0;
239  foreach ($templates as $template) {
240  if ($template->getVersion() > $version) {
241  $version = $template->getVersion();
242  $resultTemplate = $template;
243  }
244  }
245 
246  $this->logger->info(sprintf('Latest version active certificate template for object: "%s"', $objId));
247 
248  return $resultTemplate;
249  }
$template
$version
Definition: build.php:27
+ Here is the call graph for this function:

◆ fetchTemplate()

ilCertificateTemplateRepository::fetchTemplate ( int  $templateId)

Definition at line 96 of file class.ilCertificateTemplateRepository.php.

References $query, $row, and createCertificateTemplate().

97  {
98  $this->logger->info(sprintf('START - Fetch certificate template with id: "%s"', $templateId));
99 
100  $sql = '
101 SELECT * FROM
102 il_cert_template
103 WHERE id = ' . $this->database->quote($templateId, 'integer') . '
104 ORDER BY version ASC';
105 
106  $query = $this->database->query($sql);
107 
108  while ($row = $this->database->fetchAssoc($query)) {
109  return $this->createCertificateTemplate($row);
110  }
111 
112  throw new ilException(sprintf('No template with id "%s" found', $templateId));
113  }
$query
$row
+ Here is the call graph for this function:

◆ save()

ilCertificateTemplateRepository::save ( ilCertificateTemplate  $certificateTemplate)
Parameters
ilCertificateTemplate$certificateTemplate
Exceptions
ilDatabaseException

Definition at line 56 of file class.ilCertificateTemplateRepository.php.

References $columns, $id, deactivatePreviousTemplates(), ilCertificateTemplate\getBackgroundImagePath(), ilCertificateTemplate\getCertificateContent(), ilCertificateTemplate\getCertificateHash(), ilCertificateTemplate\getCreatedTimestamp(), ilCertificateTemplate\getIliasVersion(), ilCertificateTemplate\getObjId(), ilCertificateTemplate\getObjType(), ilCertificateTemplate\getTemplateValues(), ilCertificateTemplate\getThumbnailImagePath(), ilCertificateTemplate\getVersion(), ilCertificateTemplate\isCurrentlyActive(), and ilCertificateTemplate\isDeleted().

57  {
58  $this->logger->info('START - Save new certificate template');
59 
60  $objId = $certificateTemplate->getObjId();
61 
62  $id = $this->database->nextId('il_cert_template');
63 
64  $this->deactivatePreviousTemplates($objId);
65 
66  $columns = array(
67  'id' => array('integer', $id),
68  'obj_id' => array('integer', $objId),
69  'obj_type' => array('text', $certificateTemplate->getObjType()),
70  'certificate_content' => array('clob', $certificateTemplate->getCertificateContent()),
71  'certificate_hash' => array('text', $certificateTemplate->getCertificateHash()),
72  'template_values' => array('clob', $certificateTemplate->getTemplateValues()),
73  'version' => array('integer', $certificateTemplate->getVersion()),
74  'ilias_version' => array('text', $certificateTemplate->getIliasVersion()),
75  'created_timestamp' => array('integer', $certificateTemplate->getCreatedTimestamp()),
76  'currently_active' => array('integer', (integer) $certificateTemplate->isCurrentlyActive()),
77  'background_image_path' => array('text', $certificateTemplate->getBackgroundImagePath()),
78  'deleted' => array('integer', (integer) $certificateTemplate->isDeleted()),
79  'thumbnail_image_path' => array('text', $certificateTemplate->getThumbnailImagePath())
80  );
81 
82  $this->database->insert('il_cert_template', $columns);
83 
84  $this->logger->info('END - certificate template saved with columns: ', json_encode($columns));
85  }
if(!array_key_exists('StateId', $_REQUEST)) $id
if(! $in) $columns
Definition: Utf8Test.php:45
+ Here is the call graph for this function:

◆ updateActivity()

ilCertificateTemplateRepository::updateActivity ( ilCertificateTemplate  $certificateTemplate,
bool  $currentlyActive 
)

Definition at line 88 of file class.ilCertificateTemplateRepository.php.

References ilCertificateTemplate\getId().

89  {
90  $sql = 'UPDATE il_cert_template SET currently_active = ' . $this->database->quote($currentlyActive, 'integer') .
91  ' WHERE id = ' . $this->database->quote($certificateTemplate->getId(), 'integer');
92 
93  return $this->database->manipulate($sql);
94  }
+ Here is the call graph for this function:

Field Documentation

◆ $database

ilCertificateTemplateRepository::$database
private

Definition at line 15 of file class.ilCertificateTemplateRepository.php.

Referenced by __construct().

◆ $logger

ilCertificateTemplateRepository::$logger
private

Definition at line 20 of file class.ilCertificateTemplateRepository.php.

Referenced by __construct().

◆ $objectDataCache

ilCertificateTemplateRepository::$objectDataCache
private

Definition at line 25 of file class.ilCertificateTemplateRepository.php.

Referenced by __construct().


The documentation for this class was generated from the following file: