27 protected int $id = 0;
42 $this->resource_storage =
$DIC->resourceStorage();
43 $this->upload_service =
$DIC->upload();
44 $this->main_template =
$DIC->ui()->mainTemplate();
45 $this->log =
$DIC->logger()->forComponent(
'badge');
46 $this->db =
$DIC->database();
64 $set =
$ilDB->query(
'SELECT * FROM badge_image_templ_type');
65 while ($row =
$ilDB->fetchAssoc($set)) {
66 $types[$row[
'tmpl_id']][] = $row[
'type_id'];
69 $set =
$ilDB->query(
'SELECT * FROM badge_image_template' .
71 while ($row =
$ilDB->fetchAssoc($set)) {
72 $row[
'types'] = (array) (
$types[$row[
'id']] ??
null);
75 $obj->importDBRow($row);
89 foreach (self::getInstances() as $tmpl) {
90 if (!count($tmpl->getTypes()) || in_array($a_type_unique_id, $tmpl->getTypes(),
true)) {
102 protected function setId(
int $a_id): void
114 $this->title = trim($a_value);
132 $this->types = is_array(
$types)
140 if (!$this->upload_service->hasBeenProcessed()) {
141 $this->upload_service->process();
143 if ($this->upload_service->hasUploads()) {
144 $array_result = $this->upload_service->getResults();
145 $array_result = array_pop($array_result);
146 if ($array_result->getName() !==
'') {
151 $identification = $this->resource_storage->manage()->upload($array_result, $stakeholder);
157 $this->main_template->setOnScreenMessage(
'failure',
$e->getMessage(),
true);
165 protected function read(
int $a_id): void
169 $set =
$ilDB->query(
'SELECT * FROM badge_image_template' .
170 ' WHERE id = ' .
$ilDB->quote($a_id,
'integer'));
171 if (
$ilDB->numRows($set)) {
172 $row =
$ilDB->fetchAssoc($set);
184 $set =
$ilDB->query(
'SELECT * FROM badge_image_templ_type WHERE tmpl_id = ' .
$ilDB->quote($a_id,
'integer'));
185 while ($row =
$ilDB->fetchAssoc($set)) {
186 $res[] = $row[
'type_id'];
198 $this->
setId($a_row[
'id']);
200 if (isset($a_row[
'image_rid'])) {
210 if ($this->
getId()) {
216 $id =
$ilDB->nextId(
'badge_image_template');
220 $fields[
'id'] = [
'integer',
$id];
222 $ilDB->insert(
'badge_image_template', $fields);
231 if (!$this->
getId()) {
240 'badge_image_template',
242 [
'id' => [
'integer', $this->
getId()]]
248 public function delete():
void
252 if (!$this->
getId()) {
257 if ($image_rid !==
null) {
259 $this->resource_storage->manage()->remove(
263 }
catch (Exception
$e) {
264 $this->log->warning(sprintf(
265 'There was an exception, while deleting the badge image template with id %s. Exception: %s',
272 $ilDB->manipulate(
'DELETE FROM badge_image_template' .
273 ' WHERE id = ' .
$ilDB->quote($this->getId(),
'integer'));
282 'title' => [
'text', $this->
getTitle()],
291 if ($this->
getId()) {
292 $ilDB->manipulate(
'DELETE FROM badge_image_templ_type' .
293 ' WHERE tmpl_id = ' .
$ilDB->quote($this->getId(),
'integer'));
296 foreach ($this->
getTypes() as $type) {
298 'tmpl_id' => [
'integer', $this->
getId()],
299 'type_id' => [
'text', $type]
301 $ilDB->insert(
'badge_image_templ_type', $fields);
310 if ($this->image_rid ===
null || $this->image_rid ===
'' || $this->image_rid ===
'-') {
325 if ($image_rid ===
null) {
329 $identification = $this->resource_storage->manage()->find(
$image_rid);
330 if ($identification ===
null) {
334 return $this->resource_storage->consume()->src($identification)->getSrc();
Class IllegalStateException.
Class ResourceIdentification.
FileUpload $upload_service
Services $resource_storage
setTitle(string $a_value)
processImageUpload(ilBadgeImageTemplate $badge)
__construct(?int $a_id=null)
importDBRow(array $a_row)
ilGlobalTemplateInterface $main_template
setImageRid(?string $image_rid=null)
setTypes(?array $types=null)
static getInstancesByType(string $a_type_unique_id)
getPropertiesForStorage()
Component logger with individual log levels by component id.
foreach($_POST as $key=> $value) $res