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 
32 include_once 'class.ilMDBase.php';
33 include_once 'Services/MetaData/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  }
42  function getOrCompositeId()
43  {
44  global $ilDB;
45 
46  if(!$this->or_composite_id)
47  {
48  $query = "SELECT MAX(or_composite_id) orc FROM il_meta_requirement ".
49  "WHERE rbac_id = ".$ilDB->quote($this->getRBACId() ,'integer')." ".
50  "AND obj_id = ".$ilDB->quote($this->getObjId() ,'integer')." ";
51 
52  $res = $this->db->query($query);
53  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
54  {
55  $this->or_composite_id = $row->orc;
56  }
57  ++$this->or_composite_id;
58  }
59  return $this->or_composite_id;
60  }
61 
62  function &getRequirementIds()
63  {
64  include_once 'Services/MetaData/classes/class.ilMDRequirement.php';
65 
66  return ilMDRequirement::_getIds($this->getRBACId(),
67  $this->getObjId(),
68  $this->getParentId(),
69  'meta_technical',
70  $this->getOrCompositeId());
71  }
72 
73  function &getRequirement($a_requirement_id)
74  {
75  include_once 'Services/MetaData/classes/class.ilMDRequirement.php';
76 
77  if(!$a_requirement_id)
78  {
79  return false;
80  }
81  $req = new ilMDRequirement();
82  $req->setMetaId($a_requirement_id);
83 
84  return $req;
85  }
86 
87  function &addRequirement()
88  {
89  include_once 'Services/MetaData/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  function save()
104  {
105  echo 'Use ilMDOrcomposite::addRequirement()';
106  }
107 
108  function delete()
109  {
110  foreach($this->getRequirementIds() as $id)
111  {
112  $req = $this->getRequirement($id);
113  $req->delete();
114  }
115  return true;
116  }
117 
118  /*
119  * XML Export of all meta data
120  * @param object (xml writer) see class.ilMD2XML.php
121  *
122  */
123  function toXML(&$writer)
124  {
125  // For all requirements
126  $writer->xmlStartTag('OrComposite');
127 
128  $reqs = $this->getRequirementIds();
129  foreach($reqs as $id)
130  {
131  $req = $this->getRequirement($id);
132  $req->toXML($writer);
133  }
134  if(!count($reqs))
135  {
136  include_once 'Services/MetaData/classes/class.ilMDRequirement.php';
137  $req = new ilMDRequirement($this->getRBACId(),$this->getObjId());
138  $req->toXML($writer);
139  }
140  $writer->xmlEndTag('OrComposite');
141 
142  }
143 
144 
145  // STATIC
146  static function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type,$a_or_composite_id = 0)
147  {
148  global $ilDB;
149 
150  $query = "SELECT DISTINCT(or_composite_id) or_composite_id FROM il_meta_requirement ".
151  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
152  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
153  "AND parent_id = ".$ilDB->quote($a_parent_id ,'integer')." ".
154  "AND parent_type = ".$ilDB->quote($a_parent_type ,'text')." ".
155  "AND or_composite_id > 0 ";
156 
157  $res = $ilDB->query($query);
158  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
159  {
160  $ids[] = $row->or_composite_id;
161  }
162  return $ids ? $ids : array();
163  }
164 }
165 ?>
setOrCompositeId($a_or_composite_id)
& getRequirement($a_requirement_id)
Create styles array
The data for the language used.
global $ilDB
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type, $a_or_composite_id=0)
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type, $a_or_composite_id=0)