ILIAS  release_4-4 Revision
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)
 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.

References initECSMappings(), and read().

59  {
60  global $ilDB;
61 
62  $this->db = $ilDB;
63  $this->type = $a_type;
64 
65  $this->initECSMappings();
66  $this->read();
67  }
+ Here is the call graph for this function:

Member Function Documentation

◆ _getInstanceByObjectType()

static ilAdvancedMDSubstitution::_getInstanceByObjectType (   $a_type)
static

Singleton: use this method to get an instance.

Parameters
stringilias object type (3 or 4 characters) public

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

Referenced by ilObjCourseListGUI\init(), ilObjCategoryListGUI\init(), ilObjRemoteCategoryListGUI\init(), ilObjRemoteGlossaryListGUI\init(), ilObjRemoteTestListGUI\init(), ilObjRemoteGroupListGUI\init(), ilObjRemoteLearningModuleListGUI\init(), ilObjRemoteCourseListGUI\init(), ilObjRemoteFileListGUI\init(), ilObjRemoteWikiListGUI\init(), ilObjCourseReferenceListGUI\init(), ilObjCategoryReferenceListGUI\init(), ilAdvancedMDSettingsGUI\initFormSubstitutions(), and ilAdvancedMDSettingsGUI\updateSubstitutions().

78  {
79  if(isset(self::$instances[$a_type]))
80  {
81  return self::$instances[$a_type];
82  }
83  return self::$instances[$a_type] = new ilAdvancedMDSubstitution($a_type);
84  }
+ Here is the caller graph for this function:

◆ appendSubstitution()

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

append field to substitutions

public

Parameters
intfield id

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

294  {
295  $this->substitutions[] = $a_field_id;
296  if($a_bold)
297  {
298  $this->bold[] = $a_field_id;
299  }
300  if($a_newline)
301  {
302  $this->newline[] = $a_field_id;
303  }
304  }

◆ enableDescription()

ilAdvancedMDSubstitution::enableDescription (   $a_status)

Enable description presentation.

public

Parameters
boolstatus description enabled

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

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

◆ enabledFieldNames()

ilAdvancedMDSubstitution::enabledFieldNames ( )

is field name enabled

public

Definition at line 145 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

public

Parameters
boolenable/disable status

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

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

◆ getParsedSubstitutions()

ilAdvancedMDSubstitution::getParsedSubstitutions (   $a_ref_id,
  $a_obj_id 
)

Substitute.

public

Parameters
intref_id
intobj_id
stringdescription

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

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

172  {
173  if(!count($this->getSubstitutions()))
174  {
175  return array();
176  }
177 
178  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
179  $values = ilAdvancedMDValues::_getValuesByObjId($a_obj_id);
180 
181  $counter = 0;
182  foreach($this->getSubstitutions() as $field_id)
183  {
184  if(!isset($this->active_fields[$field_id]))
185  {
186  continue;
187  }
188  if(!isset($values[$field_id]) or !$values[$field_id])
189  {
190  if($this->hasNewline($field_id) and $counter)
191  {
192  $substituted[$counter-1]['newline'] = true;
193  }
194  continue;
195  }
196 
197  $value = $this->parseValue($field_id,$values);
198 
199  $substituted[$counter]['name'] = $this->active_fields[$field_id];
200  $substituted[$counter]['value'] = $value;
201  $substituted[$counter]['bold'] = $this->isBold($field_id);
202  if($this->hasNewline($field_id))
203  {
204  $substituted[$counter]['newline'] = true;
205  }
206  else
207  {
208  $substituted[$counter]['newline'] = false;
209  }
210  $substituted[$counter]['show_field'] = $this->enabledFieldNames();
211  $counter++;
212  }
213 
214  return $substituted ? $substituted : array();
215  }
static _getValuesByObjId($a_obj_id)
Get all values of an object.
getSubstitutions()
get substitution string
parseValue($a_field_id, $a_values)
special handling for date(time) values and ECS dates
+ Here is the call graph for this function:

◆ getSubstitutions()

ilAdvancedMDSubstitution::getSubstitutions ( )

get substitution string

public

Parameters

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

Referenced by getParsedSubstitutions(), and isSubstituted().

314  {
315  return $this->substitutions ? $this->substitutions : array();
316  }
+ Here is the caller graph for this function:

◆ hasNewline()

ilAdvancedMDSubstitution::hasNewline (   $a_field_id)

has newline

public

Parameters
intfield_id

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

Referenced by getParsedSubstitutions(), and update().

352  {
353  return in_array($a_field_id,$this->newline);
354  }
+ Here is the caller graph for this function:

◆ initECSMappings()

ilAdvancedMDSubstitution::initECSMappings ( )
private

init ECS mappings

private

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

References ilECSDataMappingSettings\_getInstance().

Referenced by __construct().

469  {
470  return true;
471 
472  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
473 
474  if(isset(self::$mappings) and is_object(self::$mappings))
475  {
476  return true;
477  }
478  self::$mappings = ilECSDataMappingSettings::_getInstance();
479  return true;
480  }
static _getInstance()
Get Singleton instance.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isActive()

ilAdvancedMDSubstitution::isActive ( )

Is substitution active.

public

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

References $active.

◆ isBold()

ilAdvancedMDSubstitution::isBold (   $a_field_id)

is bold

public

Parameters
intfield_id

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

Referenced by getParsedSubstitutions(), and update().

338  {
339  #var_dump("<pre>",$this->bold,$a_field_id,"</pre>");
340 
341  return in_array($a_field_id,$this->bold);
342  }
+ Here is the caller graph for this function:

◆ isDescriptionEnabled()

ilAdvancedMDSubstitution::isDescriptionEnabled ( )

Is description enabled.

public

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

References $enabled_desc.

Referenced by update().

123  {
124  return (bool) $this->enabled_desc;
125  }
+ Here is the caller graph for this function:

◆ isSubstituted()

ilAdvancedMDSubstitution::isSubstituted (   $a_field_id)

is substituted

public

Parameters
intfield_id

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

References getSubstitutions().

326  {
327  return in_array($a_field_id,$this->getSubstitutions());
328  }
getSubstitutions()
get substitution string
+ Here is the call graph for this function:

◆ parseValue()

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

special handling for date(time) values and ECS dates

Parameters
int$a_field_idfield ID
array$a_valuesvalues public
Returns
string parsed value

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

References $ilUser, ilDatePresentation\formatDate(), and IL_CAL_UNIX.

Referenced by getParsedSubstitutions().

228  {
229  global $ilUser;
230 
231  if($this->type == 'crs' or $this->type == 'rcrs')
232  {
233  // Special handling for ECS fields
234  // @FIXME
235  /*
236  if($a_field_id == self::$mappings->getMappingByECSName('begin') and
237  $end = self::$mappings->getMappingByECSName('end'))
238  {
239  // Parse a duration
240  $start = in_array($a_field_id,$this->date_fields) ?
241  new ilDate($a_values[$a_field_id],IL_CAL_UNIX) :
242  new ilDateTime($a_values[$a_field_id],IL_CAL_UNIX);
243  $end = in_array($end,$this->date_fields) ?
244  new ilDate($a_values[$end],IL_CAL_UNIX) :
245  new ilDateTime($a_values[$end],IL_CAL_UNIX);
246 
247  include_once('./Services/Calendar/classes/class.ilCalendarUtil.php');
248  $weekday = ilCalendarUtil::_numericDayToString($start->get(IL_CAL_FKT_DATE,'w',$ilUser->getTimeZone()),false);
249 
250  ilDatePresentation::setUseRelativeDates(false);
251  $value = ilDatePresentation::formatPeriod($start,$end);
252  ilDatePresentation::setUseRelativeDates(true);
253  return $weekday.', '.$value;
254  }
255  */
256  }
257  if(in_array($a_field_id,$this->date_fields))
258  {
259  return $value = ilDatePresentation::formatDate(new ilDate((int) $a_values[$a_field_id],IL_CAL_UNIX));
260  }
261  elseif(in_array($a_field_id,$this->datetime_fields))
262  {
263  return $value = ilDatePresentation::formatDate(new ilDateTime((int) $a_values[$a_field_id],IL_CAL_UNIX));
264  }
265  else
266  {
267  return $value = $a_values[$a_field_id];
268  }
269  }
const IL_CAL_UNIX
Class for single dates.
static formatDate(ilDateTime $date)
Format a date public.
Date and time handling
global $ilUser
Definition: imgupload.php:15
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read()

ilAdvancedMDSubstitution::read ( )
private

Read db entries.

private

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

References $query, $res, $row, ilAdvancedMDFieldDefinition\_lookupDateFields(), and DB_FETCHMODE_OBJECT.

Referenced by __construct().

396  {
397  global $ilDB;
398 
399  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
400  $this->date_fields = ilAdvancedMDFieldDefinition::_lookupDateFields();
401  $this->datetime_fields = ilAdvancedMDFieldDefinition::_lookupDatetimeFields();
402 
403  // Check active status
404  $query = "SELECT active,field_id,amfd.title FROM adv_md_record amr ".
405  "JOIN adv_md_record_objs amro ON amr.record_id = amro.record_id ".
406  "JOIN adv_mdf_definition amfd ON amr.record_id = amfd.record_id ".
407  "WHERE active = 1 ".
408  "AND obj_type = ".$this->db->quote($this->type ,'text')." ";
409  $res = $this->db->query($query);
410  $this->active = $res->numRows() ? true : false;
411  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
412  {
413  $this->active_fields[$row->field_id] = $row->title;
414  }
415 
416  $query = "SELECT * FROM adv_md_substitutions ".
417  "WHERE obj_type = ".$this->db->quote($this->type ,'text')." ";
418  $res = $this->db->query($query);
419  $this->substitutions = array();
420  $this->bold = array();
421  $this->newline = array();
422  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
423  {
424  $tmp_substitutions = unserialize($row->substitution);
425  if(is_array($tmp_substitutions))
426  {
427  foreach($tmp_substitutions as $substitution)
428  {
429  if($substitution['field_id'])
430  {
431  $this->substitutions[] = $substitution['field_id'];
432  }
433  if($substitution['bold'])
434  {
435  $this->bold[] = $substitution['field_id'];
436  }
437  if($substitution['newline'])
438  {
439  $this->newline[] = $substitution['field_id'];
440  }
441 
442  }
443  }
444  $this->enabled_desc = !$row->hide_description;
445  $this->enabled_field_names = !$row->hide_field_names;
446  }
447 
448  if($this->type == 'crs' or $this->type == 'rcrs')
449  {
450  // Handle ECS substitutions
451  /*
452  if($begin = self::$mappings->getMappingByECSName('begin') and
453  $end = self::$mappings->getMappingByECSName('end'))
454  {
455  // Show something like 'Monday, 30.12.2008 9:00 - 12:00'
456  unset($this->active_fields[$end]);
457  }
458  */
459  }
460  }
static _lookupDateFields()
Lookup date fields.
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resetSubstitutions()

ilAdvancedMDSubstitution::resetSubstitutions ( )

set substitutions

public

Parameters
arrayarray of field definitions

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

280  {
281  $this->substitutions = array();
282  $this->bold = array();
283  $this->newline = array();
284  }

◆ sortDefinitions()

ilAdvancedMDSubstitution::sortDefinitions (   $a_definitions)

Sort definitions.

public

Parameters
arrayint field_id

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

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

◆ update()

ilAdvancedMDSubstitution::update ( )

update

public

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

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

362  {
363  global $ilDB;
364 
365  $counter = 0;
366  $substitutions = array();
367 
368  foreach($this->substitutions as $field_id)
369  {
370  $substitutions[$counter]['field_id'] = $field_id;
371  $substitutions[$counter]['bold'] = $this->isBold($field_id);
372  $substitutions[$counter]['newline'] = $this->hasNewline($field_id);
373  $counter++;
374  }
375 
376  $query = "DELETE FROM adv_md_substitutions WHERE obj_type = ".$ilDB->quote($this->type,'text');
377  $res = $ilDB->manipulate($query);
378 
379 
380  $values = array(
381  'obj_type' => array('text',$this->type),
382  'substitution' => array('clob',serialize($substitutions)),
383  'hide_description' => array('integer',!$this->isDescriptionEnabled()),
384  'hide_field_names' => array('integer',!$this->enabledFieldNames())
385  );
386  $ilDB->insert('adv_md_substitutions',$values);
387  }
isDescriptionEnabled()
Is description enabled.
+ 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: