ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilObjCertificateSettings Class Reference

Class ilObjCertificateSettings. More...

+ Inheritance diagram for ilObjCertificateSettings:
+ Collaboration diagram for ilObjCertificateSettings:

Public Member Functions

 __construct (int $a_id=0, bool $a_reference=true)
 
 uploadBackgroundImage (UploadResult $upload_result)
 Uploads a background image for the certificate. More...
 
 deleteBackgroundImage ()
 
 getBackgroundImageDefaultFolder (bool $relativePath=false)
 
 getDefaultBackgroundImagePath (bool $relativePath=false)
 
 getDefaultBackgroundImageThumbPath (bool $relativePath=false)
 
 hasBackgroundImage ()
 
 getDefaultBackgroundImagePathWeb ()
 
 getBackgroundImageThumbPathWeb ()
 
- Public Member Functions inherited from ilObject
 getObjectProperties ()
 
 flushObjectProperties ()
 
 withReferences ()
 determines whether objects are referenced or not (got ref ids or not) More...
 
 processAutoRating ()
 
 read ()
 
 getId ()
 
 setId (int $id)
 
 setRefId (int $ref_id)
 
 getRefId ()
 
 getType ()
 
 setType (string $type)
 
 getPresentationTitle ()
 get presentation title Normally same as title Overwritten for sessions More...
 
 getTitle ()
 
 getUntranslatedTitle ()
 Get untranslated object title WebDAV needs to access the untranslated title of an object. More...
 
 setTitle (string $title)
 
 getDescription ()
 
 setDescription (string $description)
 
 getLongDescription ()
 get object long description (stored in object_description) More...
 
 getImportId ()
 
 setImportId (string $import_id)
 
 setOfflineStatus (bool $status)
 
 getOfflineStatus ()
 
 supportsOfflineHandling ()
 
 getOwner ()
 
 getOwnerName ()
 get full name of object owner More...
 
 setOwner (int $usr_id)
 
 getCreateDate ()
 Get create date in YYYY-MM-DD HH-MM-SS format. More...
 
 getLastUpdateDate ()
 Get last update date in YYYY-MM-DD HH-MM-SS format. More...
 
 create ()
 note: title, description and type should be set when this function is called More...
 
 update ()
 
 MDUpdateListener (string $element)
 Metadata update listener. More...
 
 createMetaData ()
 
 updateMetaData ()
 
 deleteMetaData ()
 
 updateOwner ()
 update owner of object in db More...
 
 putInTree (int $parent_ref_id)
 maybe this method should be in tree object!? More...
 
 setPermissions (int $parent_ref_id)
 
 setParentRolePermissions (int $parent_ref_id)
 Initialize the permissions of parent roles (local roles of categories, global roles...) This method is overwritten in e.g. More...
 
 createReference ()
 creates reference for object More...
 
 countReferences ()
 
 delete ()
 delete object or referenced object (in the case of a referenced object, object data is only deleted if last reference is deleted) This function removes an object entirely from system!! More...
 
 initDefaultRoles ()
 init default roles settings Purpose of this function is to create a local role folder and local roles, that are needed depending on the object type. More...
 
 applyDidacticTemplate (int $tpl_id)
 
 getXMLZip ()
 
 getHTMLDirectory ()
 
 appendCopyInfo (int $target_id, int $copy_id)
 Prepend Copy info if object with same name exists in that container. More...
 
 cloneDependencies (int $target_id, int $copy_id)
 Clone object dependencies. More...
 
 cloneMetaData (ilObject $target_obj)
 Copy meta data. More...
 
 selfOrParentWithRatingEnabled ()
 
 getPossibleSubObjects (bool $filter=true)
 get all possible sub objects of this type the object can decide which types of sub objects are possible jut in time overwrite if the decision distinguish from standard model More...
 

Private Member Functions

 getDefaultBackgroundImageTempFilePath (string $extension)
 

Private Attributes

ilLogger $cert_logger
 
ILIAS Filesystem Util Convert LegacyImages $file_converter
 
Factory $uuid_factory
 
ilSetting $certificate_settings
 
ilCertificateTemplateDatabaseRepository $certificate_repo
 
ilUserCertificateRepository $user_certificate_repo
 

Additional Inherited Members

- Static Public Member Functions inherited from ilObject
static _lookupObjIdByImportId (string $import_id)
 Get (latest) object id for an import id. More...
 
static _lookupImportId (int $obj_id)
 
static _lookupOwnerName (int $owner_id)
 Lookup owner name for owner id. More...
 
static _getIdForImportId (string $import_id)
 
static _getAllReferences (int $id)
 get all reference ids for object ID More...
 
static _lookupTitle (int $obj_id)
 
static lookupOfflineStatus (int $obj_id)
 Lookup offline status using objectDataCache. More...
 
static _lookupOwner (int $obj_id)
 Lookup owner user ID for object ID. More...
 
static _getIdsForTitle (string $title, string $type='', bool $partial_match=false)
 
static _lookupDescription (int $obj_id)
 
static _lookupLastUpdate (int $obj_id, bool $formatted=false)
 
static _getLastUpdateOfObjects (array $obj_ids)
 
static _lookupObjId (int $ref_id)
 
static _setDeletedDate (int $ref_id, int $deleted_by)
 
static setDeletedDates (array $ref_ids, int $user_id)
 
static _resetDeletedDate (int $ref_id)
 
static _lookupDeletedDate (int $ref_id)
 
static _writeTitle (int $obj_id, string $title)
 write title to db (static) More...
 
static _writeDescription (int $obj_id, string $desc)
 write description to db (static) More...
 
static _writeImportId (int $obj_id, string $import_id)
 write import id to db (static) More...
 
static _lookupType (int $id, bool $reference=false)
 
static _isInTrash (int $ref_id)
 
static _hasUntrashedReference (int $obj_id)
 checks whether an object has at least one reference that is not in trash More...
 
static _lookupObjectId (int $ref_id)
 
static _getObjectsDataForType (string $type, bool $omit_trash=false)
 get all objects of a certain type More...
 
static _exists (int $id, bool $reference=false, ?string $type=null)
 checks if an object exists in object_data More...
 
static _getObjectsByType (string $obj_type="", int $owner=null)
 
static _prepareCloneSelection (array $ref_ids, string $new_type, bool $show_path=true)
 Prepare copy wizard object selection. More...
 
static _getIcon (int $obj_id=0, string $size="big", string $type="", bool $offline=false)
 Get icon for repository item. More...
 
static collectDeletionDependencies (array &$deps, int $ref_id, int $obj_id, string $type, int $depth=0)
 Collect deletion dependencies. More...
 
static getDeletionDependencies (int $obj_id)
 Get deletion dependencies. More...
 
static getLongDescriptions (array $obj_ids)
 
static getAllOwnedRepositoryObjects (int $user_id)
 
static fixMissingTitles ($type, array &$obj_title_map)
 Try to fix missing object titles. More...
 
static _lookupCreationDate (int $obj_id)
 
static _getObjectTypeIdByTitle (string $type, \ilDBInterface $ilDB=null)
 
- Data Fields inherited from ilObject
const TITLE_LENGTH = 255
 
const DESC_LENGTH = 128
 
const LONG_DESC_LENGTH = 4000
 
const TABLE_OBJECT_DATA = "object_data"
 
array $objectList
 
string $untranslatedTitle
 
- Protected Member Functions inherited from ilObject
 doMDUpdateListener (string $a_element)
 
 beforeMDUpdateListener (string $a_element)
 
 doCreateMetaData ()
 
 beforeCreateMetaData ()
 
 doUpdateMetaData ()
 
 beforeUpdateMetaData ()
 
 doDeleteMetaData ()
 
 beforeDeleteMetaData ()
 
 handleAutoRating ()
 
 hasAutoRating ()
 
- Protected Attributes inherited from ilObject
ilLogger $obj_log
 
ILIAS $ilias
 
ilObjectDefinition $obj_definition
 
ilDBInterface $db
 
ilLogger $log
 
ilErrorHandling $error
 
ilTree $tree
 
ilAppEventHandler $app_event_handler
 
ilRbacAdmin $rbac_admin
 
ilRbacReview $rbac_review
 
ilObjUser $user
 
ilLanguage $lng
 
bool $call_by_reference
 
int $max_title = self::TITLE_LENGTH
 
int $max_desc = self::DESC_LENGTH
 
bool $add_dots = true
 
int $ref_id = null
 
string $type = ""
 
string $title = ""
 
string $desc = ""
 
string $long_desc = ""
 
int $owner = 0
 
string $create_date = ""
 
string $last_update = ""
 
string $import_id = ""
 
bool $register = false
 

Detailed Description

Class ilObjCertificateSettings.

Author
Helmut Schottmüller ilias.nosp@m.@aur.nosp@m.ealis.nosp@m..de
Version
$Id$

Definition at line 31 of file class.ilObjCertificateSettings.php.

Constructor & Destructor Documentation

◆ __construct()

ilObjCertificateSettings::__construct ( int  $a_id = 0,
bool  $a_reference = true 
)

Definition at line 40 of file class.ilObjCertificateSettings.php.

References $DIC, and ILIAS\MetaData\Repository\Validation\Data\__construct().

41  {
42  global $DIC;
43 
44  parent::__construct($a_id, $a_reference);
45  $this->type = 'cert';
46  $this->cert_logger = $DIC->logger()->cert();
47  $this->file_converter = $DIC->fileConverters()->legacyImages();
48  $this->uuid_factory = new Factory();
49  $this->certificate_settings = new ilSetting('certificate');
50  $this->certificate_repo = new ilCertificateTemplateDatabaseRepository($DIC->database());
51  $this->user_certificate_repo = new ilUserCertificateRepository($DIC->database());
52  }
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
+ Here is the call graph for this function:

Member Function Documentation

◆ deleteBackgroundImage()

ilObjCertificateSettings::deleteBackgroundImage ( )

PhpCastIsUnnecessaryInspection

UnnecessaryCastingInspection

Definition at line 171 of file class.ilObjCertificateSettings.php.

References getDefaultBackgroundImagePath(), getDefaultBackgroundImageTempFilePath(), getDefaultBackgroundImageThumbPath(), and ilCertificateBackgroundImageFileService\VALID_BACKGROUND_IMAGE_EXTENSIONS.

171  : bool
172  {
173  $result = true;
174 
175 
176  if (
177  $this->certificate_settings->get('defaultImageFileName', '')
178  && !$this->certificate_repo->isBackgroundImageUsed($this->getDefaultBackgroundImagePath(true))
179  && !$this->user_certificate_repo->isBackgroundImageUsed($this->getDefaultBackgroundImagePath(true))
180  ) {
181  //No certificates exist using the currently configured file, deleting file possible.
182 
183  if (is_file($this->getDefaultBackgroundImageThumbPath())) {
184  $result &= unlink($this->getDefaultBackgroundImageThumbPath());
185  }
186  if (is_file($this->getDefaultBackgroundImagePath())) {
187  $result &= unlink($this->getDefaultBackgroundImagePath());
188  }
189 
191  if (is_file($this->getDefaultBackgroundImageTempFilePath($extension))) {
192  $result &= unlink($this->getDefaultBackgroundImageTempFilePath($extension));
193  }
194  }
195  }
196 
197  $this->certificate_settings->set('defaultImageFileName', '');
198 
201  return (bool) $result; // Don't remove the cast, otherwise $result will be 1 or 0
202  }
getDefaultBackgroundImageThumbPath(bool $relativePath=false)
getDefaultBackgroundImageTempFilePath(string $extension)
getDefaultBackgroundImagePath(bool $relativePath=false)
+ Here is the call graph for this function:

◆ getBackgroundImageDefaultFolder()

ilObjCertificateSettings::getBackgroundImageDefaultFolder ( bool  $relativePath = false)

Definition at line 204 of file class.ilObjCertificateSettings.php.

References CLIENT_WEB_DIR.

Referenced by getDefaultBackgroundImagePath(), getDefaultBackgroundImageTempFilePath(), and uploadBackgroundImage().

204  : string
205  {
206  return ($relativePath ? '' : CLIENT_WEB_DIR) . '/certificates/default/';
207  }
const CLIENT_WEB_DIR
Definition: constants.php:47
+ Here is the caller graph for this function:

◆ getBackgroundImageThumbPathWeb()

ilObjCertificateSettings::getBackgroundImageThumbPathWeb ( )

Definition at line 245 of file class.ilObjCertificateSettings.php.

References getDefaultBackgroundImageThumbPath(), and ilFileUtils\removeTrailingPathSeparators().

245  : string
246  {
247  return str_replace(
248  ilFileUtils::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH),
251  );
252  }
getDefaultBackgroundImageThumbPath(bool $relativePath=false)
static removeTrailingPathSeparators(string $path)
+ Here is the call graph for this function:

◆ getDefaultBackgroundImagePath()

ilObjCertificateSettings::getDefaultBackgroundImagePath ( bool  $relativePath = false)

Definition at line 209 of file class.ilObjCertificateSettings.php.

References getBackgroundImageDefaultFolder().

Referenced by ilCertificateCloneAction\__construct(), deleteBackgroundImage(), getDefaultBackgroundImagePathWeb(), getDefaultBackgroundImageThumbPath(), hasBackgroundImage(), and uploadBackgroundImage().

209  : string
210  {
211  return $this->getBackgroundImageDefaultFolder($relativePath)
212  . $this->certificate_settings->get('defaultImageFileName', '');
213  }
getBackgroundImageDefaultFolder(bool $relativePath=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultBackgroundImagePathWeb()

ilObjCertificateSettings::getDefaultBackgroundImagePathWeb ( )

Definition at line 236 of file class.ilObjCertificateSettings.php.

References getDefaultBackgroundImagePath(), and ilFileUtils\removeTrailingPathSeparators().

236  : string
237  {
238  return str_replace(
239  ilFileUtils::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH),
242  );
243  }
static removeTrailingPathSeparators(string $path)
getDefaultBackgroundImagePath(bool $relativePath=false)
+ Here is the call graph for this function:

◆ getDefaultBackgroundImageTempFilePath()

ilObjCertificateSettings::getDefaultBackgroundImageTempFilePath ( string  $extension)
private

Definition at line 220 of file class.ilObjCertificateSettings.php.

References ilCertificateBackgroundImageFileService\BACKGROUND_TEMPORARY_UPLOAD_FILE_NAME, and getBackgroundImageDefaultFolder().

Referenced by deleteBackgroundImage(), and uploadBackgroundImage().

220  : string
221  {
222  return implode('', [
225  '.' . $extension
226  ]);
227  }
getBackgroundImageDefaultFolder(bool $relativePath=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultBackgroundImageThumbPath()

ilObjCertificateSettings::getDefaultBackgroundImageThumbPath ( bool  $relativePath = false)

Definition at line 215 of file class.ilObjCertificateSettings.php.

References ilCertificateBackgroundImageFileService\BACKGROUND_THUMBNAIL_FILE_ENDING, and getDefaultBackgroundImagePath().

Referenced by deleteBackgroundImage(), getBackgroundImageThumbPathWeb(), and uploadBackgroundImage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasBackgroundImage()

ilObjCertificateSettings::hasBackgroundImage ( )

Definition at line 229 of file class.ilObjCertificateSettings.php.

References getDefaultBackgroundImagePath().

229  : bool
230  {
231  $filePath = $this->getDefaultBackgroundImagePath();
232 
233  return is_file($filePath) && filesize($filePath) > 0;
234  }
getDefaultBackgroundImagePath(bool $relativePath=false)
+ Here is the call graph for this function:

◆ uploadBackgroundImage()

ilObjCertificateSettings::uploadBackgroundImage ( UploadResult  $upload_result)

Uploads a background image for the certificate.

Creates a new directory for the certificate if needed. Removes an existing certificate image if necessary

Returns
bool True on success, otherwise false
Exceptions
ilException

Definition at line 60 of file class.ilObjCertificateSettings.php.

References ilCertificateBackgroundImageFileService\BACKGROUND_THUMBNAIL_FILE_ENDING, getBackgroundImageDefaultFolder(), getDefaultBackgroundImagePath(), getDefaultBackgroundImageTempFilePath(), getDefaultBackgroundImageThumbPath(), ILIAS\FileUpload\DTO\UploadResult\getName(), ILIAS\FileUpload\DTO\UploadResult\getPath(), ilFileUtils\makeDirParents(), and ilFileUtils\moveUploadedFile().

60  : bool
61  {
62  $image_temp_file_name = $upload_result->getPath();
63  if ($image_temp_file_name !== '') {
64  $extension = pathinfo($upload_result->getName(), PATHINFO_EXTENSION);
65  $image_path = $this->getBackgroundImageDefaultFolder();
66  $new_image_file_name = "background_{$this->uuid_factory->uuid4AsString()}.jpg";
67  $new_image_path = $image_path . $new_image_file_name;
68 
69  if (!is_dir($image_path)) {
70  ilFileUtils::makeDirParents($image_path);
71  }
72  // upload the file
74  $image_temp_file_name,
75  basename($this->getDefaultBackgroundImageTempFilePath($extension)),
76  $this->getDefaultBackgroundImageTempFilePath($extension)
77  )) {
78  $this->cert_logger->error(sprintf(
79  "Could not upload certificate background image from '%s' to temporary file '%s' (name: '%s')",
80  $image_temp_file_name,
81  $this->getDefaultBackgroundImageTempFilePath($extension),
82  basename($this->getDefaultBackgroundImageTempFilePath($extension))
83  ));
84  return false;
85  }
86 
87  if (!is_file($this->getDefaultBackgroundImageTempFilePath($extension))) {
88  $this->cert_logger->error(sprintf(
89  "Uploaded certificate background image could not be moved to temporary file '%s'",
90  $this->getDefaultBackgroundImageTempFilePath($extension)
91  ));
92  return false;
93  }
94 
95  // convert the uploaded file to JPEG
96  $this->file_converter->convertToFormat(
97  $this->getDefaultBackgroundImageTempFilePath($extension),
98  $new_image_path,
99  ImageOutputOptions::FORMAT_JPG
100  );
101 
102  $this->file_converter->croppedSquare(
103  $this->getDefaultBackgroundImageTempFilePath($extension),
105  100,
106  ImageOutputOptions::FORMAT_JPG
107  );
108 
109  if (!is_file($new_image_path) || !file_exists($new_image_path)) {
110  // Something went wrong converting the file. Use the original file and hope, that PDF can work with it.
111  $this->cert_logger->error(sprintf(
112  "Could not convert certificate background image from '%s' as JPEG to '%s', trying fallback ...",
113  $this->getDefaultBackgroundImageTempFilePath($extension),
114  $new_image_path
115  ));
117  $this->getDefaultBackgroundImageTempFilePath($extension),
118  $new_image_file_name,
119  $new_image_path
120  )) {
121  $this->cert_logger->error(sprintf(
122  "Could not upload certificate background image from '%s' to final file '%s' (name: '%s')",
123  $this->getDefaultBackgroundImageTempFilePath($extension),
124  $new_image_path,
125  $new_image_file_name
126  ));
127  return false;
128  }
129  }
130 
131  if (
132  is_file($this->getDefaultBackgroundImageTempFilePath($extension))
133  && file_exists($this->getDefaultBackgroundImageTempFilePath($extension))
134  ) {
135  unlink($this->getDefaultBackgroundImageTempFilePath($extension));
136  }
137 
138  if (file_exists($new_image_path) && (filesize($new_image_path) > 0)) {
139  $old_path = $this->getDefaultBackgroundImagePath();
140  $old_path_thumb = $this->getDefaultBackgroundImageThumbPath();
141  $old_relative_path = $this->getDefaultBackgroundImagePath(true);
142  $this->certificate_settings->set('defaultImageFileName', $new_image_file_name);
143  $new_relative_path = $this->getDefaultBackgroundImagePath(true);
144 
145  $this->certificate_repo->updateDefaultBackgroundImagePaths($old_relative_path, $new_relative_path);
146 
147  if (
148  !$this->certificate_repo->isBackgroundImageUsed($old_relative_path)
149  && !$this->user_certificate_repo->isBackgroundImageUsed($old_relative_path)
150  ) {
151  if (is_file($old_path) && file_exists($old_path)) {
152  unlink($old_path);
153  }
154 
155  if (is_file($old_path_thumb) && file_exists($old_path_thumb)) {
156  unlink($old_path_thumb);
157  }
158  }
159  return true;
160  }
161 
162  $this->cert_logger->error(sprintf(
163  "Final background image '%s' does not exist or is empty",
164  $new_image_path
165  ));
166  }
167 
168  return false;
169  }
getDefaultBackgroundImageThumbPath(bool $relativePath=false)
getBackgroundImageDefaultFolder(bool $relativePath=false)
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
getDefaultBackgroundImageTempFilePath(string $extension)
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
getDefaultBackgroundImagePath(bool $relativePath=false)
+ Here is the call graph for this function:

Field Documentation

◆ $cert_logger

ilLogger ilObjCertificateSettings::$cert_logger
private

Definition at line 33 of file class.ilObjCertificateSettings.php.

◆ $certificate_repo

ilCertificateTemplateDatabaseRepository ilObjCertificateSettings::$certificate_repo
private

Definition at line 37 of file class.ilObjCertificateSettings.php.

◆ $certificate_settings

ilSetting ilObjCertificateSettings::$certificate_settings
private

Definition at line 36 of file class.ilObjCertificateSettings.php.

◆ $file_converter

ILIAS Filesystem Util Convert LegacyImages ilObjCertificateSettings::$file_converter
private

Definition at line 34 of file class.ilObjCertificateSettings.php.

◆ $user_certificate_repo

ilUserCertificateRepository ilObjCertificateSettings::$user_certificate_repo
private

Definition at line 38 of file class.ilObjCertificateSettings.php.

◆ $uuid_factory

Factory ilObjCertificateSettings::$uuid_factory
private

Definition at line 35 of file class.ilObjCertificateSettings.php.


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