ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilAdvancedMDFieldTranslation.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4
10{
11 public const TABLE_NAME = 'adv_md_field_int';
12
16 private $field_id;
17
21 private $title;
22
26 private $description;
27
31 private $lang_key;
32
33
37 private $db;
38
42 public function __construct(int $field_id, string $title, string $description, string $lang_key)
43 {
44 global $DIC;
45
46 $this->db = $DIC->database();
47
48 $this->field_id = $field_id;
49 $this->title = $title;
50 $this->description = $description;
51 $this->lang_key = $lang_key;
52 }
53
57 public function setTitle(string $title) : void
58 {
59 $this->title = $title;
60 }
61
65 public function setDescription(string $description) : void
66 {
67 $this->description = $description;
68 }
69
70
74 public function getFieldId() : int
75 {
76 return $this->field_id;
77 }
78
82 public function getTitle() : string
83 {
84 return $this->title;
85 }
86
90 public function getDescription() : string
91 {
92 return $this->description;
93 }
94
98 public function getLangKey() : string
99 {
100 return $this->lang_key;
101 }
102
106 public function update()
107 {
108 $query = 'select * from ' . self::TABLE_NAME . ' ' .
109 'where field_id = ' . $this->db->quote($this->getFieldId(), ilDBConstants::T_INTEGER) . ' ' .
110 'and lang_code = ' . $this->db->quote($this->getLangKey(), ilDBConstants::T_TEXT) . ' ';
111 $res = $this->db->query($query);
112 if (!$res->numRows()) {
113 return $this->insert();
114 }
115
116 $query = 'update ' . self::TABLE_NAME . ' ' .
117 'set title = ' . $this->db->quote($this->getTitle(), ilDBConstants::T_TEXT) . ', ' .
118 'description = ' . $this->db->quote($this->getDescription(), ilDBConstants::T_TEXT) . ' ' .
119 'where field_id = ' . $this->db->quote($this->getFieldId(), ilDBConstants::T_INTEGER) . ' ' .
120 'and lang_code = ' . $this->db->quote($this->getLangKey(), ilDBConstants::T_TEXT);
121
122 $this->db->manipulate($query);
123 }
124
125 public function delete()
126 {
127 $query = 'delete from ' . self::TABLE_NAME . ' ' .
128 'where field_id = ' . $this->db->quote($this->getFieldId(), ilDBConstants::T_INTEGER) . ' and ' .
129 'lang_code = ' . $this->db->quote($this->getLangKey(), ilDBConstants::T_TEXT);
130 $this->db->manipulate($query);
131 }
132
133 public function insert()
134 {
135 $query = 'insert into ' . self::TABLE_NAME . ' (field_id, title, lang_code, description) ' .
136 'values ( ' .
137 $this->db->quote($this->getFieldId(), ilDBConstants::T_INTEGER) . ', ' .
138 $this->db->quote($this->getTitle() , ilDBConstants::T_TEXT) . ', ' .
139 $this->db->quote($this->getLangKey(), ilDBConstants::T_TEXT) . ', ' .
140 $this->db->quote($this->getDescription(), ilDBConstants::T_TEXT) . ' ' .
141 ')';
142 $this->db->manipulate($query);
143 }
144
145}
An exception for terminatinating execution or to throw for unit testing.
Class ilAdvancedMDFieldTranslation.
__construct(int $field_id, string $title, string $description, string $lang_key)
ilAdvancedMDFieldTranslation constructor.
global $DIC
Definition: goto.php:24
$query
foreach($_POST as $key=> $value) $res