• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/MetaData/classes/class.ilMDLifecycle.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00032 include_once 'class.ilMDBase.php';
00033 
00034 class ilMDLifecycle extends ilMDBase
00035 {
00036         function ilMDLifecycle($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         function getPossibleSubelements()
00044         {
00045                 $subs['Contribute'] = 'meta_contribute';
00046 
00047                 return $subs;
00048         }               
00049 
00050         // Get subelemsts 'Contribute'
00051         function &getContributeIds()
00052         {
00053                 include_once 'Services/MetaData/classes/class.ilMDContribute.php';
00054 
00055                 return ilMDContribute::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_lifecycle');
00056         }
00057         function &getContribute($a_contribute_id)
00058         {
00059                 include_once 'Services/MetaData/classes/class.ilMDContribute.php';
00060                 
00061                 if(!$a_contribute_id)
00062                 {
00063                         return false;
00064                 }
00065                 $con =& new ilMDContribute();
00066                 $con->setMetaId($a_contribute_id);
00067 
00068                 return $con;
00069         }
00070         function &addContribute()
00071         {
00072                 include_once 'Services/MetaData/classes/class.ilMDContribute.php';
00073 
00074                 $con =& new ilMDContribute($this->getRBACId(),$this->getObjId(),$this->getObjType());
00075                 $con->setParentId($this->getMetaId());
00076                 $con->setParentType('meta_lifecycle');
00077 
00078                 return $con;
00079         }
00080 
00081 
00082         // SET/GET
00083         function setStatus($a_status)
00084         {
00085                 switch($a_status)
00086                 {
00087                         case 'Draft':
00088                         case 'Final':
00089                         case 'Revised':
00090                         case 'Unavailable':
00091                                 $this->status = $a_status;
00092 
00093                         default:
00094                                 return false;
00095                 }
00096         }
00097         function getStatus()
00098         {
00099                 return $this->status;
00100         }
00101         function setVersion($a_version)
00102         {
00103                 $this->version = $a_version;
00104         }
00105         function getVersion()
00106         {
00107                 return $this->version;
00108         }
00109         function setVersionLanguage($lng_obj)
00110         {
00111                 if(is_object($lng_obj))
00112                 {
00113                         $this->version_language =& $lng_obj;
00114                 }
00115         }
00116         function &getVersionLanguage()
00117         {
00118                 return $this->version_language;
00119         }
00120         function getVersionLanguageCode()
00121         {
00122                 if(is_object($this->version_language))
00123                 {
00124                         return $this->version_language->getLanguageCode();
00125                 }
00126                 return false;
00127         }
00128 
00129         function save()
00130         {
00131                 if($this->db->autoExecute('il_meta_lifecycle',
00132                                                                   $this->__getFields(),
00133                                                                   DB_AUTOQUERY_INSERT))
00134                 {
00135                         $this->setMetaId($this->db->getLastInsertId());
00136 
00137                         return $this->getMetaId();
00138                 }
00139                 return false;
00140         }
00141 
00142         function update()
00143         {
00144                 if($this->getMetaId())
00145                 {
00146                         if($this->db->autoExecute('il_meta_lifecycle',
00147                                                                           $this->__getFields(),
00148                                                                           DB_AUTOQUERY_UPDATE,
00149                                                                           "meta_lifecycle_id = '".$this->getMetaId()."'"))
00150                         {
00151                                 return true;
00152                         }
00153                 }
00154                 return false;
00155         }
00156 
00157         function delete()
00158         {
00159                 // Delete 'contribute'
00160                 foreach($this->getContributeIds() as $id)
00161                 {
00162                         $con = $this->getContribute($id);
00163                         $con->delete();
00164                 }
00165 
00166 
00167                 if($this->getMetaId())
00168                 {
00169                         $query = "DELETE FROM il_meta_lifecycle ".
00170                                 "WHERE meta_lifecycle_id = '".$this->getMetaId()."'";
00171                         
00172                         $this->db->query($query);
00173                         
00174                         return true;
00175                 }
00176                 return false;
00177         }
00178                         
00179 
00180         function __getFields()
00181         {
00182                 return array('rbac_id'  => $this->getRBACId(),
00183                                          'obj_id'       => $this->getObjId(),
00184                                          'obj_type'     => ilUtil::prepareDBString($this->getObjType()),
00185                                          'lifecycle_status'     => $this->getStatus(),
00186                                          'meta_version'         => $this->getVersion(),
00187                                          'version_language' => $this->getVersionLanguageCode());
00188         }
00189 
00190         function read()
00191         {
00192                 include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
00193 
00194                 if($this->getMetaId())
00195                 {
00196                         $query = "SELECT * FROM il_meta_lifecycle ".
00197                                 "WHERE meta_lifecycle_id = '".$this->getMetaId()."'";
00198 
00199                         $res = $this->db->query($query);
00200                         while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00201                         {
00202                                 $this->setRBACId($row->rbac_id);
00203                                 $this->setObjId($row->obj_id);
00204                                 $this->setObjType($row->obj_type);
00205                                 $this->setStatus($row->lifecycle_status);
00206                                 $this->setVersion($row->meta_version);
00207                                 $this->setVersionLanguage(new ilMDLanguageItem($row->version_language));
00208                         }
00209                 }
00210                 return true;
00211         }
00212 
00213         /*
00214          * XML Export of all meta data
00215          * @param object (xml writer) see class.ilMD2XML.php
00216          * 
00217          */
00218         function toXML(&$writer)
00219         {
00220                 $writer->xmlStartTag('Lifecycle',array('Status' => $this->getStatus() 
00221                                                                                            ? $this->getStatus() 
00222                                                                                            : 'Draft'));
00223                 $writer->xmlElement('Version',array('Language' => $this->getVersionLanguageCode() 
00224                                                                                         ? $this->getVersionLanguageCode()
00225                                                                                         : 'en'),
00226                                                         $this->getVersion());
00227 
00228                 // contribute
00229                 $contributes = $this->getContributeIds();
00230                 foreach($contributes as $id)
00231                 {
00232                         $con =& $this->getContribute($id);
00233                         $con->toXML($writer);
00234                 }
00235                 if(!count($contributes))
00236                 {
00237                         include_once 'Services/MetaData/classes/class.ilMDContribute.php';
00238                         $con = new ilMDContribute($this->getRBACId(),$this->getObjId());
00239                         $con->toXML($writer);
00240                 }
00241                 $writer->xmlEndTag('Lifecycle');
00242         }
00243 
00244                                 
00245 
00246         // STATIC
00247         function _getId($a_rbac_id,$a_obj_id)
00248         {
00249                 global $ilDB;
00250 
00251                 $query = "SELECT meta_lifecycle_id FROM il_meta_lifecycle ".
00252                         "WHERE rbac_id = '".$a_rbac_id."' ".
00253                         "AND obj_id = '".$a_obj_id."'";
00254 
00255 
00256                 $res = $ilDB->query($query);
00257                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00258                 {
00259                         return $row->meta_lifecycle_id;
00260                 }
00261                 return false;
00262         }
00263 }
00264 ?>

Generated on Fri Dec 13 2013 13:52:11 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1