ILIAS  release_8 Revision v8.24
ilAdvancedMDSubstitution Class Reference
+ Collaboration diagram for ilAdvancedMDSubstitution:

Public Member Functions

 sortDefinitions (array $a_definitions)
 Sort definitions. More...
 
 isActive ()
 
 isDescriptionEnabled ()
 
 enableDescription (bool $a_status)
 
 enabledFieldNames ()
 
 enableFieldNames (bool $a_status)
 
 getParsedSubstitutions (int $a_ref_id, int $a_obj_id)
 
 resetSubstitutions ()
 
 appendSubstitution (int $a_field_id, bool $a_bold=false, bool $a_newline=false)
 append field to substitutions @access public More...
 
 getSubstitutions ()
 
 isSubstituted (int $a_field_id)
 
 isBold (int $a_field_id)
 
 hasNewline (int $a_field_id)
 
 update ()
 update @access public More...
 

Static Public Member Functions

static _getInstanceByObjectType (string $a_type)
 

Protected Attributes

ilDBInterface $db
 
string $type
 
array $substitutions
 
array $bold = array()
 
array $newline = array()
 
bool $enabled_desc = true
 
bool $enabled_field_names = true
 
bool $active = false
 
array $date_fields = array()
 
array $datetime_fields = array()
 
array $active_fields = array()
 

Private Member Functions

 __construct (string $a_type)
 
 parseValue (int $a_field_id, array $a_values_records)
 
 read ()
 Read db entries @access private. More...
 
 initECSMappings ()
 

Static Private Attributes

static array $instances = null
 
static array $mappings = null
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilAdvancedMDSubstitution::__construct ( string  $a_type)
private

Definition at line 49 of file class.ilAdvancedMDSubstitution.php.

50 {
51 global $DIC;
52
53 $this->db = $DIC->database();
54 $this->type = $a_type;
55
56 $this->initECSMappings();
57 $this->read();
58 }
read()
Read db entries @access private.
global $DIC
Definition: feed.php:28

References $DIC, initECSMappings(), and read().

+ Here is the call graph for this function:

Member Function Documentation

◆ _getInstanceByObjectType()

◆ appendSubstitution()

ilAdvancedMDSubstitution::appendSubstitution ( int  $a_field_id,
bool  $a_bold = false,
bool  $a_newline = false 
)

append field to substitutions @access public

Parameters
intfield id

Definition at line 173 of file class.ilAdvancedMDSubstitution.php.

173 : void
174 {
175 $this->substitutions[] = $a_field_id;
176 if ($a_bold) {
177 $this->bold[] = $a_field_id;
178 }
179 if ($a_newline) {
180 $this->newline[] = $a_field_id;
181 }
182 }

◆ enableDescription()

ilAdvancedMDSubstitution::enableDescription ( bool  $a_status)

Definition at line 95 of file class.ilAdvancedMDSubstitution.php.

95 : void
96 {
97 $this->enabled_desc = $a_status;
98 }

◆ enabledFieldNames()

ilAdvancedMDSubstitution::enabledFieldNames ( )

Definition at line 100 of file class.ilAdvancedMDSubstitution.php.

100 : bool
101 {
103 }

References $enabled_field_names.

Referenced by getParsedSubstitutions(), and update().

+ Here is the caller graph for this function:

◆ enableFieldNames()

ilAdvancedMDSubstitution::enableFieldNames ( bool  $a_status)

Definition at line 105 of file class.ilAdvancedMDSubstitution.php.

105 : void
106 {
107 $this->enabled_field_names = $a_status;
108 }

◆ getParsedSubstitutions()

ilAdvancedMDSubstitution::getParsedSubstitutions ( int  $a_ref_id,
int  $a_obj_id 
)

Definition at line 110 of file class.ilAdvancedMDSubstitution.php.

110 : array
111 {
112 if (!count($this->getSubstitutions())) {
113 return array();
114 }
115
116 $values_records = ilAdvancedMDValues::preloadedRead($this->type, $a_obj_id);
117
118 $counter = 0;
119 $substituted = [];
120 foreach ($this->getSubstitutions() as $field_id) {
121 if (!isset($this->active_fields[$field_id])) {
122 continue;
123 }
124
125 $value = $this->parseValue($field_id, $values_records);
126
127 if ($value === null) {
128 if ($this->hasNewline($field_id) and $counter) {
129 $substituted[$counter - 1]['newline'] = true;
130 }
131 continue;
132 }
133
134 $substituted[$counter]['name'] = $this->active_fields[$field_id];
135 $substituted[$counter]['value'] = $value;
136 $substituted[$counter]['bold'] = $this->isBold($field_id);
137 if ($this->hasNewline($field_id)) {
138 $substituted[$counter]['newline'] = true;
139 } else {
140 $substituted[$counter]['newline'] = false;
141 }
142 $substituted[$counter]['show_field'] = $this->enabledFieldNames();
143 $counter++;
144 }
145 return $substituted;
146 }
parseValue(int $a_field_id, array $a_values_records)
static preloadedRead(string $a_type, int $a_obj_id)

References enabledFieldNames(), getSubstitutions(), hasNewline(), isBold(), parseValue(), and ilAdvancedMDValues\preloadedRead().

+ Here is the call graph for this function:

◆ getSubstitutions()

ilAdvancedMDSubstitution::getSubstitutions ( )

Definition at line 184 of file class.ilAdvancedMDSubstitution.php.

184 : array
185 {
186 return !$this->substitutions ? array() : $this->substitutions;
187 }

References $substitutions.

Referenced by getParsedSubstitutions(), and isSubstituted().

+ Here is the caller graph for this function:

◆ hasNewline()

ilAdvancedMDSubstitution::hasNewline ( int  $a_field_id)

Definition at line 199 of file class.ilAdvancedMDSubstitution.php.

199 : bool
200 {
201 return in_array($a_field_id, $this->newline);
202 }

Referenced by getParsedSubstitutions(), and update().

+ Here is the caller graph for this function:

◆ initECSMappings()

ilAdvancedMDSubstitution::initECSMappings ( )
private

Definition at line 284 of file class.ilAdvancedMDSubstitution.php.

284 : void
285 {
286 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ isActive()

ilAdvancedMDSubstitution::isActive ( )

Definition at line 85 of file class.ilAdvancedMDSubstitution.php.

85 : bool
86 {
87 return $this->active;
88 }

References $active.

◆ isBold()

ilAdvancedMDSubstitution::isBold ( int  $a_field_id)

Definition at line 194 of file class.ilAdvancedMDSubstitution.php.

194 : bool
195 {
196 return in_array($a_field_id, $this->bold);
197 }

Referenced by getParsedSubstitutions(), and update().

+ Here is the caller graph for this function:

◆ isDescriptionEnabled()

ilAdvancedMDSubstitution::isDescriptionEnabled ( )

Definition at line 90 of file class.ilAdvancedMDSubstitution.php.

90 : bool
91 {
93 }

References $enabled_desc.

Referenced by update().

+ Here is the caller graph for this function:

◆ isSubstituted()

ilAdvancedMDSubstitution::isSubstituted ( int  $a_field_id)

Definition at line 189 of file class.ilAdvancedMDSubstitution.php.

189 : bool
190 {
191 return in_array($a_field_id, $this->getSubstitutions());
192 }

References getSubstitutions().

+ Here is the call graph for this function:

◆ parseValue()

ilAdvancedMDSubstitution::parseValue ( int  $a_field_id,
array  $a_values_records 
)
private

Definition at line 148 of file class.ilAdvancedMDSubstitution.php.

148 : ?string
149 {
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()) {
154 return ilADTFactory::getInstance()->getPresentationBridgeForInstance($element)->getList();
155 }
156 }
157 }
158 return null;
159 }

References ilADTFactory\getInstance().

Referenced by getParsedSubstitutions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read()

ilAdvancedMDSubstitution::read ( )
private

Read db entries @access private.

Definition at line 240 of file class.ilAdvancedMDSubstitution.php.

240 : void
241 {
242 global $DIC;
243
244 $ilDB = $DIC['ilDB'];
245
246 // Check active status
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') . " ";
252 $res = $this->db->query($query);
253 $this->active = $res->numRows() ? true : false;
254 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
255 $this->active_fields[(int) $row->field_id] = (string) $row->title;
256 }
257
258 $query = "SELECT * FROM adv_md_substitutions " .
259 "WHERE obj_type = " . $this->db->quote($this->type, 'text') . " ";
260 $res = $this->db->query($query);
261 $this->substitutions = array();
262 $this->bold = array();
263 $this->newline = array();
264 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
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'];
270 }
271 if ($substitution['bold']) {
272 $this->bold[] = $substitution['field_id'];
273 }
274 if ($substitution['newline']) {
275 $this->newline[] = $substitution['field_id'];
276 }
277 }
278 }
279 $this->enabled_desc = !$row->hide_description;
280 $this->enabled_field_names = !$row->hide_field_names;
281 }
282 }
return true
$res
Definition: ltiservices.php:69
$query

References $DIC, $ilDB, $query, $res, ilDBConstants\FETCHMODE_OBJECT, ILIAS\Repository\int(), and true.

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resetSubstitutions()

ilAdvancedMDSubstitution::resetSubstitutions ( )

Definition at line 161 of file class.ilAdvancedMDSubstitution.php.

161 : void
162 {
163 $this->substitutions = array();
164 $this->bold = array();
165 $this->newline = array();
166 }

◆ sortDefinitions()

ilAdvancedMDSubstitution::sortDefinitions ( array  $a_definitions)

Sort definitions.

Definition at line 73 of file class.ilAdvancedMDSubstitution.php.

73 : array
74 {
75 $sorted = array();
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]);
80 }
81 }
82 return array_merge($sorted, $a_definitions);
83 }

◆ update()

ilAdvancedMDSubstitution::update ( )

update @access public

Definition at line 208 of file class.ilAdvancedMDSubstitution.php.

208 : void
209 {
210 global $DIC;
211
212 $ilDB = $DIC['ilDB'];
213
214 $counter = 0;
215 $substitutions = array();
216
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);
221 $counter++;
222 }
223
224 $query = "DELETE FROM adv_md_substitutions WHERE obj_type = " . $ilDB->quote($this->type, 'text');
225 $res = $ilDB->manipulate($query);
226
227 $values = array(
228 'obj_type' => array('text', $this->type),
229 'substitution' => array('clob', serialize($substitutions)),
230 'hide_description' => array('integer', !$this->isDescriptionEnabled()),
231 'hide_field_names' => array('integer', !$this->enabledFieldNames())
232 );
233 $ilDB->insert('adv_md_substitutions', $values);
234 }

References $DIC, $ilDB, $query, $res, $substitutions, enabledFieldNames(), hasNewline(), isBold(), and isDescriptionEnabled().

+ Here is the call graph for this function:

Field Documentation

◆ $active

bool ilAdvancedMDSubstitution::$active = false
protected

Definition at line 44 of file class.ilAdvancedMDSubstitution.php.

Referenced by isActive().

◆ $active_fields

array ilAdvancedMDSubstitution::$active_fields = array()
protected

Definition at line 47 of file class.ilAdvancedMDSubstitution.php.

◆ $bold

array ilAdvancedMDSubstitution::$bold = array()
protected

Definition at line 39 of file class.ilAdvancedMDSubstitution.php.

◆ $date_fields

array ilAdvancedMDSubstitution::$date_fields = array()
protected

Definition at line 45 of file class.ilAdvancedMDSubstitution.php.

◆ $datetime_fields

array ilAdvancedMDSubstitution::$datetime_fields = array()
protected

Definition at line 46 of file class.ilAdvancedMDSubstitution.php.

◆ $db

ilDBInterface ilAdvancedMDSubstitution::$db
protected

Definition at line 35 of file class.ilAdvancedMDSubstitution.php.

◆ $enabled_desc

bool ilAdvancedMDSubstitution::$enabled_desc = true
protected

Definition at line 42 of file class.ilAdvancedMDSubstitution.php.

Referenced by isDescriptionEnabled().

◆ $enabled_field_names

bool ilAdvancedMDSubstitution::$enabled_field_names = true
protected

Definition at line 43 of file class.ilAdvancedMDSubstitution.php.

Referenced by enabledFieldNames().

◆ $instances

array ilAdvancedMDSubstitution::$instances = null
staticprivate

Definition at line 32 of file class.ilAdvancedMDSubstitution.php.

◆ $mappings

array ilAdvancedMDSubstitution::$mappings = null
staticprivate

Definition at line 33 of file class.ilAdvancedMDSubstitution.php.

◆ $newline

array ilAdvancedMDSubstitution::$newline = array()
protected

Definition at line 40 of file class.ilAdvancedMDSubstitution.php.

◆ $substitutions

array ilAdvancedMDSubstitution::$substitutions
protected

Definition at line 38 of file class.ilAdvancedMDSubstitution.php.

Referenced by getSubstitutions(), and update().

◆ $type

string ilAdvancedMDSubstitution::$type
protected

Definition at line 37 of file class.ilAdvancedMDSubstitution.php.


The documentation for this class was generated from the following file: