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