19 declare(strict_types=1);
33 protected array
$bold = array();
47 $this->db = $DIC->database();
48 $this->type = $a_type;
58 if (isset(self::$instances[$a_type])) {
59 return self::$instances[$a_type];
70 foreach ($this->substitutions as $field_id) {
71 if (isset($a_definitions[$field_id])) {
72 $sorted[$field_id] = $a_definitions[$field_id];
73 unset($a_definitions[$field_id]);
76 return array_merge($sorted, $a_definitions);
91 $this->enabled_desc = $a_status;
101 $this->enabled_field_names = $a_status;
115 if (!isset($this->active_fields[$field_id])) {
119 $value = $this->
parseValue($field_id, $values_records);
121 if ($value ===
null) {
122 if ($this->
hasNewline($field_id) and $counter) {
123 $substituted[$counter - 1][
'newline'] =
true;
128 $substituted[$counter][
'name'] = $this->active_fields[$field_id];
129 $substituted[$counter][
'value'] = $value;
130 $substituted[$counter][
'bold'] = $this->
isBold($field_id);
132 $substituted[$counter][
'newline'] =
true;
134 $substituted[$counter][
'newline'] =
false;
142 private function parseValue(
int $a_field_id, array $a_values_records): ?string
144 foreach ($a_values_records as $a_values) {
145 if ($a_values->getADTGroup()->hasElement((
string) $a_field_id)) {
146 $element = $a_values->getADTGroup()->getElement((
string) $a_field_id);
147 if (!$element->isNull()) {
157 $this->substitutions = array();
158 $this->
bold = array();
159 $this->newline = array();
167 public function appendSubstitution(
int $a_field_id,
bool $a_bold =
false,
bool $a_newline =
false): void
169 $this->substitutions[] = $a_field_id;
171 $this->
bold[] = $a_field_id;
174 $this->newline[] = $a_field_id;
188 public function isBold(
int $a_field_id): bool
190 return in_array($a_field_id, $this->
bold);
195 return in_array($a_field_id, $this->newline);
206 $ilDB = $DIC[
'ilDB'];
209 $substitutions = array();
211 foreach ($this->substitutions as $field_id) {
212 $substitutions[$counter][
'field_id'] = $field_id;
213 $substitutions[$counter][
'bold'] = $this->
isBold($field_id);
214 $substitutions[$counter][
'newline'] = $this->
hasNewline($field_id);
218 $query =
"DELETE FROM adv_md_substitutions WHERE obj_type = " .
$ilDB->quote($this->type,
'text');
222 'obj_type' => array(
'text', $this->type),
223 'substitution' => array(
'clob', serialize($substitutions)),
227 $ilDB->insert(
'adv_md_substitutions', $values);
238 $ilDB = $DIC[
'ilDB'];
241 $query =
"SELECT active,field_id,amfd.title FROM adv_md_record amr " .
242 "JOIN adv_md_record_objs amro ON amr.record_id = amro.record_id " .
243 "JOIN adv_mdf_definition amfd ON amr.record_id = amfd.record_id " .
244 "WHERE active = 1 " .
245 "AND obj_type = " . $this->db->quote($this->type,
'text') .
" ";
246 $res = $this->db->query($query);
247 $this->active =
$res->numRows() ? true :
false;
249 $this->active_fields[(
int) $row->field_id] = (
string) $row->title;
252 $query =
"SELECT * FROM adv_md_substitutions " .
253 "WHERE obj_type = " . $this->db->quote($this->type,
'text') .
" ";
254 $res = $this->db->query($query);
255 $this->substitutions = array();
256 $this->
bold = array();
257 $this->newline = array();
259 $tmp_substitutions = unserialize((
string) $row->substitution);
260 if (is_array($tmp_substitutions)) {
261 foreach ($tmp_substitutions as $substitution) {
262 if ($substitution[
'field_id']) {
263 $this->substitutions[] = $substitution[
'field_id'];
265 if ($substitution[
'bold']) {
266 $this->
bold[] = $substitution[
'field_id'];
268 if ($substitution[
'newline']) {
269 $this->newline[] = $substitution[
'field_id'];
273 $this->enabled_desc = !$row->hide_description;
274 $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)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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)
bold()
expected output: > ILIAS shows the rendered Component.
isSubstituted(int $a_field_id)
static _getInstanceByObjectType(string $a_type)