ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAdvancedMDFieldTranslation.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
27 public const TABLE_NAME = 'adv_md_field_int';
28
29 private int $field_id;
30 private string $title;
31 private string $description;
32 private string $lang_key;
33
35
39 public function __construct(int $field_id, string $title, string $description, string $lang_key)
40 {
41 global $DIC;
42
43 $this->db = $DIC->database();
44
45 $this->field_id = $field_id;
46 $this->title = $title;
47 $this->description = $description;
48 $this->lang_key = $lang_key;
49 }
50
51 public function setTitle(string $title): void
52 {
53 $this->title = $title;
54 }
55
56 public function setDescription(string $description): void
57 {
58 $this->description = $description;
59 }
60
61 public function getFieldId(): int
62 {
63 return $this->field_id;
64 }
65
66 public function getTitle(): string
67 {
68 return $this->title;
69 }
70
71 public function getDescription(): string
72 {
73 return $this->description;
74 }
75
76 public function getLangKey(): string
77 {
78 return $this->lang_key;
79 }
80
81 public function update(): void
82 {
83 $query = 'select * from ' . self::TABLE_NAME . ' ' .
84 'where field_id = ' . $this->db->quote($this->getFieldId(), ilDBConstants::T_INTEGER) . ' ' .
85 'and lang_code = ' . $this->db->quote($this->getLangKey(), ilDBConstants::T_TEXT) . ' ';
86 $res = $this->db->query($query);
87 if (!$res->numRows()) {
88 $this->insert();
89 return;
90 }
91
92 $query = 'update ' . self::TABLE_NAME . ' ' .
93 'set title = ' . $this->db->quote($this->getTitle(), ilDBConstants::T_TEXT) . ', ' .
94 'description = ' . $this->db->quote($this->getDescription(), ilDBConstants::T_TEXT) . ' ' .
95 'where field_id = ' . $this->db->quote($this->getFieldId(), ilDBConstants::T_INTEGER) . ' ' .
96 'and lang_code = ' . $this->db->quote($this->getLangKey(), ilDBConstants::T_TEXT);
97
98 $this->db->manipulate($query);
99 }
100
101 public function delete(): void
102 {
103 $query = 'delete from ' . self::TABLE_NAME . ' ' .
104 'where field_id = ' . $this->db->quote($this->getFieldId(), ilDBConstants::T_INTEGER) . ' and ' .
105 'lang_code = ' . $this->db->quote($this->getLangKey(), ilDBConstants::T_TEXT);
106 $this->db->manipulate($query);
107 }
108
109 public function insert(): void
110 {
111 $query = 'insert into ' . self::TABLE_NAME . ' (field_id, title, lang_code, description) ' .
112 'values ( ' .
113 $this->db->quote($this->getFieldId(), ilDBConstants::T_INTEGER) . ', ' .
114 $this->db->quote($this->getTitle(), ilDBConstants::T_TEXT) . ', ' .
115 $this->db->quote($this->getLangKey(), ilDBConstants::T_TEXT) . ', ' .
116 $this->db->quote($this->getDescription(), ilDBConstants::T_TEXT) . ' ' .
117 ')';
118 $this->db->manipulate($query);
119 }
120}
Class ilAdvancedMDFieldTranslation.
__construct(int $field_id, string $title, string $description, string $lang_key)
ilAdvancedMDFieldTranslation constructor.
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26