19 declare(strict_types=1);
44 string $global_certificate_path = null
46 if (null === $fileSystem) {
48 $fileSystem = $DIC->filesystem()->web();
52 if (null === $objectHelper) {
57 if (!$global_certificate_settings) {
62 if (null === $global_certificate_path) {
75 public function cloneCertificate(
81 $oldType = $oldObject->
getType();
82 $newType = $newObject->
getType();
84 if ($oldType !== $newType) {
86 'The types "%s" and "%s" for cloning does not match',
92 $certificatePath = $this->pathFactory->create($newObject);
94 $templates = $this->templateRepository->fetchCertificateTemplatesByObjId($oldObject->
getId());
97 foreach ($templates as $template) {
98 $backgroundImagePath = $template->getBackgroundImagePath();
99 $backgroundImageFile = basename($backgroundImagePath);
100 $backgroundImageThumbnail = dirname($backgroundImagePath) .
'/background.jpg.thumb.jpg';
102 $newBackgroundImage =
'';
103 $newBackgroundImageThumbnail =
'';
104 if ($this->global_certificate_path !== $backgroundImagePath) {
105 if ($this->fileSystem->has($backgroundImagePath) &&
106 !$this->fileSystem->hasDir($backgroundImagePath)
108 $newBackgroundImage = $certificatePath . $backgroundImageFile;
109 $newBackgroundImageThumbnail = str_replace(
114 if ($this->fileSystem->has($newBackgroundImage) &&
115 !$this->fileSystem->hasDir($newBackgroundImage)
117 $this->fileSystem->delete($newBackgroundImage);
120 $this->fileSystem->copy(
121 $backgroundImagePath,
127 $newBackgroundImageThumbnail !==
'' &&
128 $this->fileSystem->has($backgroundImageThumbnail) &&
129 !$this->fileSystem->hasDir($backgroundImageThumbnail)
131 if ($this->fileSystem->has($newBackgroundImageThumbnail) &&
132 !$this->fileSystem->hasDir($newBackgroundImageThumbnail)
134 $this->fileSystem->delete($newBackgroundImageThumbnail);
137 $this->fileSystem->copy(
138 $backgroundImageThumbnail,
139 $newBackgroundImageThumbnail
146 $newCardThumbImage =
'';
147 $cardThumbImagePath = $template->getThumbnailImagePath();
149 if ($this->fileSystem->has($cardThumbImagePath) && !$this->fileSystem->hasDir($cardThumbImagePath)) {
150 $newCardThumbImage = $certificatePath . basename($cardThumbImagePath);
151 if ($this->fileSystem->has($newCardThumbImage) && !$this->fileSystem->hasDir($newCardThumbImage)) {
152 $this->fileSystem->delete($newCardThumbImage);
154 $this->fileSystem->copy(
162 $this->objectHelper->lookupType($newObject->
getId()),
163 $template->getCertificateContent(),
164 $template->getCertificateHash(),
165 $template->getTemplateValues(),
166 $template->getVersion(),
169 $template->isCurrentlyActive(),
174 $this->templateRepository->save($newTemplate);
179 $this->database->replace(
181 [
'obj_id' => [
'integer', $newObject->
getId()]],
189 $sql =
'SELECT 1 FROM il_certificate WHERE obj_id = ' . $this->database->quote($objectId,
'integer');
191 return (
bool) $this->database->fetchAssoc($this->database->query($sql));
196 return "background.jpg";
const ILIAS_VERSION_NUMERIC
readonly ilObjCertificateSettings $global_certificate_settings
Class ilObjCertificateSettings.
readonly string $global_certificate_path
readonly ilCertificateObjectHelper $objectHelper
getDefaultBackgroundImagePath(bool $relativePath=false)
getBackgroundImageThumbPath(string $certificatePath)
readonly Filesystem $fileSystem
__construct(private readonly ilDBInterface $database, private readonly ilCertificatePathFactory $pathFactory, private readonly ilCertificateTemplateRepository $templateRepository, private readonly string $webDirectory=CLIENT_WEB_DIR, ?Filesystem $fileSystem=null, ?ilCertificateObjectHelper $objectHelper=null, ?ilObjCertificateSettings $global_certificate_settings=null, string $global_certificate_path=null)