ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilCertificateCloneAction.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 
31 {
32  private readonly Filesystem $fileSystem;
34 
35  public function __construct(
36  private readonly ilDBInterface $database,
37  private readonly ilCertificatePathFactory $pathFactory,
38  private readonly ilCertificateTemplateRepository $templateRepository,
39  ?ilCertificateObjectHelper $objectHelper = null,
40  ?ilObjCertificateSettings $global_certificate_settings = null,
41  ) {
42  if (null === $objectHelper) {
43  $objectHelper = new ilCertificateObjectHelper();
44  }
45  $this->objectHelper = $objectHelper;
46  }
47 
55  public function cloneCertificate(
56  ilObject $oldObject,
57  ilObject $newObject,
58  string $iliasVersion = ILIAS_VERSION_NUMERIC,
59  string $webDir = CLIENT_WEB_DIR
60  ): void {
61  $oldType = $oldObject->getType();
62  $newType = $newObject->getType();
63 
64  if ($oldType !== $newType) {
65  throw new ilException(sprintf(
66  'The types "%s" and "%s" for cloning does not match',
67  $oldType,
68  $newType
69  ));
70  }
71 
72  $certificatePath = $this->pathFactory->create($newObject);
73 
74  $templates = $this->templateRepository->fetchCertificateTemplatesByObjId($oldObject->getId());
75 
77  foreach ($templates as $template) {
78  $newTemplate = new ilCertificateTemplate(
79  $newObject->getId(),
80  $this->objectHelper->lookupType($newObject->getId()),
81  $template->getCertificateContent(),
82  $template->getCertificateHash(),
83  $template->getTemplateValues(),
84  $template->getVersion(),
85  $iliasVersion,
86  time(),
87  $template->isCurrentlyActive(),
88  $template->getBackgroundImagePath(),
89  $template->getTileImagePath(),
90  $template->getBackgroundImageIdentification(),
91  $template->getTileImageIdentification()
92  );
93 
94  $this->templateRepository->save($newTemplate);
95  }
96 
97  // #10271
98  if ($this->isActive($oldObject->getId())) {
99  $this->database->replace(
100  'il_certificate',
101  ['obj_id' => ['integer', $newObject->getId()]],
102  []
103  );
104  }
105  }
106 
107  private function isActive(int $objectId): bool
108  {
109  $sql = 'SELECT 1 FROM il_certificate WHERE obj_id = ' . $this->database->quote($objectId, 'integer');
110 
111  return (bool) $this->database->fetchAssoc($this->database->query($sql));
112  }
113 }
__construct(private readonly ilDBInterface $database, private readonly ilCertificatePathFactory $pathFactory, private readonly ilCertificateTemplateRepository $templateRepository, ?ilCertificateObjectHelper $objectHelper=null, ?ilObjCertificateSettings $global_certificate_settings=null,)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
const ILIAS_VERSION_NUMERIC
const CLIENT_WEB_DIR
Definition: constants.php:47
readonly ilCertificateObjectHelper $objectHelper