Skip to content
Snippets Groups Projects
BaseObject.php 2.98 KiB
Newer Older
  • Learn to ignore specific revisions
  • SNA's avatar
    SNA committed
    /*
    *    Copyright 2008,2009,2010 Maarch
    *
    *  This file is part of Maarch Framework.
    *
    *   Maarch Framework is free software: you can redistribute it and/or modify
    *   it under the terms of the GNU General Public License as published by
    *   the Free Software Foundation, either version 3 of the License, or
    *   (at your option) any later version.
    *
    *   Maarch Framework is distributed in the hope that it will be useful,
    *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    *   GNU General Public License for more details.
    *
    *   You should have received a copy of the GNU General Public License
    *    along with Maarch Framework.  If not, see <http://www.gnu.org/licenses/>.
    */
    
    /**
    
    SNA's avatar
    SNA committed
     * This object aims at giving a 
     * standard structure for objects
     * that come directly from the 
     * table of a database.
     * 
    
    SNA's avatar
    SNA committed
     * @author Claire Figueras <dev@maarch.org>
     * @author Boulio Nicolas
    
    SNA's avatar
    SNA committed
     *
     */
    
    require_once("core/class/class_functions.php");
    
    
    SNA's avatar
    SNA committed
    class BaseObject {
    	protected $data = array(); 
    
    SNA's avatar
    SNA committed
    	 * Initializes an object
    
    SNA's avatar
    SNA committed
    	public function __construct(){
    
    SNA's avatar
    SNA committed
    	 * Sets value of a property of current object
    	 * 
    
    	 * @param string $name Name of property to set
    	 * @param object $value Value of property $name
    
    SNA's avatar
    SNA committed
    	 * @return boolean True if the set is ok, false otherwise
    
    SNA's avatar
    SNA committed
    	public function __set($name, $value)
    	{
    		if(isset($name))
    		{
    			$this->data[$name] = $value;
    			return true;
    		}
    		return false;
    		
    
    SNA's avatar
    SNA committed
    	 * Gets value of a property of current object
    	 * 
    
    	 * @param string $name Name of property to get
    
    SNA's avatar
    SNA committed
    	 * @return string Value of $name  or null
    
    	 * @exception $e Exception Sent if $name does not exist
    	 */
    
    SNA's avatar
    SNA committed
    	public function __get($name) {
    
    			if (isset($this->data[$name])) return $this->data[$name];
    
    		} catch (Exception $e) {
    
    			echo 'Exception catched: '.functions::xssafe($e->getMessage()).', null returned<br/>';
    
    SNA's avatar
    SNA committed
    	/**
    	 * Checks if a given property is set in the current object
    	 * 
    	 * @param string $name Name of property to check
    	 * @return Bool
    	 */
    	public function __isset($name)
    	{
    		if (isset($this->data[$name])) 
    			return (false === empty($this->data[$name]));
    		 else 
    			return false;
    	        
    
    SNA's avatar
    SNA committed
    	/**
    	 * Gets values of all properties of the current object in an array
    	 * 
    	 * @return Array properties ( key=>value)
    	 */
    	public function getArray() 
    	{
    
    SNA's avatar
    SNA committed
    		if(is_null($this->data))
    			return null;
    		else
    			return $this->data;
    
        /**
        * Sets an array in the current object
        */
    
    SNA's avatar
    SNA committed
    	public function setArray($array) 
    	{
    
    SNA's avatar
    SNA committed
    		$this->data = $array;
    	}
    
        
    	/**
        * Get label of a given property 
        *
        * @return String label
        */
    
    SNA's avatar
    SNA committed
    	public function getLabel($name){
    		if(in_array($name, array_keys($data))){
    			return eval("_".strtoupper($name));
    		} else {
    			return "";
    		}
    	}
    
        
        /**
    	* Delete a given property in the current object
    	* 
    	* @param string $name Name of property to delete
    	*/
        public function __unset($name)
    	{
            unset($this->data[$name]);
        }