ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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/Migration/DBUpdate_5295/classes/class.ilMDRequirement.php';
34 
35 class 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 $DIC;
45 
46  $ilDB = $DIC['ilDB'];
47 
48  if (!$this->or_composite_id) {
49  $query = "SELECT MAX(or_composite_id) orc FROM il_meta_requirement " .
50  "WHERE rbac_id = " . $ilDB->quote($this->getRBACId(), 'integer') . " " .
51  "AND obj_id = " . $ilDB->quote($this->getObjId(), 'integer') . " ";
52 
53  $res = $this->db->query($query);
54  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
55  $this->or_composite_id = $row->orc;
56  }
57  ++$this->or_composite_id;
58  }
59  return $this->or_composite_id;
60  }
61 
62  public function &getRequirementIds()
63  {
64  include_once 'Services/Migration/DBUpdate_5295/classes/class.ilMDRequirement.php';
65 
67  $this->getRBACId(),
68  $this->getObjId(),
69  $this->getParentId(),
70  'meta_technical',
71  $this->getOrCompositeId()
72  );
73  }
74 
75  public function &getRequirement($a_requirement_id)
76  {
77  include_once 'Services/Migration/DBUpdate_5295/classes/class.ilMDRequirement.php';
78 
79  if (!$a_requirement_id) {
80  return false;
81  }
82  $req = new ilMDRequirement();
83  $req->setMetaId($a_requirement_id);
84 
85  return $req;
86  }
87 
88  public function &addRequirement()
89  {
90  include_once 'Services/Migration/DBUpdate_5295/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  public function save()
105  {
106  echo 'Use ilMDOrcomposite::addRequirement()';
107  }
108 
109  public function delete()
110  {
111  foreach ($this->getRequirementIds() as $id) {
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  public function toXML(&$writer)
124  {
125  // For all requirements
126  $writer->xmlStartTag('OrComposite');
127 
128  $reqs = $this->getRequirementIds();
129  foreach ($reqs as $id) {
130  $req = $this->getRequirement($id);
131  $req->toXML($writer);
132  }
133  if (!count($reqs)) {
134  include_once 'Services/Migration/DBUpdate_5295/classes/class.ilMDRequirement.php';
135  $req = new ilMDRequirement($this->getRBACId(), $this->getObjId());
136  $req->toXML($writer);
137  }
138  $writer->xmlEndTag('OrComposite');
139  }
140 
141 
142  // STATIC
143  public static function _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type, $a_or_composite_id = 0)
144  {
145  global $DIC;
146 
147  $ilDB = $DIC['ilDB'];
148 
149  $query = "SELECT DISTINCT(or_composite_id) or_composite_id FROM il_meta_requirement " .
150  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
151  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
152  "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
153  "AND parent_type = " . $ilDB->quote($a_parent_type, 'text') . " " .
154  "AND or_composite_id > 0 ";
155 
156  $res = $ilDB->query($query);
157  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
158  $ids[] = $row->or_composite_id;
159  }
160  return $ids ? $ids : array();
161  }
162 }
global $DIC
Definition: saml.php:7
setOrCompositeId($a_or_composite_id)
if(!array_key_exists('StateId', $_REQUEST)) $id
& getRequirement($a_requirement_id)
$req
Definition: getUserInfo.php:20
foreach($_POST as $key=> $value) $res
$query
$row
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)