ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilMDOrComposite.php
Go to the documentation of this 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
32include_once 'class.ilMDBase.php';
33include_once 'Services/MetaData/classes/class.ilMDRequirement.php';
34
36{
37 function ilMDOrComposite($a_rbac_id = 0,$a_obj_id = 0,$a_obj_type = '')
38 {
39 parent::ilMDRequirement($a_rbac_id,
40 $a_obj_id,
41 $a_obj_type);
42 }
43
44 // SET/GET
45 function setOrCompositeId($a_or_composite_id)
46 {
47 $this->or_composite_id = (int) $a_or_composite_id;
48 }
50 {
51 global $ilDB;
52
53 if(!$this->or_composite_id)
54 {
55 $query = "SELECT MAX(or_composite_id) orc FROM il_meta_requirement ".
56 "WHERE rbac_id = ".$ilDB->quote($this->getRBACId() ,'integer')." ".
57 "AND obj_id = ".$ilDB->quote($this->getObjId() ,'integer')." ";
58
59 $res = $this->db->query($query);
60 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
61 {
62 $this->or_composite_id = $row->orc;
63 }
64 ++$this->or_composite_id;
65 }
66 return $this->or_composite_id;
67 }
68
70 {
71 include_once 'Services/MetaData/classes/class.ilMDRequirement.php';
72
73 return ilMDRequirement::_getIds($this->getRBACId(),
74 $this->getObjId(),
75 $this->getParentId(),
76 'meta_technical',
77 $this->getOrCompositeId());
78 }
79
80 function &getRequirement($a_requirement_id)
81 {
82 include_once 'Services/MetaData/classes/class.ilMDRequirement.php';
83
84 if(!$a_requirement_id)
85 {
86 return false;
87 }
88 $req =& new ilMDRequirement();
89 $req->setMetaId($a_requirement_id);
90
91 return $req;
92 }
93
94 function &addRequirement()
95 {
96 include_once 'Services/MetaData/classes/class.ilMDRequirement.php';
97
98 $req =& new ilMDRequirement($this->getRBACId(),$this->getObjId(),$this->getObjType());
99 $req->setParentId($this->getParentId());
100 $req->setParentType('meta_technical');
101 $req->setOrCompositeId($this->getOrCompositeId());
102
103 return $req;
104 }
105
106 /*
107 * Overwritten save method, to get new or_composite_id
108 *
109 */
110 function save()
111 {
112 echo 'Use ilMDOrcomposite::addRequirement()';
113 }
114
115 function delete()
116 {
117 foreach($this->getRequirementIds() as $id)
118 {
119 $req = $this->getRequirement($id);
120 $req->delete();
121 }
122 return true;
123 }
124
125 /*
126 * XML Export of all meta data
127 * @param object (xml writer) see class.ilMD2XML.php
128 *
129 */
130 function toXML(&$writer)
131 {
132 // For all requirements
133 $writer->xmlStartTag('OrComposite');
134
135 $reqs = $this->getRequirementIds();
136 foreach($reqs as $id)
137 {
138 $req = $this->getRequirement($id);
139 $req->toXML($writer);
140 }
141 if(!count($reqs))
142 {
143 include_once 'Services/MetaData/classes/class.ilMDRequirement.php';
144 $req = new ilMDRequirement($this->getRBACId(),$this->getObjId());
145 $req->toXML($writer);
146 }
147 $writer->xmlEndTag('OrComposite');
148
149 }
150
151
152 // STATIC
153 function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type)
154 {
155 global $ilDB;
156
157 $query = "SELECT DISTINCT(or_composite_id) or_composite_id FROM il_meta_requirement ".
158 "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
159 "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
160 "AND parent_id = ".$ilDB->quote($a_parent_id ,'integer')." ".
161 "AND parent_type = ".$ilDB->quote($a_parent_type ,'text')." ".
162 "AND or_composite_id > 0 ";
163
164 $res = $ilDB->query($query);
165 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
166 {
167 $ids[] = $row->or_composite_id;
168 }
169 return $ids ? $ids : array();
170 }
171}
172?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
_getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
& getRequirement($a_requirement_id)
setOrCompositeId($a_or_composite_id)
ilMDOrComposite($a_rbac_id=0, $a_obj_id=0, $a_obj_type='')
ilMDRequirement($a_rbac_id=0, $a_obj_id=0, $a_obj_type='')
_getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type, $a_or_composite_id=0)
global $ilDB