ILIAS  release_8 Revision v8.23
class.ilCertificateTemplateDeleteAction.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
27  private string $rootDirectory;
30  private string $iliasVersion;
31 
32  public function __construct(
33  ilCertificateTemplateRepository $templateRepository,
34  string $rootDirectory = CLIENT_WEB_DIR,
35  ?ilCertificateUtilHelper $utilHelper = null,
36  ?ilCertificateObjectHelper $objectHelper = null,
37  string $iliasVersion = ILIAS_VERSION_NUMERIC
38  ) {
39  $this->templateRepository = $templateRepository;
40 
41  $this->rootDirectory = $rootDirectory;
42 
43  if (null === $utilHelper) {
44  $utilHelper = new ilCertificateUtilHelper();
45  }
46  $this->utilHelper = $utilHelper;
47 
48  if (null === $objectHelper) {
49  $objectHelper = new ilCertificateObjectHelper();
50  }
51  $this->objectHelper = $objectHelper;
52 
53  $this->iliasVersion = $iliasVersion;
54  }
55 
56  public function delete(int $templateId, int $objectId): void
57  {
58  $template = $this->templateRepository->fetchCurrentlyUsedCertificate($objectId);
59 
60  $this->templateRepository->deleteTemplate($templateId, $objectId);
61 
62  $version = $template->getVersion();
63  $certificateTemplate = new ilCertificateTemplate(
64  $objectId,
65  $this->objectHelper->lookupType($objectId),
66  '',
67  hash('sha256', ''),
68  '',
69  ($version + 1),
70  $this->iliasVersion,
71  time(),
72  false,
73  '',
74  ''
75  );
76 
77  $this->templateRepository->save($certificateTemplate);
78  }
79 }
const ILIAS_VERSION_NUMERIC
const CLIENT_WEB_DIR
Definition: constants.php:47
Just a wrapper class to create Unit Test for other classes.
$version
Definition: plugin.php:24
__construct(ilCertificateTemplateRepository $templateRepository, string $rootDirectory=CLIENT_WEB_DIR, ?ilCertificateUtilHelper $utilHelper=null, ?ilCertificateObjectHelper $objectHelper=null, string $iliasVersion=ILIAS_VERSION_NUMERIC)