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
00031 include_once 'class.ilMDBase.php';
00032
00033 class ilMDRights extends ilMDBase
00034 {
00035 function ilMDRights($a_rbac_id = 0,$a_obj_id = 0,$a_obj_type = '')
00036 {
00037 parent::ilMDBase($a_rbac_id,
00038 $a_obj_id,
00039 $a_obj_type);
00040 }
00041
00042
00043 function setCosts($a_costs)
00044 {
00045 switch($a_costs)
00046 {
00047 case 'Yes':
00048 case 'No':
00049 $this->costs = $a_costs;
00050 return true;
00051
00052 default:
00053 return false;
00054 }
00055 }
00056 function getCosts()
00057 {
00058 return $this->costs;
00059 }
00060 function setCopyrightAndOtherRestrictions($a_caor)
00061 {
00062 switch($a_caor)
00063 {
00064 case 'Yes':
00065 case 'No':
00066 $this->caor = $a_caor;
00067 return true;
00068
00069 default:
00070 return false;
00071 }
00072 }
00073 function getCopyrightAndOtherRestrictions()
00074 {
00075 return $this->caor;
00076 }
00077 function setDescription($a_description)
00078 {
00079 $this->description = $a_description;
00080 }
00081 function getDescription()
00082 {
00083 return $this->description;
00084 }
00085 function setDescriptionLanguage(&$lng_obj)
00086 {
00087 if(is_object($lng_obj))
00088 {
00089 $this->description_language = $lng_obj;
00090 }
00091 }
00092 function &getDescriptionLanguage()
00093 {
00094 return is_object($this->description_language) ? $this->description_language : false;
00095 }
00096 function getDescriptionLanguageCode()
00097 {
00098 return is_object($this->description_language) ? $this->description_language->getLanguageCode() : false;
00099 }
00100
00101 function save()
00102 {
00103 if($this->db->autoExecute('il_meta_rights',
00104 $this->__getFields(),
00105 DB_AUTOQUERY_INSERT))
00106 {
00107 $this->setMetaId($this->db->getLastInsertId());
00108
00109 return $this->getMetaId();
00110 }
00111 return false;
00112 }
00113
00114 function update()
00115 {
00116 if($this->getMetaId())
00117 {
00118 if($this->db->autoExecute('il_meta_rights',
00119 $this->__getFields(),
00120 DB_AUTOQUERY_UPDATE,
00121 "meta_rights_id = '".$this->getMetaId()."'"))
00122 {
00123 return true;
00124 }
00125 }
00126 return false;
00127 }
00128
00129 function delete()
00130 {
00131 if($this->getMetaId())
00132 {
00133 $query = "DELETE FROM il_meta_rights ".
00134 "WHERE meta_rights_id = '".$this->getMetaId()."'";
00135
00136 $this->db->query($query);
00137
00138 return true;
00139 }
00140 return false;
00141 }
00142
00143
00144 function __getFields()
00145 {
00146 return array('rbac_id' => $this->getRBACId(),
00147 'obj_id' => $this->getObjId(),
00148 'obj_type' => $this->getObjType(),
00149 'costs' => $this->getCosts(),
00150 'copyright_and_other_restrictions' => $this->getCopyrightAndOtherRestrictions(),
00151 'description' => $this->getDescription(),
00152 'description_language' => $this->getDescriptionLanguageCode());
00153 }
00154
00155 function read()
00156 {
00157 include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
00158
00159
00160 if($this->getMetaId())
00161 {
00162
00163 $query = "SELECT * FROM il_meta_rights ".
00164 "WHERE meta_rights_id = '".$this->getMetaId()."'";
00165
00166
00167 $res = $this->db->query($query);
00168 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00169 {
00170 $this->setRBACId($row->rbac_id);
00171 $this->setObjId($row->obj_id);
00172 $this->setObjType($row->obj_type);
00173 $this->setDescription($row->description);
00174 $this->setDescriptionLanguage(new ilMDLanguageItem($row->description_language));
00175 $this->setCosts($row->costs);
00176 $this->setCopyrightAndOtherRestrictions($row->copyright_and_other_restrictions);
00177 }
00178 return true;
00179 }
00180 return false;
00181 }
00182
00183
00184
00185
00186
00187
00188 function toXML(&$writer)
00189 {
00190 $writer->xmlStartTag('Rights',array('Cost' => $this->getCosts()
00191 ? $this->getCosts()
00192 : 'No',
00193 'CopyrightAndOtherRestrictions' => $this->getCopyrightAndOtherRestrictions()
00194 ? $this->getCopyrightAndOtherRestrictions()
00195 : 'No'));
00196 $writer->xmlElement('Description',array('Language' => $this->getDescriptionLanguageCode()
00197 ? $this->getDescriptionLanguageCode()
00198 : 'en'),
00199 $this->getDescription());
00200 $writer->xmlEndTag('Rights');
00201 }
00202
00203
00204 function _getId($a_rbac_id,$a_obj_id)
00205 {
00206 global $ilDB;
00207
00208 $query = "SELECT meta_rights_id FROM il_meta_rights ".
00209 "WHERE rbac_id = '".$a_rbac_id."' ".
00210 "AND obj_id = '".$a_obj_id."'";
00211
00212 $res = $ilDB->query($query);
00213 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00214 {
00215 return $row->meta_rights_id;
00216 }
00217 return false;
00218 }
00219 }
00220 ?>