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

Services/MetaData/classes/class.ilMDTypicalAgeRange.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 
00031 include_once 'class.ilMDBase.php';
00032 
00033 class ilMDTypicalAgeRange extends ilMDBase
00034 {
00035         function ilMDTypicalAgeRange($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         // SET/GET
00043         function setTypicalAgeRange($a_typical_age_range)
00044         {
00045                 $this->typical_age_range = $a_typical_age_range;
00046         }
00047         function getTypicalAgeRange()
00048         {
00049                 return $this->typical_age_range;
00050         }
00051         function setTypicalAgeRangeLanguage(&$lng_obj)
00052         {
00053                 if(is_object($lng_obj))
00054                 {
00055                         $this->typical_age_range_language = $lng_obj;
00056                 }
00057         }
00058         function &getTypicalAgeRangeLanguage()
00059         {
00060                 return is_object($this->typical_age_range_language) ? $this->typical_age_range_language : false;
00061         }
00062         function getTypicalAgeRangeLanguageCode()
00063         {
00064                 return is_object($this->typical_age_range_language) ? $this->typical_age_range_language->getLanguageCode() : false;
00065         }
00066 
00067         function setTypicalAgeRangeMinimum($a_min)
00068         {
00069                 $this->typical_age_range_minimum = $a_min;
00070         }
00071         function getTypicalAgeRangeMinimum()
00072         {
00073                 return $this->typical_age_range_minimum;
00074         }
00075         function setTypicalAgeRangeMaximum($a_max)
00076         {
00077                 $this->typical_age_range_maximum = $a_max;
00078         }
00079         function getTypicalAgeRangeMaximum()
00080         {
00081                 return $this->typical_age_range_maximum;
00082         }
00083 
00084 
00085         function save()
00086         {
00087                 $this->__parseTypicalAgeRange();
00088 
00089                 if($this->db->autoExecute('il_meta_typical_age_range',
00090                                                                   $this->__getFields(),
00091                                                                   DB_AUTOQUERY_INSERT))
00092                 {
00093                         $this->setMetaId($this->db->getLastInsertId());
00094 
00095                         return $this->getMetaId();
00096                 }
00097                 return false;
00098         }
00099 
00100         function update()
00101         {
00102                 $this->__parseTypicalAgeRange();
00103 
00104                 if($this->getMetaId())
00105                 {
00106                         if($this->db->autoExecute('il_meta_typical_age_range',
00107                                                                           $this->__getFields(),
00108                                                                           DB_AUTOQUERY_UPDATE,
00109                                                                           "meta_typical_age_range_id = '".$this->getMetaId()."'"))
00110                         {
00111                                 return true;
00112                         }
00113                 }
00114                 return false;
00115         }
00116 
00117         function delete()
00118         {
00119                 if($this->getMetaId())
00120                 {
00121                         $query = "DELETE FROM il_meta_typical_age_range ".
00122                                 "WHERE meta_typical_age_range_id = '".$this->getMetaId()."'";
00123                         
00124                         $this->db->query($query);
00125                         
00126                         return true;
00127                 }
00128                 return false;
00129         }
00130                         
00131 
00132         function __getFields()
00133         {
00134                 return array('rbac_id'  => $this->getRBACId(),
00135                                          'obj_id'       => $this->getObjId(),
00136                                          'obj_type'     => $this->getObjType(),
00137                                          'parent_type' => $this->getParentType(),
00138                                          'parent_id' => $this->getParentId(),
00139                                          'typical_age_range'    => $this->getTypicalAgeRange(),
00140                                          'typical_age_range_language' => $this->getTypicalAgeRangeLanguageCode(),
00141                                          'typical_age_range_min' => $this->getTypicalAgeRangeMinimum(),
00142                                          'typical_age_range_max' => $this->getTypicalAgeRangeMaximum());
00143         }
00144 
00145         function read()
00146         {
00147                 include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
00148 
00149                 if($this->getMetaId())
00150                 {
00151                         $query = "SELECT * FROM il_meta_typical_age_range ".
00152                                 "WHERE meta_typical_age_range_id = '".$this->getMetaId()."'";
00153 
00154                         $res = $this->db->query($query);
00155                         while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00156                         {
00157                                 $this->setRBACId($row->rbac_id);
00158                                 $this->setObjId($row->obj_id);
00159                                 $this->setObjType($row->obj_type);
00160                                 $this->setParentId($row->parent_id);
00161                                 $this->setParentType($row->parent_type);
00162                                 $this->setTypicalAgeRange($row->typical_age_range);
00163                                 $this->setTypicalAgeRangeLanguage(new ilMDLanguageItem($row->typical_age_range_language));
00164                                 $this->setTypicalAgeRangeMinimum($row->typical_age_range_min);
00165                                 $this->setTypicalAgeRangeMaximum($row->typical_age_range_max);
00166                         }
00167                 }
00168                 return true;
00169         }
00170                                 
00171         /*
00172          * XML Export of all meta data
00173          * @param object (xml writer) see class.ilMD2XML.php
00174          * 
00175          */
00176         function toXML(&$writer)
00177         {
00178                 $writer->xmlElement('TypicalAgeRange',array('Language' => $this->getTypicalAgeRangeLanguageCode()
00179                                                                                                         ? $this->getTypicalAgeRangeLanguageCode()
00180                                                                                                         : 'en'),
00181                                                         $this->getTypicalAgeRange());
00182         }
00183 
00184 
00185         // STATIC
00186         function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type)
00187         {
00188                 global $ilDB;
00189 
00190                 $query = "SELECT meta_typical_age_range_id FROM il_meta_typical_age_range ".
00191                         "WHERE rbac_id = '".$a_rbac_id."' ".
00192                         "AND obj_id = '".$a_obj_id."' ".
00193                         "AND parent_id = '".$a_parent_id."' ".
00194                         "AND parent_type = '".$a_parent_type."'";
00195 
00196                 $res = $ilDB->query($query);
00197                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00198                 {
00199                         $ids[] = $row->meta_typical_age_range_id;
00200                 }
00201                 return $ids ? $ids : array();
00202         }
00203 
00204         // PRIVATE
00205         function __parseTypicalAgeRange()
00206         {
00207                 if(preg_match("/\s*(\d*)\s*(-?)\s*(\d*)/",$this->getTypicalAgeRange(),$matches))
00208                 {
00209                         if(!$matches[2] and !$matches[3])
00210                         {
00211                                 $min = $max = $matches[1];
00212                         }
00213                         elseif($matches[2] and !$matches[3])
00214                         {
00215                                 $min = $matches[1];
00216                                 $max = 99;
00217                         }
00218                         else
00219                         {
00220                                 $min = $matches[1];
00221                                 $max = $matches[3];
00222                         }
00223                         $this->setTypicalAgeRangeMaximum($max);
00224                         $this->setTypicalAgeRangeMinimum($min);
00225 
00226                         return true;
00227                 }
00228 
00229                 if(!$this->getTypicalAgeRange())
00230                 {
00231                         $this->setTypicalAgeRangeMinimum(-1);
00232                         $this->setTypicalAgeRangeMaximum(-1);
00233                 }
00234                 return true;
00235         }
00236                         
00237 }
00238 ?>

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