ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCertificateTemplateDeleteAction.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
8 {
13 
17  private $rootDirectory;
18 
22  private $utilHelper;
23 
27  private $objectHelper;
28 
32  private $iliasVersion;
33 
41  public function __construct(
43  string $rootDirectory = CLIENT_WEB_DIR,
47  ) {
48  $this->templateRepository = $templateRepository;
49 
50  $this->rootDirectory = $rootDirectory;
51 
52  if (null === $utilHelper) {
54  }
55  $this->utilHelper = $utilHelper;
56 
57  if (null === $objectHelper) {
59  }
60  $this->objectHelper = $objectHelper;
61 
62  $this->iliasVersion = $iliasVersion;
63  }
64 
72  public function delete($templateTemplateId, $objectId)
73  {
74  $template = $this->templateRepository->fetchCurrentlyUsedCertificate($objectId);
75 
76  $this->templateRepository->deleteTemplate($templateTemplateId, $objectId);
77 
78  $version = (int) $template->getVersion();
79  $certificateTemplate = new ilCertificateTemplate(
80  $objectId,
81  $this->objectHelper->lookupType($objectId),
82  '',
83  hash('sha256', ''),
84  '',
85  $version + 1,
87  time(),
88  false,
89  '',
90  ''
91  );
92 
93  $this->templateRepository->save($certificateTemplate);
94 
95  $this->overwriteBackgroundImageThumbnail($certificateTemplate);
96  }
97 
101  private function overwriteBackgroundImageThumbnail(ilCertificateTemplate $previousTemplate)
102  {
103  $relativePath = $previousTemplate->getBackgroundImagePath();
104 
105  if (null === $relativePath || '' === $relativePath) {
106  $relativePath = '/certificates/default/background.jpg';
107  }
108 
109  $pathInfo = pathinfo($relativePath);
110 
111  $newFilePath = $pathInfo['dirname'] . '/background.jpg.thumb.jpg';
112 
113  $this->utilHelper->convertImage(
114  $this->rootDirectory . $relativePath,
115  $this->rootDirectory . $newFilePath,
116  'JPEG',
117  100
118  );
119  }
120 }
const ILIAS_VERSION_NUMERIC
$template
__construct(ilCertificateTemplateRepository $templateRepository, string $rootDirectory=CLIENT_WEB_DIR, ilCertificateUtilHelper $utilHelper=null, ilCertificateObjectHelper $objectHelper=null, $iliasVersion=ILIAS_VERSION_NUMERIC)
$version
Definition: build.php:27
overwriteBackgroundImageThumbnail(ilCertificateTemplate $previousTemplate)
Just a wrapper class to create Unit Test for other classes.
hash(StreamInterface $stream, $algo, $rawOutput=false)
Calculate a hash of a Stream.
Definition: functions.php:406