Services_Ebay
[ class tree: Services_Ebay ] [ index: Services_Ebay ] [ all elements ]

Source for file Model.php

Documentation is available at Model.php

  1. <?PHP
  2. /**
  3.  * Base class for all models
  4.  *
  5.  * $Id: Model.php,v 1.1 2004/10/28 17:14:53 schst Exp $
  6.  *
  7.  * The base class provides __set() and __get()
  8.  * as well as some other helper methods.
  9.  *
  10.  * @package Services_Ebay
  11.  * @author  Stephan Schmidt <schst@php.net>
  12.  */
  13. {
  14.    /**
  15.     * properties of the model
  16.     *
  17.     * @var  array 
  18.     */
  19.     protected $properties = array();
  20.  
  21.    /**
  22.     * properties that are stored in eBay's database
  23.     *
  24.     * These are stored to check, which fields have been modified
  25.     * in the item
  26.     *
  27.     * @var  array 
  28.     */
  29.     protected $eBayProperties = array();
  30.  
  31.    /**
  32.     * optional session, used to send API calls
  33.     *
  34.     * @var  object Services_Ebay_Session 
  35.     */
  36.     protected $session;
  37.     
  38.    /**
  39.     * property that stores the unique identifier (=pk) of the model
  40.     *
  41.     * @var string 
  42.     */
  43.     protected $primaryKey = null;
  44.     
  45.     /**
  46.     * create new model
  47.     *
  48.     * @param    array   properties
  49.     */
  50.     public function __construct($props$session = null)
  51.     {
  52.         if (is_array($props)) {
  53.             $this->properties = $props;
  54.         elseif ($this->primaryKey !== null{
  55.             $this->properties[$this->primaryKey$props;
  56.         }
  57.         if$session instanceof Services_Ebay_Session{
  58.             $this->session = $session;
  59.         }
  60.         $this->eBayProperties = $this->properties;
  61.     }
  62.     
  63.    /**
  64.     * set the session
  65.     *
  66.     * @param    object Services_Ebay_Session 
  67.     */
  68.     public function setSession(Services_Ebay_Session $session)
  69.     {
  70.         $this->session = $session;
  71.     }
  72.     
  73.    /**
  74.     * get a property
  75.     *
  76.     * @param    string   property name
  77.     * @return   mixed    property value
  78.     */
  79.     public function __get($prop)
  80.     {
  81.         if (isset($this->properties[$prop])) {
  82.             return $this->properties[$prop];
  83.         }
  84.     }
  85.     
  86.    /**
  87.     * set a property
  88.     *
  89.     * @param    string   property name
  90.     * @param    mixed    property value
  91.     */
  92.     public function __set($prop$value)
  93.     {
  94.         $this->properties[$prop$value;
  95.     }
  96.     
  97.    /**
  98.     * return all properties of the user
  99.     *
  100.     * @return   array 
  101.     */
  102.     public function toArray()
  103.     {
  104.         return $this->properties;
  105.     }
  106.  
  107.    /**
  108.     * get the properties that have been modified,
  109.     * since the item has been fetched the last
  110.     * time.
  111.     *
  112.     * This does not involve an API-call
  113.     *
  114.     * @return   array 
  115.     */
  116.     public function GetModifiedProperties()
  117.     {
  118.         $modified = array();
  119.         foreach ($this->properties as $key => $value{
  120.             if (!isset($this->eBayProperties[$key])) {
  121.                 $modified[$key$value;
  122.                 continue;
  123.             }
  124.             if ($this->eBayProperties[$key=== $value{
  125.                 continue;
  126.             }
  127.             $modified[$key$value;
  128.         }
  129.         return $modified;
  130.     }
  131. }
  132. ?>

Documentation generated on Mon, 11 Mar 2019 13:58:07 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.