ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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

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

+ 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) @access public

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

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 }

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

+ Here is the caller graph for this function:

◆ appendSubstitution()

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

append field to substitutions

@access public

Parameters
intfield id

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

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

◆ enableDescription()

ilAdvancedMDSubstitution::enableDescription (   $a_status)

Enable description presentation.

@access public

Parameters
boolstatus description enabled

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

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

◆ enabledFieldNames()

ilAdvancedMDSubstitution::enabledFieldNames ( )

is field name enabled

@access public

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

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

◆ getParsedSubstitutions()

ilAdvancedMDSubstitution::getParsedSubstitutions (   $a_ref_id,
  $a_obj_id 
)

Substitute.

@access public

Parameters
intref_id
intobj_id
stringdescription

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

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

317 {
318 return $this->substitutions ? $this->substitutions : array();
319 }

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

355 {
356 return in_array($a_field_id,$this->newline);
357 }

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

468 {
469 return true;
470
471 include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
472
473 if(isset(self::$mappings) and is_object(self::$mappings))
474 {
475 return true;
476 }
477 self::$mappings = ilECSDataMappingSettings::_getInstance();
478 return true;
479 }
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 113 of file class.ilAdvancedMDSubstitution.php.

References $active.

◆ isBold()

ilAdvancedMDSubstitution::isBold (   $a_field_id)

is bold

@access public

Parameters
intfield_id

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

341 {
342 #var_dump("<pre>",$this->bold,$a_field_id,"</pre>");
343
344 return in_array($a_field_id,$this->bold);
345 }

Referenced by getParsedSubstitutions(), and update().

+ Here is the caller graph for this function:

◆ isDescriptionEnabled()

ilAdvancedMDSubstitution::isDescriptionEnabled ( )

Is description enabled.

@access public

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

329 {
330 return in_array($a_field_id,$this->getSubstitutions());
331 }

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

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

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

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

References $ilDB, $query, $res, $row, and DB_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 282 of file class.ilAdvancedMDSubstitution.php.

283 {
284 $this->substitutions = array();
285 $this->bold = array();
286 $this->newline = array();
287 }

◆ sortDefinitions()

ilAdvancedMDSubstitution::sortDefinitions (   $a_definitions)

Sort definitions.

@access 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 if(isset($a_definitions[$field_id]))
99 {
100 $sorted[$field_id] = $a_definitions[$field_id];
101 unset($a_definitions[$field_id]);
102 }
103 }
104 return array_merge($sorted,$a_definitions);
105 }

◆ update()

ilAdvancedMDSubstitution::update ( )

update

@access public

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

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

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