ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 $DIC;
61
62 $ilDB = $DIC['ilDB'];
63
64 $this->db = $ilDB;
65 $this->type = $a_type;
66
67 $this->initECSMappings();
68 $this->read();
69 }
global $ilDB
$a_type
Definition: workflow.php:92
$DIC
Definition: xapitoken.php:46

References $a_type, $DIC, $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 285 of file class.ilAdvancedMDSubstitution.php.

286 {
287 $this->substitutions[] = $a_field_id;
288 if ($a_bold) {
289 $this->bold[] = $a_field_id;
290 }
291 if ($a_newline) {
292 $this->newline[] = $a_field_id;
293 }
294 }

◆ enableDescription()

ilAdvancedMDSubstitution::enableDescription (   $a_status)

Enable description presentation.

@access public

Parameters
boolstatus description enabled

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

136 {
137 $this->enabled_desc = $a_status;
138 }

◆ enabledFieldNames()

ilAdvancedMDSubstitution::enabledFieldNames ( )

is field name enabled

@access public

Definition at line 146 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 158 of file class.ilAdvancedMDSubstitution.php.

159 {
160 $this->enabled_field_names = $a_status;
161 }

◆ getParsedSubstitutions()

ilAdvancedMDSubstitution::getParsedSubstitutions (   $a_ref_id,
  $a_obj_id 
)

Substitute.

@access public

Parameters
intref_id
intobj_id
stringdescription

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

173 {
174 if (!count($this->getSubstitutions())) {
175 return array();
176 }
177
178 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
179 $values_records = ilAdvancedMDValues::preloadedRead($this->type, $a_obj_id);
180
181 $counter = 0;
182 foreach ($this->getSubstitutions() as $field_id) {
183 if (!isset($this->active_fields[$field_id])) {
184 continue;
185 }
186
187 $value = $this->parseValue($field_id, $values_records);
188
189 if ($value === null) {
190 if ($this->hasNewline($field_id) and $counter) {
191 $substituted[$counter - 1]['newline'] = true;
192 }
193 continue;
194 }
195
196 $substituted[$counter]['name'] = $this->active_fields[$field_id];
197 $substituted[$counter]['value'] = $value;
198 $substituted[$counter]['bold'] = $this->isBold($field_id);
199 if ($this->hasNewline($field_id)) {
200 $substituted[$counter]['newline'] = true;
201 } else {
202 $substituted[$counter]['newline'] = false;
203 }
204 $substituted[$counter]['show_field'] = $this->enabledFieldNames();
205 $counter++;
206 }
207
208 return $substituted ? $substituted : array();
209 }
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)

References 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 303 of file class.ilAdvancedMDSubstitution.php.

304 {
305 return $this->substitutions ? $this->substitutions : array();
306 }

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 341 of file class.ilAdvancedMDSubstitution.php.

342 {
343 return in_array($a_field_id, $this->newline);
344 }

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 448 of file class.ilAdvancedMDSubstitution.php.

449 {
450 return true;
451
452 include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
453
454 if (isset(self::$mappings) and is_object(self::$mappings)) {
455 return true;
456 }
457 self::$mappings = ilECSDataMappingSettings::_getInstance();
458 return true;
459 }
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 112 of file class.ilAdvancedMDSubstitution.php.

References $active.

◆ isBold()

ilAdvancedMDSubstitution::isBold (   $a_field_id)

is bold

@access public

Parameters
intfield_id

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

328 {
329 #var_dump("<pre>",$this->bold,$a_field_id,"</pre>");
330
331 return in_array($a_field_id, $this->bold);
332 }

Referenced by getParsedSubstitutions(), and update().

+ Here is the caller graph for this function:

◆ isDescriptionEnabled()

ilAdvancedMDSubstitution::isDescriptionEnabled ( )

Is description enabled.

@access public

Definition at line 123 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 315 of file class.ilAdvancedMDSubstitution.php.

316 {
317 return in_array($a_field_id, $this->getSubstitutions());
318 }

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 221 of file class.ilAdvancedMDSubstitution.php.

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

References $DIC, $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 386 of file class.ilAdvancedMDSubstitution.php.

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

References $DIC, $ilDB, $query, $res, 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 271 of file class.ilAdvancedMDSubstitution.php.

272 {
273 $this->substitutions = array();
274 $this->bold = array();
275 $this->newline = array();
276 }

◆ sortDefinitions()

ilAdvancedMDSubstitution::sortDefinitions (   $a_definitions)

Sort definitions.

@access public

Parameters
arrayint field_id

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

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

◆ update()

ilAdvancedMDSubstitution::update ( )

update

@access public

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

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

References $DIC, $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: