ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilAdvancedMDSubstitution Class Reference
+ Collaboration diagram for ilAdvancedMDSubstitution:

Public Member Functions

 sortDefinitions ($a_definitions)
 Sort definitions. More...
 
 isActive ()
 Is substitution active. More...
 
 isDescriptionEnabled ()
 Is description enabled. More...
 
 enableDescription ($a_status)
 Enable description presentation. More...
 
 enabledFieldNames ()
 is field name enabled More...
 
 enableFieldNames ($a_status)
 enable field names More...
 
 getParsedSubstitutions ($a_ref_id, $a_obj_id)
 Substitute. More...
 
 resetSubstitutions ()
 set substitutions More...
 
 appendSubstitution ($a_field_id, $a_bold=false, $a_newline=false)
 append field to substitutions More...
 
 getSubstitutions ()
 get substitution string More...
 
 isSubstituted ($a_field_id)
 is substituted More...
 
 isBold ($a_field_id)
 is bold More...
 
 hasNewline ($a_field_id)
 has newline More...
 
 update ()
 update More...
 

Static Public Member Functions

static _getInstanceByObjectType ($a_type)
 Singleton: use this method to get an instance. More...
 

Protected Attributes

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

Private Member Functions

 __construct ($a_type)
 
 parseValue ($a_field_id, $a_values_records)
 special handling for date(time) values and ECS dates More...
 
 read ()
 Read db entries. More...
 
 initECSMappings ()
 init ECS mappings More...
 

Static Private Attributes

static $instances = null
 
static $mappings = null
 

Detailed Description

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

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

Constructor & Destructor Documentation

◆ __construct()

ilAdvancedMDSubstitution::__construct (   $a_type)
private

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

59 {
60 global $ilDB;
61
62 $this->db = $ilDB;
63 $this->type = $a_type;
64
65 $this->initECSMappings();
66 $this->read();
67 }
global $ilDB
$a_type
Definition: workflow.php:92

References $a_type, $ilDB, initECSMappings(), and read().

+ Here is the call graph for this function:

Member Function Documentation

◆ _getInstanceByObjectType()

◆ appendSubstitution()

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

append field to substitutions

@access public

Parameters
intfield id

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

282 {
283 $this->substitutions[] = $a_field_id;
284 if ($a_bold) {
285 $this->bold[] = $a_field_id;
286 }
287 if ($a_newline) {
288 $this->newline[] = $a_field_id;
289 }
290 }

◆ enableDescription()

ilAdvancedMDSubstitution::enableDescription (   $a_status)

Enable description presentation.

@access public

Parameters
boolstatus description enabled

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

134 {
135 $this->enabled_desc = $a_status;
136 }

◆ enabledFieldNames()

ilAdvancedMDSubstitution::enabledFieldNames ( )

is field name enabled

@access public

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

References $enabled_field_names.

Referenced by getParsedSubstitutions(), and update().

+ Here is the caller graph for this function:

◆ enableFieldNames()

ilAdvancedMDSubstitution::enableFieldNames (   $a_status)

enable field names

@access public

Parameters
boolenable/disable status

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

157 {
158 $this->enabled_field_names = $a_status;
159 }

◆ getParsedSubstitutions()

ilAdvancedMDSubstitution::getParsedSubstitutions (   $a_ref_id,
  $a_obj_id 
)

Substitute.

@access public

Parameters
intref_id
intobj_id
stringdescription

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

171 {
172 if (!count($this->getSubstitutions())) {
173 return array();
174 }
175
176 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
177 $values_records = ilAdvancedMDValues::preloadedRead($this->type, $a_obj_id);
178
179 $counter = 0;
180 foreach ($this->getSubstitutions() as $field_id) {
181 if (!isset($this->active_fields[$field_id])) {
182 continue;
183 }
184
185 $value = $this->parseValue($field_id, $values_records);
186
187 if ($value === null) {
188 if ($this->hasNewline($field_id) and $counter) {
189 $substituted[$counter-1]['newline'] = true;
190 }
191 continue;
192 }
193
194 $substituted[$counter]['name'] = $this->active_fields[$field_id];
195 $substituted[$counter]['value'] = $value;
196 $substituted[$counter]['bold'] = $this->isBold($field_id);
197 if ($this->hasNewline($field_id)) {
198 $substituted[$counter]['newline'] = true;
199 } else {
200 $substituted[$counter]['newline'] = false;
201 }
202 $substituted[$counter]['show_field'] = $this->enabledFieldNames();
203 $counter++;
204 }
205
206 return $substituted ? $substituted : array();
207 }
parseValue($a_field_id, $a_values_records)
special handling for date(time) values and ECS dates
getSubstitutions()
get substitution string
static preloadedRead($a_type, $a_obj_id)
$counter

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

+ Here is the call graph for this function:

◆ getSubstitutions()

ilAdvancedMDSubstitution::getSubstitutions ( )

get substitution string

@access public

Parameters

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

300 {
301 return $this->substitutions ? $this->substitutions : array();
302 }

Referenced by getParsedSubstitutions(), and isSubstituted().

+ Here is the caller graph for this function:

◆ hasNewline()

ilAdvancedMDSubstitution::hasNewline (   $a_field_id)

has newline

@access public

Parameters
intfield_id

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

338 {
339 return in_array($a_field_id, $this->newline);
340 }

Referenced by getParsedSubstitutions(), and update().

+ Here is the caller graph for this function:

◆ initECSMappings()

ilAdvancedMDSubstitution::initECSMappings ( )
private

init ECS mappings

@access private

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

441 {
442 return true;
443
444 include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
445
446 if (isset(self::$mappings) and is_object(self::$mappings)) {
447 return true;
448 }
449 self::$mappings = ilECSDataMappingSettings::_getInstance();
450 return true;
451 }
static _getInstance()
Get Singleton instance.

References ilECSDataMappingSettings\_getInstance().

Referenced by __construct().

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

◆ isActive()

ilAdvancedMDSubstitution::isActive ( )

Is substitution active.

@access public

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

References $active.

◆ isBold()

ilAdvancedMDSubstitution::isBold (   $a_field_id)

is bold

@access public

Parameters
intfield_id

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

324 {
325 #var_dump("<pre>",$this->bold,$a_field_id,"</pre>");
326
327 return in_array($a_field_id, $this->bold);
328 }

Referenced by getParsedSubstitutions(), and update().

+ Here is the caller graph for this function:

◆ isDescriptionEnabled()

ilAdvancedMDSubstitution::isDescriptionEnabled ( )

Is description enabled.

@access public

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

References $enabled_desc.

Referenced by update().

+ Here is the caller graph for this function:

◆ isSubstituted()

ilAdvancedMDSubstitution::isSubstituted (   $a_field_id)

is substituted

@access public

Parameters
intfield_id

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

312 {
313 return in_array($a_field_id, $this->getSubstitutions());
314 }

References getSubstitutions().

+ Here is the call graph for this function:

◆ parseValue()

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

special handling for date(time) values and ECS dates

Parameters
int$a_field_idfield ID
array$a_values_recordsvalues @access public
Returns
string parsed value

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

220 {
221 global $ilUser;
222
223 if ($this->type == 'crs' or $this->type == 'rcrs') {
224 // Special handling for ECS fields
225 // @FIXME
226 /*
227 if($a_field_id == self::$mappings->getMappingByECSName('begin') and
228 $end = self::$mappings->getMappingByECSName('end'))
229 {
230 // Parse a duration
231 $start = in_array($a_field_id,$this->date_fields) ?
232 new ilDate($a_values[$a_field_id],IL_CAL_UNIX) :
233 new ilDateTime($a_values[$a_field_id],IL_CAL_UNIX);
234 $end = in_array($end,$this->date_fields) ?
235 new ilDate($a_values[$end],IL_CAL_UNIX) :
236 new ilDateTime($a_values[$end],IL_CAL_UNIX);
237
238 include_once('./Services/Calendar/classes/class.ilCalendarUtil.php');
239 $weekday = ilCalendarUtil::_numericDayToString($start->get(IL_CAL_FKT_DATE,'w',$ilUser->getTimeZone()),false);
240
241 ilDatePresentation::setUseRelativeDates(false);
242 $value = ilDatePresentation::formatPeriod($start,$end);
243 ilDatePresentation::setUseRelativeDates(true);
244 return $weekday.', '.$value;
245 }
246 */
247 }
248
249 foreach ($a_values_records as $a_values) {
250 if ($a_values->getADTGroup()->hasElement($a_field_id)) {
251 $element = $a_values->getADTGroup()->getElement($a_field_id);
252 if (!$element->isNull()) {
253 return ilADTFactory::getInstance()->getPresentationBridgeForInstance($element)->getList();
254 }
255 }
256 }
257 }
static getInstance()
Get singleton.
$ilUser
Definition: imgupload.php:18

References $ilUser, and 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 380 of file class.ilAdvancedMDSubstitution.php.

381 {
382 global $ilDB;
383
384 // Check active status
385 $query = "SELECT active,field_id,amfd.title FROM adv_md_record amr " .
386 "JOIN adv_md_record_objs amro ON amr.record_id = amro.record_id " .
387 "JOIN adv_mdf_definition amfd ON amr.record_id = amfd.record_id " .
388 "WHERE active = 1 " .
389 "AND obj_type = " . $this->db->quote($this->type, 'text') . " ";
390 $res = $this->db->query($query);
391 $this->active = $res->numRows() ? true : false;
392 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
393 $this->active_fields[$row->field_id] = $row->title;
394 }
395
396 $query = "SELECT * FROM adv_md_substitutions " .
397 "WHERE obj_type = " . $this->db->quote($this->type, 'text') . " ";
398 $res = $this->db->query($query);
399 $this->substitutions = array();
400 $this->bold = array();
401 $this->newline = array();
402 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
403 $tmp_substitutions = unserialize($row->substitution);
404 if (is_array($tmp_substitutions)) {
405 foreach ($tmp_substitutions as $substitution) {
406 if ($substitution['field_id']) {
407 $this->substitutions[] = $substitution['field_id'];
408 }
409 if ($substitution['bold']) {
410 $this->bold[] = $substitution['field_id'];
411 }
412 if ($substitution['newline']) {
413 $this->newline[] = $substitution['field_id'];
414 }
415 }
416 }
417 $this->enabled_desc = !$row->hide_description;
418 $this->enabled_field_names = !$row->hide_field_names;
419 }
420
421 if ($this->type == 'crs' or $this->type == 'rcrs') {
422 // Handle ECS substitutions
423 /*
424 if($begin = self::$mappings->getMappingByECSName('begin') and
425 $end = self::$mappings->getMappingByECSName('end'))
426 {
427 // Show something like 'Monday, 30.12.2008 9:00 - 12:00'
428 unset($this->active_fields[$end]);
429 }
430 */
431 }
432 }
$query
foreach($_POST as $key=> $value) $res

References $ilDB, $query, $res, $row, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ resetSubstitutions()

ilAdvancedMDSubstitution::resetSubstitutions ( )

set substitutions

@access public

Parameters
arrayarray of field definitions

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

268 {
269 $this->substitutions = array();
270 $this->bold = array();
271 $this->newline = array();
272 }

◆ sortDefinitions()

ilAdvancedMDSubstitution::sortDefinitions (   $a_definitions)

Sort definitions.

@access public

Parameters
arrayint field_id

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

93 {
94 $sorted = array();
95 foreach ($this->substitutions as $field_id) {
96 if (isset($a_definitions[$field_id])) {
97 $sorted[$field_id] = $a_definitions[$field_id];
98 unset($a_definitions[$field_id]);
99 }
100 }
101 return array_merge($sorted, $a_definitions);
102 }

◆ update()

ilAdvancedMDSubstitution::update ( )

update

@access public

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

348 {
349 global $ilDB;
350
351 $counter = 0;
352 $substitutions = array();
353
354 foreach ($this->substitutions as $field_id) {
355 $substitutions[$counter]['field_id'] = $field_id;
356 $substitutions[$counter]['bold'] = $this->isBold($field_id);
357 $substitutions[$counter]['newline'] = $this->hasNewline($field_id);
358 $counter++;
359 }
360
361 $query = "DELETE FROM adv_md_substitutions WHERE obj_type = " . $ilDB->quote($this->type, 'text');
362 $res = $ilDB->manipulate($query);
363
364
365 $values = array(
366 'obj_type' => array('text',$this->type),
367 'substitution' => array('clob',serialize($substitutions)),
368 'hide_description' => array('integer',!$this->isDescriptionEnabled()),
369 'hide_field_names' => array('integer',!$this->enabledFieldNames())
370 );
371 $ilDB->insert('adv_md_substitutions', $values);
372 }
isDescriptionEnabled()
Is description enabled.

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

+ Here is the call graph for this function:

Field Documentation

◆ $active

ilAdvancedMDSubstitution::$active = false
protected

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

Referenced by isActive().

◆ $active_fields

ilAdvancedMDSubstitution::$active_fields = array()
protected

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

◆ $bold

ilAdvancedMDSubstitution::$bold = array()
protected

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

◆ $date_fields

ilAdvancedMDSubstitution::$date_fields = array()
protected

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

◆ $datetime_fields

ilAdvancedMDSubstitution::$datetime_fields = array()
protected

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

◆ $db

ilAdvancedMDSubstitution::$db
protected

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

◆ $enabled_desc

ilAdvancedMDSubstitution::$enabled_desc = true
protected

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

Referenced by isDescriptionEnabled().

◆ $enabled_field_names

ilAdvancedMDSubstitution::$enabled_field_names = true
protected

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

Referenced by enabledFieldNames().

◆ $instances

ilAdvancedMDSubstitution::$instances = null
staticprivate

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

◆ $mappings

ilAdvancedMDSubstitution::$mappings = null
staticprivate

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

◆ $newline

ilAdvancedMDSubstitution::$newline = array()
protected

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

◆ $substitutions

ilAdvancedMDSubstitution::$substitutions
protected

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

Referenced by update().

◆ $type

ilAdvancedMDSubstitution::$type
protected

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


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