Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00032 include_once 'class.ilMDBase.php';
00033 include_once 'Services/MetaData/classes/class.ilMDRequirement.php';
00034
00035 class ilMDOrComposite extends ilMDRequirement
00036 {
00037 function ilMDOrComposite($a_rbac_id = 0,$a_obj_id = 0,$a_obj_type = '')
00038 {
00039 parent::ilMDRequirement($a_rbac_id,
00040 $a_obj_id,
00041 $a_obj_type);
00042 }
00043
00044
00045 function setOrCompositeId($a_or_composite_id)
00046 {
00047 $this->or_composite_id = (int) $a_or_composite_id;
00048 }
00049 function getOrCompositeId()
00050 {
00051 if(!$this->or_composite_id)
00052 {
00053 $query = "SELECT MAX(or_composite_id) AS orc FROM il_meta_requirement ".
00054 "WHERE rbac_id = '".$this->getRBACId()."' ".
00055 "AND obj_id = '".$this->getObjId()."' ".
00056 "GROUP BY or_composite_id";
00057
00058 $res = $this->db->query($query);
00059 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00060 {
00061 $this->or_composite_id = $row->orc;
00062 }
00063 ++$this->or_composite_id;
00064 }
00065 return $this->or_composite_id;
00066 }
00067
00068 function &getRequirementIds()
00069 {
00070 include_once 'Services/MetaData/classes/class.ilMDRequirement.php';
00071
00072 return ilMDRequirement::_getIds($this->getRBACId(),
00073 $this->getObjId(),
00074 $this->getParentId(),
00075 'meta_technical',
00076 $this->getOrCompositeId());
00077 }
00078
00079 function &getRequirement($a_requirement_id)
00080 {
00081 include_once 'Services/MetaData/classes/class.ilMDRequirement.php';
00082
00083 if(!$a_requirement_id)
00084 {
00085 return false;
00086 }
00087 $req =& new ilMDRequirement();
00088 $req->setMetaId($a_requirement_id);
00089
00090 return $req;
00091 }
00092
00093 function &addRequirement()
00094 {
00095 include_once 'Services/MetaData/classes/class.ilMDRequirement.php';
00096
00097 $req =& new ilMDRequirement($this->getRBACId(),$this->getObjId(),$this->getObjType());
00098 $req->setParentId($this->getParentId());
00099 $req->setParentType('meta_technical');
00100 $req->setOrCompositeId($this->getOrCompositeId());
00101
00102 return $req;
00103 }
00104
00105
00106
00107
00108
00109 function save()
00110 {
00111 echo 'Use ilMDOrcomposite::addRequirement()';
00112 }
00113
00114 function delete()
00115 {
00116 foreach($this->getRequirementIds() as $id)
00117 {
00118 $req = $this->getRequirement($id);
00119 $req->delete();
00120 }
00121 return true;
00122 }
00123
00124
00125
00126
00127
00128
00129 function toXML(&$writer)
00130 {
00131
00132 $writer->xmlStartTag('OrComposite');
00133
00134 $reqs = $this->getRequirementIds();
00135 foreach($reqs as $id)
00136 {
00137 $req = $this->getRequirement($id);
00138 $req->toXML($writer);
00139 }
00140 if(!count($reqs))
00141 {
00142 include_once 'Services/MetaData/classes/class.ilMDRequirement.php';
00143 $req = new ilMDRequirement($this->getRBACId(),$this->getObjId());
00144 $req->toXML($writer);
00145 }
00146 $writer->xmlEndTag('OrComposite');
00147
00148 }
00149
00150
00151
00152 function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type)
00153 {
00154 global $ilDB;
00155
00156 $query = "SELECT DISTINCT(or_composite_id) AS or_composite_id FROM il_meta_requirement ".
00157 "WHERE rbac_id = '".$a_rbac_id."' ".
00158 "AND obj_id = '".$a_obj_id."' ".
00159 "AND parent_id = '".$a_parent_id."' ".
00160 "AND parent_type = '".$a_parent_type."' ".
00161 "AND or_composite_id > 0 ";
00162
00163 $res = $ilDB->query($query);
00164 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00165 {
00166 $ids[] = $row->or_composite_id;
00167 }
00168 return $ids ? $ids : array();
00169 }
00170 }
00171 ?>