ILIAS  trunk Revision v5.2.0beta1-34132-g2d4d73d4a0
ilADTActiveRecordByType Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilADTActiveRecordByType:

Public Member Functions

 __construct (ilADTDBBridge $a_properties)
 
 setElementIdColumn (string $a_name, string $a_type)
 
 getElementIdColumn ()
 
 read (bool $a_return_additional_data=false)
 Read record. More...
 
 write (array $a_additional_data=null)
 Create/insert record. More...
 

Static Public Member Functions

static deleteByPrimary (string $a_table, array $a_primary, string $a_type=null)
 
static preloadByPrimary (string $a_table, array $a_primary)
 
static cloneByPrimary (string $a_table, array $a_primary_def, array $a_source_primary, array $a_target_primary, array $a_additional=null)
 Clone values by (partial) primary key. More...
 
static readByPrimary (string $a_table, array $a_primary, ?string $a_type=null)
 Read directly. More...
 
static create (string $table, array $fields, string $type)
 
static writeByPrimary (string $a_table, array $a_primary, string $a_type, $a_value)
 Write directly. More...
 
static find (string $a_table, string $a_type, int $a_field_id, string $a_condition, ?string $a_additional_fields=null)
 Find entries. More...
 

Data Fields

const SINGLE_COLUMN_NAME = "value"
 

Protected Member Functions

 init ()
 
 getTableForElementType (string $a_type)
 Get table name for ADT type. More...
 
 mapElementsToTables ()
 Map all group elements to sub tables. More...
 
 processTableRowForElement (string $a_sub_table, string $a_element_id, array $a_row)
 
 findCurrentDBBridge (int $element_id)
 

Static Protected Member Functions

static getTablesMap ()
 
static buildPartialPrimaryWhere (array $a_primary)
 
static getTableTypeMap ()
 

Protected Attributes

ilADTDBBridge $properties
 
string $element_column = ''
 
string $element_column_type = ''
 
array $tables_map = []
 
array $tables_map_type = []
 
ilDBInterface $db
 

Static Protected Attributes

static array $preloaded = []
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning ADT Active Record by type helper class This class expects a valid primary for all actions!

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 27 of file class.ilADTActiveRecordByType.php.

Constructor & Destructor Documentation

◆ __construct()

ilADTActiveRecordByType::__construct ( ilADTDBBridge  $a_properties)

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

References $DIC, and init().

42  {
43  global $DIC;
44 
45  $this->db = $DIC->database();
46  $this->properties = $a_properties;
47  $this->init();
48  }
$DIC
Definition: xapitoken.php:62
+ Here is the call graph for this function:

Member Function Documentation

◆ buildPartialPrimaryWhere()

static ilADTActiveRecordByType::buildPartialPrimaryWhere ( array  $a_primary)
staticprotected

Definition at line 369 of file class.ilADTActiveRecordByType.php.

References $DIC, and $ilDB.

369  : string
370  {
371  global $DIC;
372 
373  $ilDB = $DIC->database();
374 
375  $where = [];
376  foreach ($a_primary as $field => $def) {
377  if (!is_array($def[1])) {
378  $where[] = $field . "=" . $ilDB->quote($def[1], $def[0]);
379  } else {
380  $where[] = $ilDB->in($field, $def[1], false, $def[0]);
381  }
382  }
383  if (count($where)) {
384  return implode(" AND ", $where);
385  }
386  return '';
387  }
$DIC
Definition: xapitoken.php:62

◆ cloneByPrimary()

static ilADTActiveRecordByType::cloneByPrimary ( string  $a_table,
array  $a_primary_def,
array  $a_source_primary,
array  $a_target_primary,
array  $a_additional = null 
)
static

Clone values by (partial) primary key.

Parameters
string$a_table
array$a_primary_def
array$a_source_primary
array$a_target_primary
array$a_additional
Returns
bool

Definition at line 467 of file class.ilADTActiveRecordByType.php.

References $DIC, $ilDB, ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

Referenced by ilAdvancedMDValues\_cloneValues(), and ilGlossaryTerm\_copyTerm().

473  : bool {
474  global $DIC;
475 
476  $ilDB = $DIC->database();
477 
478  $where = self::buildPartialPrimaryWhere($a_source_primary);
479  if (!$where) {
480  return false;
481  }
482 
483  $has_data = false;
484  $type_map = self::getTableTypeMap();
485  foreach (array_keys(self::getTablesMap()) as $table) {
486  $sub_table = $a_table . "_" . $table;
487 
488  $sql = "SELECT * FROM " . $sub_table .
489  " WHERE " . $where;
490  $set = $ilDB->query($sql);
491  if ($ilDB->numRows($set)) {
492  $has_data = true;
493  while ($row = $ilDB->fetchAssoc($set)) {
494  // primary fields
495  $fields = array();
496  foreach ($a_primary_def as $pfield => $ptype) {
497  // make source to target primary
498  if (array_key_exists($pfield, $a_target_primary)) {
499  $row[$pfield] = $a_target_primary[$pfield][1];
500  }
501  $fields[$pfield] = array($ptype, $row[$pfield]);
502  }
503 
504  // value field(s)
505  switch ($table) {
506  case "location":
507  $fields["loc_lat"] = ["float", $row["loc_lat"]];
508  $fields["loc_long"] = ["float", $row["loc_long"]];
509  $fields["loc_zoom"] = ["integer", $row["loc_zoom"]];
510  break;
511 
512  case 'ltext':
513  $fields['value_index'] = [ilDBConstants::T_TEXT, $row['value_index']];
514  $fields['value'] = [ilDBConstants::T_TEXT, $row['value']];
515  break;
516 
517  case 'enum':
518  $fields['value_index'] = [ilDBConstants::T_INTEGER, $row['value_index']];
519  break;
520 
521  case 'extlink':
522  $fields['value'] = [ilDBConstants::T_TEXT, $row['value']];
523  $fields['title'] = [ilDBConstants::T_TEXT, $row['title']];
524  break;
525 
526  default:
527  $fields[self::SINGLE_COLUMN_NAME] = [
528  $type_map[$table],
529  $row[self::SINGLE_COLUMN_NAME]
530  ];
531  break;
532  }
533 
534  // additional data
535  if ($a_additional) {
536  foreach ($a_additional as $afield => $atype) {
537  $fields[$afield] = array($atype, $row[$afield]);
538  }
539  }
540  $ilDB->insert($sub_table, $fields);
541  }
542  }
543  }
544  return $has_data;
545  }
$DIC
Definition: xapitoken.php:62
+ Here is the caller graph for this function:

◆ create()

static ilADTActiveRecordByType::create ( string  $table,
array  $fields,
string  $type 
)
static

Definition at line 597 of file class.ilADTActiveRecordByType.php.

References $DIC, ilDBInterface\manipulate(), and ilDBInterface\quote().

Referenced by ilAdvancedMDFieldDefinitionSelect\update().

597  : void
598  {
599  global $DIC;
600 
601  $db = $DIC->database();
602 
603  $type_table_name = '';
604  foreach (self::getTablesMap() as $type_table_part => $types) {
605  if (in_array($type, $types)) {
606  $type_table_name = $type_table_part;
607  break;
608  }
609  }
610  if (!strlen($type_table_name)) {
611  return;
612  }
613  $table_name = $table . '_' . $type_table_name;
614 
615  $insert = 'insert into ' . $table_name . ' ( ';
616  $cols = [];
617  foreach ($fields as $col => $field_definition) {
618  $cols[] = $col;
619  }
620  $insert .= implode(',', $cols);
621  $insert .= ') VALUES ( ';
622  $values = [];
623  foreach ($fields as $col => $field_definition) {
624  $values[] = $db->quote($field_definition[1], $field_definition[0]);
625  }
626  $insert .= implode(',', $values);
627  $insert .= ' )';
628 
629  $db->manipulate($insert);
630  }
quote($value, string $type)
$DIC
Definition: xapitoken.php:62
manipulate(string $query)
Run a (write) Query on the database.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteByPrimary()

static ilADTActiveRecordByType::deleteByPrimary ( string  $a_table,
array  $a_primary,
string  $a_type = null 
)
static

Definition at line 389 of file class.ilADTActiveRecordByType.php.

References $DIC, and $ilDB.

Referenced by ilAdvancedMDValues\_cloneValues(), ilAdvancedMDValues\_deleteByFieldId(), ilAdvancedMDValues\_deleteByObjId(), and ilAdvancedMDFieldDefinitionSelect\update().

389  : void
390  {
391  global $DIC;
392 
393  $ilDB = $DIC->database();
394 
395  $where = self::buildPartialPrimaryWhere($a_primary);
396  if (!$where) {
397  return;
398  }
399 
400  // all tables
401  if (!$a_type) {
402  foreach (array_keys(self::getTablesMap()) as $table) {
403  $sql = "DELETE FROM " . $a_table . "_" . $table .
404  " WHERE " . $where;
405  $ilDB->manipulate($sql);
406  }
407  } else {
408  $found = null;
409  foreach (self::getTablesMap() as $table => $types) {
410  if (in_array($a_type, $types)) {
411  $found = $table;
412  break;
413  }
414  }
415  if ($found) {
416  $sql = "DELETE FROM " . $a_table . "_" . $found .
417  " WHERE " . $where;
418  $ilDB->manipulate($sql);
419  }
420  }
421  }
$DIC
Definition: xapitoken.php:62
+ Here is the caller graph for this function:

◆ find()

static ilADTActiveRecordByType::find ( string  $a_table,
string  $a_type,
int  $a_field_id,
string  $a_condition,
?string  $a_additional_fields = null 
)
static

Find entries.

Definition at line 673 of file class.ilADTActiveRecordByType.php.

References $DIC, $ilDB, $res, and ilDBConstants\FETCHMODE_ASSOC.

Referenced by ilAdvancedMDFieldDefinitionSelect\findBySingleValue(), ilAdvancedMDFieldDefinitionInternalLink\searchObjects(), ilAdvancedMDFieldDefinitionText\searchObjects(), ilAdvancedMDFieldDefinition\searchObjects(), and ilAdvancedMDFieldDefinition\searchSubObjects().

679  : ?array {
680  global $DIC;
681 
682  $ilDB = $DIC->database();
683  // type-specific table
684  $found = null;
685  foreach (self::getTablesMap() as $table => $types) {
686  if (in_array($a_type, $types)) {
687  $found = $table;
688  break;
689  }
690  }
691  if ($found) {
692  $objects = [];
693  $sql = "SELECT *" . $a_additional_fields .
694  " FROM " . $a_table . "_" . $found .
695  " WHERE field_id = " . $ilDB->quote($a_field_id, "integer") .
696  " AND " . $a_condition;
697  $res = $ilDB->query($sql);
698  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
699  $objects[] = $row;
700  }
701  return $objects;
702  }
703  return null;
704  }
$res
Definition: ltiservices.php:67
$DIC
Definition: xapitoken.php:62
+ Here is the caller graph for this function:

◆ findCurrentDBBridge()

ilADTActiveRecordByType::findCurrentDBBridge ( int  $element_id)
protected

Definition at line 359 of file class.ilADTActiveRecordByType.php.

Referenced by write().

359  : ?ilADTDBBridge
360  {
361  foreach ($this->properties->getElements() as $prop_element_id => $prop_element) {
362  if ($element_id === $prop_element_id) {
363  return $prop_element;
364  }
365  }
366  return null;
367  }
ADT DB bridge base class.
+ Here is the caller graph for this function:

◆ getElementIdColumn()

ilADTActiveRecordByType::getElementIdColumn ( )

Definition at line 69 of file class.ilADTActiveRecordByType.php.

References $element_column.

Referenced by read(), and write().

69  : string
70  {
71  return $this->element_column;
72  }
+ Here is the caller graph for this function:

◆ getTableForElementType()

ilADTActiveRecordByType::getTableForElementType ( string  $a_type)
protected

Get table name for ADT type.

Parameters
string$a_type
Returns
string

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

Referenced by mapElementsToTables(), and write().

95  : string
96  {
97  if (isset($this->tables_map_type[$a_type])) {
98  return $this->properties->getTable() . "_" . $this->tables_map_type[$a_type];
99  }
100  return '';
101  }
+ Here is the caller graph for this function:

◆ getTablesMap()

static ilADTActiveRecordByType::getTablesMap ( )
staticprotected

Definition at line 74 of file class.ilADTActiveRecordByType.php.

74  : array
75  {
76  return [
77  'text' => ['Text'],
78  'enum' => ['Enum', 'MultiEnum'],
79  "int" => ["Integer"],
80  "float" => ["Float"],
81  "date" => ["Date"],
82  "datetime" => ["DateTime"],
83  "location" => ["Location"],
84  'extlink' => ['ExternalLink'],
85  'intlink' => ['InternalLink'],
86  'ltext' => ['LocalizedText']
87  ];
88  }

◆ getTableTypeMap()

static ilADTActiveRecordByType::getTableTypeMap ( )
staticprotected

Definition at line 446 of file class.ilADTActiveRecordByType.php.

446  : array
447  {
448  return array(
449  "text" => "text",
450  "int" => "integer",
451  "float" => "float",
452  "date" => "date",
453  "datetime" => "timestamp",
454  "intlink" => "integer"
455  );
456  }

◆ init()

ilADTActiveRecordByType::init ( )
protected

Definition at line 50 of file class.ilADTActiveRecordByType.php.

Referenced by __construct().

50  : void
51  {
52  $this->tables_map = self::getTablesMap();
53 
54  // type to table lookup
55  $this->tables_map_type = [];
56  foreach ($this->tables_map as $table => $types) {
57  foreach ($types as $type) {
58  $this->tables_map_type[$type] = $table;
59  }
60  }
61  }
+ Here is the caller graph for this function:

◆ mapElementsToTables()

ilADTActiveRecordByType::mapElementsToTables ( )
protected

Map all group elements to sub tables.

Returns
array

Definition at line 107 of file class.ilADTActiveRecordByType.php.

References $res, and getTableForElementType().

Referenced by read(), and write().

107  : array
108  {
109  $res = [];
110  foreach ($this->properties->getElements() as $element_id => $element) {
111  $table = $this->getTableForElementType($element->getADT()->getType());
112  if ($table) {
113  $res[$table][] = $element_id;
114  }
115  }
116  return $res;
117  }
$res
Definition: ltiservices.php:67
getTableForElementType(string $a_type)
Get table name for ADT type.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ preloadByPrimary()

static ilADTActiveRecordByType::preloadByPrimary ( string  $a_table,
array  $a_primary 
)
static

Definition at line 423 of file class.ilADTActiveRecordByType.php.

References $DIC, and $ilDB.

Referenced by ilAdvancedMDValues\preloadByObjIds(), and ilAdvancedMDValues\queryForRecords().

423  : bool
424  {
425  global $DIC;
426 
427  $ilDB = $DIC->database();
428 
429  $where = self::buildPartialPrimaryWhere($a_primary);
430  if (!$where) {
431  return false;
432  }
433 
434  self::$preloaded = [];
435  foreach (array_keys(self::getTablesMap()) as $table) {
436  $sql = "SELECT * FROM " . $a_table . "_" . $table .
437  " WHERE " . $where;
438  $set = $ilDB->query($sql);
439  while ($row = $ilDB->fetchAssoc($set)) {
440  self::$preloaded[$table][] = $row;
441  }
442  }
443  return true;
444  }
$DIC
Definition: xapitoken.php:62
+ Here is the caller graph for this function:

◆ processTableRowForElement()

ilADTActiveRecordByType::processTableRowForElement ( string  $a_sub_table,
string  $a_element_id,
array  $a_row 
)
protected

Definition at line 119 of file class.ilADTActiveRecordByType.php.

Referenced by read().

119  : array
120  {
121  switch ($a_sub_table) {
122  case "location":
123  return [
124  $a_element_id . "_lat" => $a_row["loc_lat"],
125  $a_element_id . "_long" => $a_row["loc_long"],
126  $a_element_id . "_zoom" => $a_row["loc_zoom"]
127  ];
128 
129  case 'extlink':
130  return [
131  $a_element_id . '_value' => $a_row['value'],
132  $a_element_id . '_title' => $a_row['title']
133  ];
134 
135  case 'ltext':
136  return [
137  $a_element_id . '_language' => $a_row['value_index'],
138  $a_element_id . '_translation' => $a_row['value']
139  ];
140 
141  case 'enum':
142  return [
143  $a_element_id => $a_row['value_index']
144  ];
145 
146  default:
147  if ($a_row[self::SINGLE_COLUMN_NAME] !== null) {
148  return [$a_element_id => $a_row[self::SINGLE_COLUMN_NAME]];
149  }
150  break;
151  }
152  return [];
153  }
+ Here is the caller graph for this function:

◆ read()

ilADTActiveRecordByType::read ( bool  $a_return_additional_data = false)

Read record.

Parameters
bool$a_return_additional_data
Returns
bool | array

Definition at line 160 of file class.ilADTActiveRecordByType.php.

References $data, ILIAS\LTI\ToolProvider\$key, getElementIdColumn(), mapElementsToTables(), and processTableRowForElement().

Referenced by ilAdvancedMDValues\queryForRecords().

161  {
162  // reset all group elements
163  $this->properties->getADT()->reset();
164 
165  // using preloaded data
166  // TODO: remove this hack.
167  if (is_array(self::$preloaded) && !$a_return_additional_data) {
168  $primary = $this->properties->getPrimary();
169  foreach (self::$preloaded as $table => $data) {
170  $sub_table = '';
171  $sub_tables = explode('_', $table);
172  if ($sub_tables !== false) {
173  $sub_table = array_pop($sub_tables);
174  }
175  foreach ($data as $row) {
176  // match by primary key
177  foreach ($primary as $primary_field => $primary_value) {
178  if ($row[$primary_field] != $primary_value[1]) {
179  continue 2;
180  }
181  }
182 
183  $element_id = (string) $row[$this->getElementIdColumn()];
184  if ($this->properties->getADT()->hasElement($element_id)) {
185  $element_row = $this->processTableRowForElement($sub_table, $element_id, $row);
186  if (is_array($element_row)) {
187  $this->properties->getElement($element_id)->readRecord($element_row);
188  }
189  }
190  }
191  }
192  }
193 
194  $has_data = false;
195  $additional = [];
196 
197  // read minimum tables
198  foreach ($this->mapElementsToTables() as $table => $element_ids) {
199  $sub_table = '';
200  $sub_tables = explode('_', $table);
201  if ($sub_tables !== false) {
202  $sub_table = array_pop($sub_tables);
203  }
204  if (isset(self::$preloaded[$sub_table]) && !$a_return_additional_data) {
205  continue;
206  }
207  $sql = "SELECT * FROM " . $table .
208  " WHERE " . $this->properties->buildPrimaryWhere();
209  $set = $this->db->query($sql);
210  if ($this->db->numRows($set)) {
211  while ($row = $this->db->fetchAssoc($set)) {
212  $element_id = (string) $row[$this->getElementIdColumn()];
213  if (in_array($element_id, $element_ids)) {
214  $has_data = true;
215 
216  $element_row = $this->processTableRowForElement($sub_table, $element_id, $row);
217  if (is_array($element_row)) {
218  $this->properties->getElement($element_id)->readRecord($element_row);
219  }
220 
221  if ($a_return_additional_data) {
222  // removing primary and field id
223  foreach (array_keys($this->properties->getPrimary()) as $key) {
224  unset($row[$key]);
225  }
226  unset($row[$this->getElementIdColumn()]);
227  $additional[$element_id] = $row;
228  }
229  } else {
230  // :TODO: element no longer valid - delete?
231  }
232  }
233  }
234  }
235 
236  if ($a_return_additional_data) {
237  return $additional;
238  }
239  return $has_data;
240  }
mapElementsToTables()
Map all group elements to sub tables.
processTableRowForElement(string $a_sub_table, string $a_element_id, array $a_row)
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readByPrimary()

static ilADTActiveRecordByType::readByPrimary ( string  $a_table,
array  $a_primary,
?string  $a_type = null 
)
static

Read directly.

Parameters
string$a_table
array$a_primary
string  |  null$a_type
Returns
array|void

Definition at line 554 of file class.ilADTActiveRecordByType.php.

References $DIC, $ilDB, and $res.

Referenced by ilAdvancedMDValues\findByObjectId().

554  : ?array
555  {
556  global $DIC;
557 
558  $ilDB = $DIC->database();
559 
560  $where = self::buildPartialPrimaryWhere($a_primary);
561  if (!$where) {
562  return null;
563  }
564 
565  // all tables
566  $res = [];
567  if (!$a_type) {
568  foreach (array_keys(self::getTablesMap()) as $table) {
569  $sql = "SELECT * FROM " . $a_table . "_" . $table .
570  " WHERE " . $where;
571  $set = $ilDB->query($sql);
572  while ($row = $ilDB->fetchAssoc($set)) {
573  $res[] = $row;
574  }
575  }
576  } // type-specific table
577  else {
578  $found = null;
579  foreach (self::getTablesMap() as $table => $types) {
580  if (in_array($a_type, $types)) {
581  $found = $table;
582  break;
583  }
584  }
585  if ($found) {
586  $sql = "SELECT * FROM " . $a_table . "_" . $found .
587  " WHERE " . $where;
588  $set = $ilDB->query($sql);
589  while ($row = $ilDB->fetchAssoc($set)) {
590  $res[] = $row;
591  }
592  }
593  }
594  return $res;
595  }
$res
Definition: ltiservices.php:67
$DIC
Definition: xapitoken.php:62
+ Here is the caller graph for this function:

◆ setElementIdColumn()

ilADTActiveRecordByType::setElementIdColumn ( string  $a_name,
string  $a_type 
)

Definition at line 63 of file class.ilADTActiveRecordByType.php.

Referenced by ilAdvancedMDValues\queryForRecords().

63  : void
64  {
65  $this->element_column = $a_name;
66  $this->element_column_type = $a_type;
67  }
+ Here is the caller graph for this function:

◆ write()

ilADTActiveRecordByType::write ( array  $a_additional_data = null)

Create/insert record.

Parameters
array$a_additional_data

Definition at line 246 of file class.ilADTActiveRecordByType.php.

References $id, ILIAS\LTI\ToolProvider\$key, $q, findCurrentDBBridge(), getElementIdColumn(), getTableForElementType(), mapElementsToTables(), and ilDBConstants\T_INTEGER.

246  : void
247  {
248  // find existing entries
249  $existing = [];
250  foreach (array_keys($this->mapElementsToTables()) as $table) {
251  $sql = "SELECT " . $this->getElementIdColumn() . " FROM " . $table .
252  " WHERE " . $this->properties->buildPrimaryWhere();
253  $set = $this->db->query($sql);
254  while ($row = $this->db->fetchAssoc($set)) {
255  $id = $row[$this->getElementIdColumn()];
256 
257  // leave other records alone
258  if ($this->properties->getADT()->hasElement((string) $id)) {
259  $existing[$table][$id] = $id;
260  }
261  }
262  }
263 
264  // gather ADT values and distribute by sub-table
265  $tmp = [];
266  foreach ($this->properties->getElements() as $element_id => $element) {
267  if (!$element->getADT()->isNull()) {
268  $table = $this->getTableForElementType($element->getADT()->getType());
269  if ($table) {
270  $fields = array();
271  $element->prepareUpdate($fields);
272 
273  // @todo add configuration for types not supporting default 'value' column
274  // DONE
275  if ($element->supportsDefaultValueColumn()) {
276  $tmp[$table][$element_id][self::SINGLE_COLUMN_NAME] = $fields[$element_id];
277  } else {
278  $tmp[$table][$element_id] = [];
279  foreach ($fields as $key => $value) {
280  $key = substr((string) $key, strlen((string) $element_id) + 1);
281  // @todo other implementation required
282  if (substr($table, -8) == "location") {
283  // long is reserved word
284  $key = "loc_" . $key;
285  }
286  if (substr($table, -4) == 'enum') {
287  $key = 'value_index';
288  }
289  $tmp[$table][$element_id][$key] = $value;
290  }
291  }
292 
293  if (isset($a_additional_data[$element_id])) {
294  $tmp[$table][$element_id] = array_merge(
295  $tmp[$table][$element_id],
296  $a_additional_data[$element_id]
297  );
298  }
299  }
300  }
301  }
302 
303  // update/insert in sub tables
304  if (count($tmp)) {
305  foreach ($tmp as $table => $elements) {
306  foreach ($elements as $element_id => $fields) {
307  if (is_array($fields) && count($fields)) {
308  $current_db_bridge = $this->findCurrentDBBridge($element_id);
309  if (isset($existing[$table][$element_id])) {
310  // update
311  $primary = array_merge(
312  $this->properties->getPrimary(),
313  $current_db_bridge->getAdditionalPrimaryFields()
314  );
315  $primary[$this->getElementIdColumn()] = array($this->element_column_type, $element_id);
316  $this->db->update($table, $fields, $primary);
317  } else {
318  // insert
319  $fields[$this->getElementIdColumn()] = array($this->element_column_type, $element_id);
320  $fields = array_merge(
321  $this->properties->getPrimary(),
322  $current_db_bridge->getAdditionalPrimaryFields(),
323  $fields
324  );
325  $this->db->insert($table, $fields);
326  }
327  }
328  $this->properties->afterUpdateElement(
330  'field_id',
331  (int) $element_id
332  );
333 
334  if (isset($existing[$table][$element_id])) {
335  unset($existing[$table][$element_id]);
336  }
337  }
338  }
339  }
340  // remove all existing values that are now null
341  if (count($existing)) {
342  foreach ($existing as $table => $element_ids) {
343  if ($element_ids) {
344  $this->db->manipulate(
345  $q = "DELETE FROM " . $table .
346  " WHERE " . $this->properties->buildPrimaryWhere() .
347  " AND " . $this->db->in(
348  $this->getElementIdColumn(),
349  $element_ids,
350  false,
351  $this->element_column_type
352  )
353  );
354  }
355  }
356  }
357  }
mapElementsToTables()
Map all group elements to sub tables.
getTableForElementType(string $a_type)
Get table name for ADT type.
string $key
Consumer key/client ID value.
Definition: System.php:193
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$q
Definition: shib_logout.php:18
+ Here is the call graph for this function:

◆ writeByPrimary()

static ilADTActiveRecordByType::writeByPrimary ( string  $a_table,
array  $a_primary,
string  $a_type,
  $a_value 
)
static

Write directly.

Parameters
string$a_table
array$a_primary
string$a_type
$a_value

Definition at line 639 of file class.ilADTActiveRecordByType.php.

References $DIC, and $ilDB.

639  : void
640  {
641  global $DIC;
642 
643  $ilDB = $DIC->database();
644  $where = self::buildPartialPrimaryWhere($a_primary);
645  if (!$where) {
646  return;
647  }
648 
649  // type-specific table
650  $found = null;
651  foreach (self::getTablesMap() as $table => $types) {
652  if (in_array($a_type, $types)) {
653  $found = $table;
654  break;
655  }
656  }
657  if ($found) {
658  $type_map = self::getTableTypeMap();
659  $value_col = self::SINGLE_COLUMN_NAME;
660  if ($found == 'enum') {
661  $value_col = 'value_index';
662  }
663  $sql = "UPDATE " . $a_table . "_" . $found .
664  " SET " . $value_col . "=" . $ilDB->quote($a_value, $type_map[$found]) .
665  " WHERE " . $where;
666  $ilDB->manipulate($sql);
667  }
668  }
$DIC
Definition: xapitoken.php:62

Field Documentation

◆ $db

ilDBInterface ilADTActiveRecordByType::$db
protected

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

◆ $element_column

string ilADTActiveRecordByType::$element_column = ''
protected

Definition at line 30 of file class.ilADTActiveRecordByType.php.

Referenced by getElementIdColumn().

◆ $element_column_type

string ilADTActiveRecordByType::$element_column_type = ''
protected

Definition at line 31 of file class.ilADTActiveRecordByType.php.

◆ $preloaded

array ilADTActiveRecordByType::$preloaded = []
staticprotected

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

◆ $properties

ilADTDBBridge ilADTActiveRecordByType::$properties
protected

Definition at line 29 of file class.ilADTActiveRecordByType.php.

◆ $tables_map

array ilADTActiveRecordByType::$tables_map = []
protected

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

◆ $tables_map_type

array ilADTActiveRecordByType::$tables_map_type = []
protected

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

◆ SINGLE_COLUMN_NAME


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