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 25/** 26* Meta Data class (element orComposite) 27* Extends MDRequirement 28* 29* @package ilias-core 30* @version $Id$ 31*/ 32include_once 'class.ilMDBase.php'; 33include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDRequirement.php'; 34 35class ilMDOrComposite extends ilMDRequirement 36{ 37 // SET/GET 38 public function setOrCompositeId($a_or_composite_id) 39 { 40 $this->or_composite_id = (int) $a_or_composite_id; 41 } 42 public function getOrCompositeId() 43 { 44 global $ilDB; 45 46 if (!$this->or_composite_id) { 47 $query = "SELECT MAX(or_composite_id) AS orc FROM il_meta_requirement " . 48 "WHERE rbac_id = " . $ilDB->quote($this->getRBACId()) . " " . 49 "AND obj_id = " . $ilDB->quote($this->getObjId()) . " " . 50 "GROUP BY or_composite_id"; 51 52 $res = $this->db->query($query); 53 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) { 54 $this->or_composite_id = $row->orc; 55 } 56 ++$this->or_composite_id; 57 } 58 return $this->or_composite_id; 59 } 60 61 public function &getRequirementIds() 62 { 63 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDRequirement.php'; 64 65 return ilMDRequirement::_getIds( 66 $this->getRBACId(), 67 $this->getObjId(), 68 $this->getParentId(), 69 'meta_technical', 70 $this->getOrCompositeId() 71 ); 72 } 73 74 public function &getRequirement($a_requirement_id) 75 { 76 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDRequirement.php'; 77 78 if (!$a_requirement_id) { 79 return false; 80 } 81 $req = new ilMDRequirement(); 82 $req->setMetaId($a_requirement_id); 83 84 return $req; 85 } 86 87 public function &addRequirement() 88 { 89 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDRequirement.php'; 90 91 $req = new ilMDRequirement($this->getRBACId(), $this->getObjId(), $this->getObjType()); 92 $req->setParentId($this->getParentId()); 93 $req->setParentType('meta_technical'); 94 $req->setOrCompositeId($this->getOrCompositeId()); 95 96 return $req; 97 } 98 99 /* 100 * Overwritten save method, to get new or_composite_id 101 * 102 */ 103 public function save() 104 { 105 echo 'Use ilMDOrcomposite::addRequirement()'; 106 } 107 108 public function delete() 109 { 110 foreach ($this->getRequirementIds() as $id) { 111 $req = $this->getRequirement($id); 112 $req->delete(); 113 } 114 return true; 115 } 116 117 /* 118 * XML Export of all meta data 119 * @param object (xml writer) see class.ilMD2XML.php 120 * 121 */ 122 public function toXML(&$writer) 123 { 124 // For all requirements 125 $writer->xmlStartTag('OrComposite'); 126 127 foreach ($this->getRequirementIds() as $id) { 128 $req = $this->getRequirement($id); 129 $req->toXML($writer); 130 } 131 $writer->xmlEndTag('OrComposite'); 132 } 133 134 135 // STATIC 136 public function _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type) 137 { 138 global $ilDB; 139 140 $query = "SELECT DISTINCT(or_composite_id) AS or_composite_id FROM il_meta_requirement " . 141 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id) . " " . 142 "AND obj_id = " . $ilDB->quote($a_obj_id) . " " . 143 "AND parent_id = " . $ilDB->quote($a_parent_id) . " " . 144 "AND parent_type = " . $ilDB->quote($a_parent_type) . " " . 145 "AND or_composite_id > 0 "; 146 147 $res = $ilDB->query($query); 148 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) { 149 $ids[] = $row->or_composite_id; 150 } 151 return $ids ? $ids : array(); 152 } 153} 154