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