ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilMDRelation Class Reference
+ Inheritance diagram for ilMDRelation:
+ Collaboration diagram for ilMDRelation:

Public Member Functions

 getIdentifier_Ids ()
 
 getIdentifier_ (int $a_identifier__id)
 
 addIdentifier_ ()
 
 getDescriptionIds ()
 
 getDescription (int $a_description_id)
 
 addDescription ()
 
 setKind (string $a_kind)
 
 getKind ()
 
 save ()
 
 update ()
 
 delete ()
 
 __getFields ()
 
 read ()
 
 toXML (ilXmlWriter $writer)
 
- Public Member Functions inherited from ilMDBase
 __construct (int $a_rbac_id=0, int $a_obj_id=0, string $a_type='')
 constructor More...
 
 read ()
 
 setRBACId (int $a_id)
 
 getRBACId ()
 
 setObjId (int $a_id)
 
 getObjId ()
 
 setObjType (string $a_type)
 
 getObjType ()
 
 setMetaId (int $a_meta_id, bool $a_read_data=true)
 
 getMetaId ()
 
 setParentType (string $a_parent_type)
 
 getParentType ()
 
 setParentId (int $a_id)
 
 getParentId ()
 
 setExportMode (bool $a_export_mode=true)
 
 getExportMode ()
 
 validate ()
 
 update ()
 
 save ()
 
 delete ()
 
 toXML (ilXmlWriter $writer)
 

Static Public Member Functions

static _getIds (int $a_rbac_id, int $a_obj_id)
 

Private Attributes

const KIND_TRANSLATION
 Compatibility fix for legacy MD classes for new db tables. More...
 
const string $kind = ''
 

Additional Inherited Members

- Protected Attributes inherited from ilMDBase
ilLogger $log
 
ilDBInterface $db
 

Detailed Description

Definition at line 26 of file class.ilMDRelation.php.

Member Function Documentation

◆ __getFields()

ilMDRelation::__getFields ( )
Returns
array<string, array<string, mixed>>

Compatibility fix for legacy MD classes for new db tables

Definition at line 180 of file class.ilMDRelation.php.

References getKind(), ilMDBase\getObjId(), ilMDBase\getObjType(), and ilMDBase\getRBACId().

Referenced by save(), and update().

180  : array
181  {
185  $kind = (string) array_search(
186  $this->getKind(),
187  self::KIND_TRANSLATION
188  );
189 
190  return array(
191  'rbac_id' => array('integer', $this->getRBACId()),
192  'obj_id' => array('integer', $this->getObjId()),
193  'obj_type' => array('text', $this->getObjType()),
194  'kind' => array('text', $kind)
195  );
196  }
const string $kind
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getIds()

static ilMDRelation::_getIds ( int  $a_rbac_id,
int  $a_obj_id 
)
static
Returns
int[]

Definition at line 260 of file class.ilMDRelation.php.

References $DIC, $ilDB, $res, ilDBConstants\FETCHMODE_OBJECT, and ILIAS\Repository\int().

Referenced by ilMD\getRelationIds().

260  : array
261  {
262  global $DIC;
263 
264  $ilDB = $DIC->database();
265 
266  $query = "SELECT meta_relation_id FROM il_meta_relation " .
267  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
268  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
269 
270  $res = $ilDB->query($query);
271  $ids = [];
272  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
273  $ids[] = (int) $row->meta_relation_id;
274  }
275  return $ids;
276  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addDescription()

ilMDRelation::addDescription ( )

Definition at line 97 of file class.ilMDRelation.php.

References ilMDBase\getMetaId(), ilMDBase\getObjId(), ilMDBase\getObjType(), and ilMDBase\getRBACId().

98  {
99  $des = new ilMDDescription($this->getRBACId(), $this->getObjId(), $this->getObjType());
100  $des->setParentId($this->getMetaId());
101  $des->setParentType('meta_relation');
102 
103  return $des;
104  }
+ Here is the call graph for this function:

◆ addIdentifier_()

ilMDRelation::addIdentifier_ ( )

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

References ilMDBase\getMetaId(), ilMDBase\getObjId(), ilMDBase\getObjType(), and ilMDBase\getRBACId().

70  {
71  $ide = new ilMDIdentifier_($this->getRBACId(), $this->getObjId(), $this->getObjType());
72  $ide->setParentId($this->getMetaId());
73  $ide->setParentType('meta_relation');
74 
75  return $ide;
76  }
+ Here is the call graph for this function:

◆ delete()

ilMDRelation::delete ( )

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

References $id, $res, getDescription(), getDescriptionIds(), getIdentifier_(), getIdentifier_Ids(), and ilMDBase\getMetaId().

156  : bool
157  {
158  if ($this->getMetaId()) {
159  $query = "DELETE FROM il_meta_relation " .
160  "WHERE meta_relation_id = " . $this->db->quote($this->getMetaId(), 'integer');
161  $res = $this->db->manipulate($query);
162 
163  foreach ($this->getIdentifier_Ids() as $id) {
164  $ide = $this->getIdentifier_($id);
165  $ide->delete();
166  }
167  foreach ($this->getDescriptionIds() as $id) {
168  $des = $this->getDescription($id);
169  $des->delete();
170  }
171 
172  return true;
173  }
174  return false;
175  }
$res
Definition: ltiservices.php:69
getDescription(int $a_description_id)
getIdentifier_(int $a_identifier__id)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:

◆ getDescription()

ilMDRelation::getDescription ( int  $a_description_id)

Definition at line 86 of file class.ilMDRelation.php.

Referenced by delete(), and toXML().

87  {
88  if (!$a_description_id) {
89  return null;
90  }
91  $des = new ilMDDescription();
92  $des->setMetaId($a_description_id);
93 
94  return $des;
95  }
+ Here is the caller graph for this function:

◆ getDescriptionIds()

ilMDRelation::getDescriptionIds ( )
Returns
int[]

Definition at line 81 of file class.ilMDRelation.php.

References ilMDDescription\_getIds(), ilMDBase\getMetaId(), ilMDBase\getObjId(), and ilMDBase\getRBACId().

Referenced by delete(), and toXML().

81  : array
82  {
83  return ilMDDescription::_getIds($this->getRBACId(), $this->getObjId(), $this->getMetaId(), 'meta_relation');
84  }
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getIdentifier_()

ilMDRelation::getIdentifier_ ( int  $a_identifier__id)

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

Referenced by delete(), and toXML().

59  {
60  if (!$a_identifier__id) {
61  return null;
62  }
63  $ide = new ilMDIdentifier_();
64  $ide->setMetaId($a_identifier__id);
65 
66  return $ide;
67  }
+ Here is the caller graph for this function:

◆ getIdentifier_Ids()

ilMDRelation::getIdentifier_Ids ( )
Returns
int[]

Definition at line 53 of file class.ilMDRelation.php.

References ilMDIdentifier_\_getIds(), ilMDBase\getMetaId(), ilMDBase\getObjId(), and ilMDBase\getRBACId().

Referenced by delete(), and toXML().

53  : array
54  {
55  return ilMDIdentifier_::_getIds($this->getRBACId(), $this->getObjId(), $this->getMetaId(), 'meta_relation');
56  }
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getKind()

ilMDRelation::getKind ( )

Definition at line 130 of file class.ilMDRelation.php.

References $kind.

Referenced by __getFields(), and toXML().

130  : string
131  {
132  return $this->kind;
133  }
const string $kind
+ Here is the caller graph for this function:

◆ read()

ilMDRelation::read ( )

Compatibility fix for legacy MD classes for new db tables

Definition at line 198 of file class.ilMDRelation.php.

References $res, ilDBConstants\FETCHMODE_OBJECT, ilMDBase\getMetaId(), setKind(), ilMDBase\setObjId(), ilMDBase\setObjType(), and ilMDBase\setRBACId().

198  : bool
199  {
200  if ($this->getMetaId()) {
201  $query = "SELECT * FROM il_meta_relation " .
202  "WHERE meta_relation_id = " . $this->db->quote($this->getMetaId(), 'integer');
203 
204  $res = $this->db->query($query);
205  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
209  if (key_exists($row->kind ?? '', self::KIND_TRANSLATION)) {
210  $row->kind = self::KIND_TRANSLATION[$row->kind ?? ''];
211  }
212 
213  $this->setRBACId((int) $row->rbac_id);
214  $this->setObjId((int) $row->obj_id);
215  $this->setObjType($row->obj_type);
216  $this->setKind($row->kind ?? '');
217  }
218  }
219  return true;
220  }
$res
Definition: ltiservices.php:69
setKind(string $a_kind)
setRBACId(int $a_id)
setObjId(int $a_id)
setObjType(string $a_type)
+ Here is the call graph for this function:

◆ save()

ilMDRelation::save ( )

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

References __getFields(), ilMDBase\getMetaId(), and ilMDBase\setMetaId().

135  : int
136  {
137  $fields = $this->__getFields();
138  $fields['meta_relation_id'] = array('integer', $next_id = $this->db->nextId('il_meta_relation'));
139 
140  if ($this->db->insert('il_meta_relation', $fields)) {
141  $this->setMetaId($next_id);
142  return $this->getMetaId();
143  }
144  return 0;
145  }
setMetaId(int $a_meta_id, bool $a_read_data=true)
+ Here is the call graph for this function:

◆ setKind()

ilMDRelation::setKind ( string  $a_kind)

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

Referenced by read().

107  : bool
108  {
109  switch ($a_kind) {
110  case 'IsPartOf':
111  case 'HasPart':
112  case 'IsVersionOf':
113  case 'HasVersion':
114  case 'IsFormatOf':
115  case 'HasFormat':
116  case 'References':
117  case 'IsReferencedBy':
118  case 'IsBasedOn':
119  case 'IsBasisFor':
120  case 'Requires':
121  case 'IsRequiredBy':
122  $this->kind = $a_kind;
123  return true;
124 
125  default:
126  return false;
127  }
128  }
+ Here is the caller graph for this function:

◆ toXML()

ilMDRelation::toXML ( ilXmlWriter  $writer)

Definition at line 222 of file class.ilMDRelation.php.

References $id, getDescription(), getDescriptionIds(), getIdentifier_(), getIdentifier_Ids(), getKind(), ilMDBase\getObjId(), ilMDBase\getRBACId(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

222  : void
223  {
224  $writer->xmlStartTag('Relation', array(
225  'Kind' => $this->getKind() ?: 'IsPartOf'
226  ));
227  $writer->xmlStartTag('Resource');
228 
229  // Identifier_
230  $ides = $this->getIdentifier_Ids();
231  foreach ($ides as $id) {
232  $ide = $this->getIdentifier_($id);
233  $ide->toXML($writer);
234  }
235  if (!count($ides)) {
236  $ide = new ilMDIdentifier_($this->getRBACId(), $this->getObjId());
237  $ide->toXML($writer);
238  }
239 
240  // Description
241  $dess = $this->getDescriptionIds();
242  foreach ($dess as $id) {
243  $des = $this->getDescription($id);
244  $des->toXML($writer);
245  }
246  if (!count($dess)) {
247  $des = new ilMDDescription($this->getRBACId(), $this->getObjId());
248  $des->toXML($writer);
249  }
250 
251  $writer->xmlEndTag('Resource');
252  $writer->xmlEndTag('Relation');
253  }
getDescription(int $a_description_id)
xmlEndTag(string $tag)
Writes an endtag.
getIdentifier_(int $a_identifier__id)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
+ Here is the call graph for this function:

◆ update()

ilMDRelation::update ( )

Definition at line 147 of file class.ilMDRelation.php.

References __getFields(), and ilMDBase\getMetaId().

147  : bool
148  {
149  return $this->getMetaId() && $this->db->update(
150  'il_meta_relation',
151  $this->__getFields(),
152  array("meta_relation_id" => array('integer', $this->getMetaId()))
153  );
154  }
+ Here is the call graph for this function:

Field Documentation

◆ $kind

const string ilMDRelation::$kind = ''
private

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

Referenced by getKind().

◆ KIND_TRANSLATION

const ilMDRelation::KIND_TRANSLATION
private
Initial value:
= [
'ispartof' => 'IsPartOf'

Compatibility fix for legacy MD classes for new db tables.

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


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