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
00034 class ilMDContribute extends ilMDBase
00035 {
00036 function ilMDContribute($a_rbac_id = 0,$a_obj_id = 0,$a_obj_type = '')
00037 {
00038 parent::ilMDBase($a_rbac_id,
00039 $a_obj_id,
00040 $a_obj_type);
00041 }
00042
00043
00044
00045 function &getEntityIds()
00046 {
00047 include_once 'Services/MetaData/classes/class.ilMDEntity.php';
00048
00049 return ilMDEntity::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_contribute');
00050 }
00051 function &getEntity($a_entity_id)
00052 {
00053 include_once 'Services/MetaData/classes/class.ilMDEntity.php';
00054
00055 if(!$a_entity_id)
00056 {
00057 return false;
00058 }
00059 $ent =& new ilMDEntity();
00060 $ent->setMetaId($a_entity_id);
00061
00062 return $ent;
00063 }
00064 function &addEntity()
00065 {
00066 include_once 'Services/MetaData/classes/class.ilMDEntity.php';
00067
00068 $ent = new ilMDEntity($this->getRBACId(),$this->getObjId(),$this->getObjType());
00069 $ent->setParentId($this->getMetaId());
00070 $ent->setParentType('meta_contribute');
00071
00072 return $ent;
00073 }
00074
00075
00076 function setRole($a_role)
00077 {
00078 switch($a_role)
00079 {
00080 case 'Author':
00081 case 'Publisher':
00082 case 'Unknown':
00083 case 'Initiator':
00084 case 'Terminator':
00085 case 'Editor':
00086 case 'GraphicalDesigner':
00087 case 'TechnicalImplementer':
00088 case 'ContentProvider':
00089 case 'TechnicalValidator':
00090 case 'EducationalValidator':
00091 case 'ScriptWriter':
00092 case 'InstructionalDesigner':
00093 case 'SubjectMatterExpert':
00094 case 'Creator':
00095 case 'Validator':
00096 $this->role = $a_role;
00097 return true;
00098
00099 default:
00100 return false;
00101 }
00102 }
00103 function getRole()
00104 {
00105 return $this->role;
00106 }
00107 function setDate($a_date)
00108 {
00109 $this->date = $a_date;
00110 }
00111 function getDate()
00112 {
00113 return $this->date;
00114 }
00115
00116
00117 function save()
00118 {
00119 if($this->db->autoExecute('il_meta_contribute',
00120 $this->__getFields(),
00121 DB_AUTOQUERY_INSERT))
00122 {
00123 $this->setMetaId($this->db->getLastInsertId());
00124
00125 return $this->getMetaId();
00126 }
00127 return false;
00128 }
00129
00130 function update()
00131 {
00132 if($this->getMetaId())
00133 {
00134 if($this->db->autoExecute('il_meta_contribute',
00135 $this->__getFields(),
00136 DB_AUTOQUERY_UPDATE,
00137 "meta_contribute_id = '".$this->getMetaId()."'"))
00138 {
00139 return true;
00140 }
00141 }
00142 return false;
00143 }
00144
00145 function delete()
00146 {
00147 if($this->getMetaId())
00148 {
00149 $query = "DELETE FROM il_meta_contribute ".
00150 "WHERE meta_contribute_id = '".$this->getMetaId()."'";
00151
00152 $this->db->query($query);
00153
00154 foreach($this->getEntityIds() as $id)
00155 {
00156 $ent = $this->getEntity($id);
00157 $ent->delete();
00158 }
00159 return true;
00160 }
00161 return false;
00162 }
00163
00164
00165 function __getFields()
00166 {
00167 return array('rbac_id' => $this->getRBACId(),
00168 'obj_id' => $this->getObjId(),
00169 'obj_type' => $this->getObjType(),
00170 'parent_type' => $this->getParentType(),
00171 'parent_id' => $this->getParentId(),
00172 'role' => $this->getRole(),
00173 'date' => $this->getDate());
00174 }
00175
00176 function read()
00177 {
00178 include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
00179
00180 if($this->getMetaId())
00181 {
00182 $query = "SELECT * FROM il_meta_contribute ".
00183 "WHERE meta_contribute_id = '".$this->getMetaId()."'";
00184
00185 $res = $this->db->query($query);
00186 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00187 {
00188 $this->setRBACId($row->rbac_id);
00189 $this->setObjId($row->obj_id);
00190 $this->setObjType($row->obj_type);
00191 $this->setParentId($row->parent_id);
00192 $this->setParentType($row->parent_type);
00193 $this->setRole($row->role);
00194 $this->setDate($row->date);
00195 }
00196 }
00197 return true;
00198 }
00199
00200
00201
00202
00203
00204
00205 function toXML(&$writer)
00206 {
00207 $writer->xmlStartTag('Contribute',array('Role' => $this->getRole()
00208 ? $this->getRole()
00209 : 'Author'));
00210
00211
00212 $entities = $this->getEntityIds();
00213 foreach($entities as $id)
00214 {
00215 $ent =& $this->getEntity($id);
00216 $ent->toXML($writer);
00217 }
00218 if(!count($entities))
00219 {
00220 include_once 'Services/MetaData/classes/class.ilMDEntity.php';
00221 $ent = new ilMDEntity($this->getRBACId(),$this->getObjId());
00222 $ent->toXML($writer);
00223 }
00224
00225 $writer->xmlElement('Date',null,$this->getDate());
00226 $writer->xmlEndTag('Contribute');
00227 }
00228
00229
00230
00231 function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type)
00232 {
00233 global $ilDB;
00234
00235 $query = "SELECT meta_contribute_id FROM il_meta_contribute ".
00236 "WHERE rbac_id = '".$a_rbac_id."' ".
00237 "AND obj_id = '".$a_obj_id."' ".
00238 "AND parent_id = '".$a_parent_id."' ".
00239 "AND parent_type = '".$a_parent_type."' ";
00240
00241 $res = $ilDB->query($query);
00242 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00243 {
00244 $ids[] = $row->meta_contribute_id;
00245 }
00246 return $ids ? $ids : array();
00247 }
00248 }
00249 ?>