ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
HeaderTitleRepo.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Administration;
22
24use ilObjUser;
25use ilStr;
26use ilObject;
27
28readonly class HeaderTitleRepo
29{
32 private int $obj_id;
33
34 public function __construct()
35 {
36 global $DIC;
37 $this->db = $DIC->database();
38 $this->user = $DIC->user();
39 $this->obj_id = SYSTEM_FOLDER_ID;
40 }
41
42 public function getHeaderTitle(): string
43 {
44 $title = '';
45
46 $q = "SELECT title FROM object_translation " .
47 "WHERE obj_id = " . $this->db->quote($this->obj_id, 'integer') . " " .
48 "AND lang_default = 1";
49 $r = $this->db->query($q);
50 $row = $this->db->fetchObject($r);
51 if ($row !== null) {
52 $title = (string) $row->title;
53 }
54
55 $q = "SELECT title FROM object_translation " .
56 "WHERE obj_id = " . $this->db->quote($this->obj_id, 'integer') . " " .
57 "AND lang_code = " .
58 $this->db->quote($this->user->getCurrentLanguage(), 'text') . " " .
59 "AND NOT lang_default = 1";
60 $r = $this->db->query($q);
61 $row = $this->db->fetchObject($r);
62
63 if ($row !== null) {
64 $title = (string) $row->title;
65 }
66
67 return $title;
68 }
69
70 public function getHeaderTitleTranslations(): array
71 {
72 $q = "SELECT * FROM object_translation WHERE obj_id = " .
73 $this->db->quote($this->obj_id, 'integer') . " ORDER BY lang_default DESC";
74 $r = $this->db->query($q);
75
76 $num = 0;
77 while ($row = $this->db->fetchObject($r)) {
78 $data["Fobject"][$num] = array("title" => $row->title,
80 (string) $row->description,
82 true
83 ),
84 "lang" => $row->lang_code
85 );
86 $num++;
87 }
88
89 // first entry is always the default language
90 $data["default_language"] = 0;
91
92 return $data ?? [];
93 }
94
95 public function removeHeaderTitleTranslations(): void
96 {
97 $query = "DELETE FROM object_translation WHERE obj_id= " .
98 $this->db->quote($this->obj_id, 'integer');
99 $this->db->manipulate($query);
100 }
101
102 public function addHeaderTitleTranslation(string $a_title, string $a_lang, bool $a_lang_default): void
103 {
104 $query = "INSERT INTO object_translation " .
105 "(obj_id,title,description,lang_code,lang_default) " .
106 "VALUES " .
107 "(" . $this->db->quote($this->obj_id, 'integer') . "," .
108 $this->db->quote($a_title, 'text') . "," .
109 $this->db->quote('', 'text') . "," .
110 $this->db->quote($a_lang, 'text') . "," .
111 $this->db->quote($a_lang_default, 'integer') . ")";
112 $res = $this->db->manipulate($query);
113 }
114}
addHeaderTitleTranslation(string $a_title, string $a_lang, bool $a_lang_default)
User class.
Class ilObject Basic functions for all objects.
const DESC_LENGTH
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: class.ilStr.php:20
static shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
const SYSTEM_FOLDER_ID
Definition: constants.php:35
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26
$q
Definition: shib_logout.php:23