/Services/Migration/DBUpdate_5295/classes/class.ilMD5295MetaMetadata.php

https://github.com/ILIAS-eLearning/ILIAS · PHP · 288 lines · 198 code · 52 blank · 38 comment · 14 complexity · bdac3d133fb8881f27cf7c8539f2320a MD5 · raw file

  1. <?php
  2. /*
  3. +-----------------------------------------------------------------------------+
  4. | ILIAS open source |
  5. +-----------------------------------------------------------------------------+
  6. | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
  7. | |
  8. | This program is free software; you can redistribute it and/or |
  9. | modify it under the terms of the GNU General Public License |
  10. | as published by the Free Software Foundation; either version 2 |
  11. | of the License, or (at your option) any later version. |
  12. | |
  13. | This program is distributed in the hope that it will be useful, |
  14. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  15. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  16. | GNU General Public License for more details. |
  17. | |
  18. | You should have received a copy of the GNU General Public License |
  19. | along with this program; if not, write to the Free Software |
  20. | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
  21. +-----------------------------------------------------------------------------+
  22. */
  23. /**
  24. * Meta Data class (element meta_data)
  25. *
  26. * @package ilias-core
  27. * @version $Id$
  28. */
  29. include_once 'class.ilMD5295Base.php';
  30. class ilMD5295MetaMetadata extends ilMD5295Base
  31. {
  32. public function getPossibleSubelements()
  33. {
  34. $subs['Identifier'] = 'meta_identifier';
  35. $subs['Contribute'] = 'meta_contribute';
  36. return $subs;
  37. }
  38. // SUBELEMENTS
  39. public function &getIdentifierIds()
  40. {
  41. include_once 'Services/Migration/DBUpdate_5295/classes/class.ilMD5295Identifier.php';
  42. return ilMD5295Identifier::_getIds($this->getRBACId(), $this->getObjId(), $this->getMetaId(), 'meta_meta_data');
  43. }
  44. public function &getIdentifier($a_identifier_id)
  45. {
  46. include_once 'Services/Migration/DBUpdate_5295/classes/class.ilMD5295Identifier.php';
  47. if (!$a_identifier_id) {
  48. return false;
  49. }
  50. $ide = new ilMD5295Identifier();
  51. $ide->setMetaId($a_identifier_id);
  52. return $ide;
  53. }
  54. public function &addIdentifier()
  55. {
  56. include_once 'Services/Migration/DBUpdate_5295/classes/class.ilMD5295Identifier.php';
  57. $ide = new ilMD5295Identifier($this->getRBACId(), $this->getObjId(), $this->getObjType());
  58. $ide->setParentId($this->getMetaId());
  59. $ide->setParentType('meta_meta_data');
  60. return $ide;
  61. }
  62. public function &getContributeIds()
  63. {
  64. include_once 'Services/Migration/DBUpdate_5295/classes/class.ilMD5295Contribute.php';
  65. return ilMD5295Contribute::_getIds($this->getRBACId(), $this->getObjId(), $this->getMetaId(), 'meta_meta_data');
  66. }
  67. public function &getContribute($a_contribute_id)
  68. {
  69. include_once 'Services/Migration/DBUpdate_5295/classes/class.ilMD5295Contribute.php';
  70. if (!$a_contribute_id) {
  71. return false;
  72. }
  73. $con = new ilMD5295Contribute();
  74. $con->setMetaId($a_contribute_id);
  75. return $con;
  76. }
  77. public function &addContribute()
  78. {
  79. include_once 'Services/Migration/DBUpdate_5295/classes/class.ilMD5295Contribute.php';
  80. $con = new ilMD5295Contribute($this->getRBACId(), $this->getObjId(), $this->getObjType());
  81. $con->setParentId($this->getMetaId());
  82. $con->setParentType('meta_meta_data');
  83. return $con;
  84. }
  85. // SET/GET
  86. public function setMetaDataScheme($a_val)
  87. {
  88. $this->meta_data_scheme = $a_val;
  89. }
  90. public function getMetaDataScheme()
  91. {
  92. // Fixed attribute
  93. return 'LOM v 1.0';
  94. }
  95. public function setLanguage(&$lng_obj)
  96. {
  97. if (is_object($lng_obj)) {
  98. $this->language = $lng_obj;
  99. }
  100. }
  101. public function &getLanguage()
  102. {
  103. return is_object($this->language) ? $this->language : false;
  104. }
  105. public function getLanguageCode()
  106. {
  107. return is_object($this->language) ? $this->language->getLanguageCode() : false;
  108. }
  109. public function save()
  110. {
  111. global $DIC;
  112. $ilDB = $DIC['ilDB'];
  113. $fields = $this->__getFields();
  114. $fields['meta_meta_data_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_meta_data'));
  115. if ($this->db->insert('il_meta_meta_data', $fields)) {
  116. $this->setMetaId($next_id);
  117. return $this->getMetaId();
  118. }
  119. return false;
  120. }
  121. public function update()
  122. {
  123. global $DIC;
  124. $ilDB = $DIC['ilDB'];
  125. if ($this->getMetaId()) {
  126. if ($this->db->update(
  127. 'il_meta_meta_data',
  128. $this->__getFields(),
  129. array("meta_meta_data_id" => array('integer',$this->getMetaId()))
  130. )) {
  131. return true;
  132. }
  133. }
  134. return false;
  135. }
  136. public function delete()
  137. {
  138. global $DIC;
  139. $ilDB = $DIC['ilDB'];
  140. if ($this->getMetaId()) {
  141. $query = "DELETE FROM il_meta_meta_data " .
  142. "WHERE meta_meta_data_id = " . $ilDB->quote($this->getMetaId(), 'integer');
  143. $res = $ilDB->manipulate($query);
  144. foreach ($this->getIdentifierIds() as $id) {
  145. $ide = $this->getIdentifier($id);
  146. $ide->delete();
  147. }
  148. foreach ($this->getContributeIds() as $id) {
  149. $con = $this->getContribute($id);
  150. $con->delete();
  151. }
  152. return true;
  153. }
  154. return false;
  155. }
  156. public function __getFields()
  157. {
  158. return array('rbac_id' => array('integer',$this->getRBACId()),
  159. 'obj_id' => array('integer',$this->getObjId()),
  160. 'obj_type' => array('text',$this->getObjType()),
  161. 'meta_data_scheme' => array('text',$this->getMetaDataScheme()),
  162. 'language' => array('text',$this->getLanguageCode()));
  163. }
  164. public function read()
  165. {
  166. global $DIC;
  167. $ilDB = $DIC['ilDB'];
  168. include_once 'Services/Migration/DBUpdate_5295/classes/class.ilMD5295LanguageItem.php';
  169. if ($this->getMetaId()) {
  170. $query = "SELECT * FROM il_meta_meta_data " .
  171. "WHERE meta_meta_data_id = " . $ilDB->quote($this->getMetaId(), 'integer');
  172. $res = $this->db->query($query);
  173. while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
  174. $this->setRBACId($row->rbac_id);
  175. $this->setObjId($row->obj_id);
  176. $this->setObjType($row->obj_type);
  177. $this->setMetaDataScheme($row->meta_data_scheme);
  178. $this->setLanguage(new ilMD5295LanguageItem($row->language));
  179. }
  180. return true;
  181. }
  182. return false;
  183. }
  184. /*
  185. * XML Export of all meta data
  186. * @param object (xml writer) see class.ilMD52952XML.php
  187. *
  188. */
  189. public function toXML(&$writer)
  190. {
  191. if ($this->getMetaDataScheme()) {
  192. $attr['MetadataScheme'] = $this->getMetaDataScheme();
  193. }
  194. if ($this->getLanguageCode()) {
  195. $attr['Language'] = $this->getLanguageCode();
  196. }
  197. $writer->xmlStartTag('Meta-Metadata', $attr ? $attr : null);
  198. // ELEMENT IDENTIFIER
  199. $identifiers = $this->getIdentifierIds();
  200. foreach ($identifiers as $id) {
  201. $ide = &$this->getIdentifier($id);
  202. $ide->toXML($writer);
  203. }
  204. if (!count($identifiers)) {
  205. include_once 'Services/Metadata/classes/class.ilMD5295Identifier.php';
  206. $ide = new ilMD5295Identifier($this->getRBACId(), $this->getObjId());
  207. $ide->toXML($writer);
  208. }
  209. // ELEMETN Contribute
  210. $contributes = $this->getContributeIds();
  211. foreach ($contributes as $id) {
  212. $con = &$this->getContribute($id);
  213. $con->toXML($writer);
  214. }
  215. if (!count($contributes)) {
  216. include_once 'Services/Migration/DBUpdate_5295/classes/class.ilMD5295Contribute.php';
  217. $con = new ilMD5295Contribute($this->getRBACId(), $this->getObjId());
  218. $con->toXML($writer);
  219. }
  220. $writer->xmlEndTag('Meta-Metadata');
  221. }
  222. // STATIC
  223. public static function _getId($a_rbac_id, $a_obj_id)
  224. {
  225. global $DIC;
  226. $ilDB = $DIC['ilDB'];
  227. $query = "SELECT meta_meta_data_id FROM il_meta_meta_data " .
  228. "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
  229. "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
  230. $res = $ilDB->query($query);
  231. while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
  232. return $row->meta_meta_data_id;
  233. }
  234. return false;
  235. }
  236. }