27 protected int $id = 0;
41 $this->resource_storage =
$DIC->resourceStorage();
42 $this->upload_service =
$DIC->upload();
43 $this->main_template =
$DIC->ui()->mainTemplate();
44 $this->db =
$DIC->database();
62 $set =
$ilDB->query(
"SELECT * FROM badge_image_templ_type");
63 while ($row =
$ilDB->fetchAssoc($set)) {
64 $types[$row[
"tmpl_id"]][] = $row[
"type_id"];
67 $set =
$ilDB->query(
"SELECT * FROM badge_image_template" .
69 while ($row =
$ilDB->fetchAssoc($set)) {
70 $row[
"types"] = (array) (
$types[$row[
"id"]] ??
null);
73 $obj->importDBRow($row);
87 foreach (self::getInstances() as $tmpl) {
88 if (!count($tmpl->getTypes()) || in_array($a_type_unique_id, $tmpl->getTypes(),
true)) {
101 protected function setId(
int $a_id): void
113 $this->title = trim($a_value);
121 protected function setImage(?
string $a_value): void
123 if ($a_value !==
null) {
124 $this->image = trim($a_value);
138 $this->types = is_array(
$types)
154 if ($this->
getId() &&
155 $a_upload_meta[
"tmp_name"]) {
161 $suffix = strtolower(array_pop($exp));
162 $tgt =
$path .
"img" . $this->
getId() .
"." . $suffix;
174 if (!$this->upload_service->hasBeenProcessed()) {
175 $this->upload_service->process();
177 if ($this->upload_service->hasUploads()) {
178 $array_result = $this->upload_service->getResults();
179 $array_result = array_pop($array_result);
180 if ($array_result->getName() !==
'') {
185 $identification = $this->resource_storage->manage()->upload($array_result, $stakeholder);
191 $this->main_template->setOnScreenMessage(
'failure',
$e->getMessage(),
true);
197 if ($this->
getId()) {
202 $exp = explode(
".", $this->
getImage());
203 $suffix = strtolower(array_pop($exp));
214 ?
string $a_subdir =
null
219 $path = $storage->getAbsolutePath() .
"/";
222 $path .= $a_subdir .
"/";
224 if (!is_dir(
$path)) {
237 protected function read(
int $a_id): void
241 $set =
$ilDB->query(
"SELECT * FROM badge_image_template" .
242 " WHERE id = " .
$ilDB->quote($a_id,
"integer"));
243 if (
$ilDB->numRows($set)) {
244 $row =
$ilDB->fetchAssoc($set);
245 $row[
"types"] = $this->readTypes($a_id);
246 $this->importDBRow($row);
256 $set =
$ilDB->query(
"SELECT * FROM badge_image_templ_type WHERE tmpl_id = " .
$ilDB->quote($a_id,
"integer"));
257 while ($row =
$ilDB->fetchAssoc($set)) {
258 $res[] = $row[
"type_id"];
270 $this->setId($a_row[
"id"]);
271 $this->setTitle($a_row[
"title"]);
272 if (isset($a_row[
"image"])) {
273 $this->setImage($a_row[
"image"]);
275 if (isset($a_row[
"image_rid"])) {
276 $this->setImageRid($a_row[
"image_rid"]);
278 $this->setTypes($a_row[
"types"]);
285 if ($this->
getId()) {
290 $id =
$ilDB->nextId(
"badge_image_template");
293 $fields = $this->getPropertiesForStorage();
294 $fields[
"id"] = array(
"integer",
$id);
296 $ilDB->insert(
"badge_image_template", $fields);
305 if (!$this->
getId()) {
310 $fields = $this->getPropertiesForStorage();
313 "badge_image_template",
315 array(
"id" => array(
"integer", $this->
getId()))
321 public function delete():
void
325 if (!$this->
getId()) {
332 $ilDB->manipulate(
"DELETE FROM badge_image_template" .
333 " WHERE id = " .
$ilDB->quote($this->getId(),
"integer"));
342 "title" => [
"text", $this->
getTitle()],
343 "image" => [
"text", $this->getImage()],
344 "image_rid" => [
"text", $this->getImageRid()]
352 if ($this->
getId()) {
353 $ilDB->manipulate(
"DELETE FROM badge_image_templ_type" .
354 " WHERE tmpl_id = " .
$ilDB->quote($this->getId(),
"integer"));
356 if ($this->getTypes()) {
357 foreach ($this->getTypes() as $type) {
359 "tmpl_id" => array(
"integer", $this->
getId()),
360 "type_id" => array(
"text", $type)
362 $ilDB->insert(
"badge_image_templ_type", $fields);
370 return $this->image_rid;
375 $this->image_rid = $image_rid;
382 if ($this->getImageRid()) {
383 $identification = $this->resource_storage->manage()->find($this->getImageRid());
384 if ($identification !==
null) {
385 $image_src = $this->resource_storage->consume()->src($identification)->getSrc();
387 } elseif ($this->getImage()) {
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Class IllegalStateException.
Class ResourceIdentification.
FileUpload $upload_service
Services $resource_storage
setTitle(string $a_value)
processImageUpload(ilBadgeImageTemplate $badge)
__construct(?int $a_id=null)
uploadImage(array $a_upload_meta)
getFilePath(int $a_id, ?string $a_subdir=null)
Init file system storage.
importDBRow(array $a_row)
ilGlobalTemplateInterface $main_template
setImageRid(?string $image_rid=null)
setTypes(?array $types=null)
static getInstancesByType(string $a_type_unique_id)
getPropertiesForStorage()
setImage(?string $a_value)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static getValidFilename(string $a_filename)
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
static signFile(string $path_to_file)