3 declare(strict_types=1);
39 protected array
$bold = array();
53 $this->db = $DIC->database();
54 $this->type = $a_type;
64 if (isset(self::$instances[$a_type])) {
65 return self::$instances[$a_type];
76 foreach ($this->substitutions as $field_id) {
77 if (isset($a_definitions[$field_id])) {
78 $sorted[$field_id] = $a_definitions[$field_id];
79 unset($a_definitions[$field_id]);
82 return array_merge($sorted, $a_definitions);
97 $this->enabled_desc = $a_status;
107 $this->enabled_field_names = $a_status;
121 if (!isset($this->active_fields[$field_id])) {
125 $value = $this->
parseValue($field_id, $values_records);
127 if ($value === null) {
128 if ($this->
hasNewline($field_id) and $counter) {
129 $substituted[$counter - 1][
'newline'] =
true;
134 $substituted[$counter][
'name'] = $this->active_fields[$field_id];
135 $substituted[$counter][
'value'] = $value;
136 $substituted[$counter][
'bold'] = $this->
isBold($field_id);
138 $substituted[$counter][
'newline'] =
true;
140 $substituted[$counter][
'newline'] =
false;
148 private function parseValue(
int $a_field_id, array $a_values_records): ?string
150 foreach ($a_values_records as $a_values) {
151 if ($a_values->getADTGroup()->hasElement((
string) $a_field_id)) {
152 $element = $a_values->getADTGroup()->getElement((
string) $a_field_id);
153 if (!$element->isNull()) {
163 $this->substitutions = array();
164 $this->bold = array();
165 $this->newline = array();
173 public function appendSubstitution(
int $a_field_id,
bool $a_bold =
false,
bool $a_newline =
false): void
175 $this->substitutions[] = $a_field_id;
177 $this->bold[] = $a_field_id;
180 $this->newline[] = $a_field_id;
194 public function isBold(
int $a_field_id): bool
196 return in_array($a_field_id, $this->bold);
201 return in_array($a_field_id, $this->newline);
212 $ilDB = $DIC[
'ilDB'];
215 $substitutions = array();
217 foreach ($this->substitutions as $field_id) {
218 $substitutions[$counter][
'field_id'] = $field_id;
219 $substitutions[$counter][
'bold'] = $this->
isBold($field_id);
220 $substitutions[$counter][
'newline'] = $this->
hasNewline($field_id);
224 $query =
"DELETE FROM adv_md_substitutions WHERE obj_type = " .
$ilDB->quote($this->type,
'text');
228 'obj_type' => array(
'text', $this->type),
229 'substitution' => array(
'clob', serialize($substitutions)),
233 $ilDB->insert(
'adv_md_substitutions', $values);
244 $ilDB = $DIC[
'ilDB'];
247 $query =
"SELECT active,field_id,amfd.title FROM adv_md_record amr " .
248 "JOIN adv_md_record_objs amro ON amr.record_id = amro.record_id " .
249 "JOIN adv_mdf_definition amfd ON amr.record_id = amfd.record_id " .
250 "WHERE active = 1 " .
251 "AND obj_type = " . $this->db->quote($this->type,
'text') .
" ";
253 $this->active =
$res->numRows() ? true :
false;
255 $this->active_fields[(
int) $row->field_id] = (
string) $row->title;
258 $query =
"SELECT * FROM adv_md_substitutions " .
259 "WHERE obj_type = " . $this->db->quote($this->type,
'text') .
" ";
261 $this->substitutions = array();
262 $this->bold = array();
263 $this->newline = array();
265 $tmp_substitutions = unserialize((
string) $row->substitution);
266 if (is_array($tmp_substitutions)) {
267 foreach ($tmp_substitutions as $substitution) {
268 if ($substitution[
'field_id']) {
269 $this->substitutions[] = $substitution[
'field_id'];
271 if ($substitution[
'bold']) {
272 $this->bold[] = $substitution[
'field_id'];
274 if ($substitution[
'newline']) {
275 $this->newline[] = $substitution[
'field_id'];
279 $this->enabled_desc = !$row->hide_description;
280 $this->enabled_field_names = !$row->hide_field_names;
hasNewline(int $a_field_id)
__construct(string $a_type)
static preloadedRead(string $a_type, int $a_obj_id)
bool $enabled_field_names
enableDescription(bool $a_status)
getParsedSubstitutions(int $a_ref_id, int $a_obj_id)
read()
Read db entries private.
enableFieldNames(bool $a_status)
sortDefinitions(array $a_definitions)
Sort definitions.
appendSubstitution(int $a_field_id, bool $a_bold=false, bool $a_newline=false)
append field to substitutions public
parseValue(int $a_field_id, array $a_values_records)
isSubstituted(int $a_field_id)
static _getInstanceByObjectType(string $a_type)