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

Source for file Preferences.php

Documentation is available at Preferences.php

  1. <?PHP
  2. /**
  3.  * Model for an eBay preference
  4.  *
  5.  * @package Services_Ebay
  6.  * @author  Stephan Schmidt <schst@php.net>
  7.  */
  8. {
  9.     /**
  10.      * preferences
  11.      * 
  12.      * @var array 
  13.      */
  14.     protected $preferences = array();
  15.  
  16.     /**
  17.      * set of preferences
  18.      * 
  19.      * @var array 
  20.      */
  21.     protected $preferenceSets = array();
  22.     
  23.    /**
  24.     * create new preferences
  25.     *
  26.     *
  27.     */
  28.     public function __construct($props$session = null)
  29.     {
  30.         if (is_string($props)) {
  31.             $this->properties['Name'$props;    
  32.         elseif (is_array($props)) {
  33.             if (isset($props['Name'])) {
  34.                 $this->properties['Name'$props['Name'];
  35.             }
  36.             if (isset($props['PreferenceRole'])) {
  37.                 $this->properties['PreferenceRole'$props['PreferenceRole'];
  38.             }
  39.             if (isset($props['Preference'])) {
  40.                 if (isset($props['Preference'][0])) {
  41.                     $this->preferences = $props['Preference'];
  42.                 else {
  43.                     $this->preferences = array($props['Preference']);
  44.                 }
  45.             }
  46.             if (isset($props['Preferences'])) {
  47.                 if (isset($props['Preferences'][0])) {
  48.                     $tmp $props['Preferences'];
  49.                 else {
  50.                     $tmp = array($props['Preferences']);
  51.                 }
  52.                 foreach ($tmp as $set{
  53.                     $this->AddPreference(Services_Ebay::loadModel('Preferences'$set$session));
  54.                 }
  55.             }
  56.         }
  57.     }
  58.     
  59.    /**
  60.     * add a new preference or preference set
  61.     *
  62.     * @param    string|object 
  63.     * @param    mixed 
  64.     * @param    string 
  65.     */
  66.     public function AddPreference($Name$Value = null$ValueType = null )
  67.     {
  68.         if ($Name instanceof Services_Ebay_Model_Preferences{
  69.             array_push($this->preferenceSets$Name);
  70.         else {
  71.             array_push($this->preferencesarray(
  72.                                                    'Name'      => $Name,
  73.                                                    'Value'     => $Value,
  74.                                                    'ValueType' => $ValueType
  75.                                                 )
  76.                     );
  77.  
  78.         }
  79.     }
  80.  
  81.    /**
  82.     * creates an array for serialization
  83.     *
  84.     * @return   array 
  85.     */
  86.     public function toArray()
  87.     {
  88.         $array = parent::toArray();
  89.         if (!empty($this->preferences)) {
  90.             $array['Preference']  $this->preferences;
  91.         }
  92.         if (!empty($this->preferenceSets)) {
  93.             $array['Preferences'= array();
  94.             foreach ($this->preferenceSets as $set{
  95.                 array_push($array['Preferences']$set->toArray());
  96.             }
  97.         }
  98.         
  99.         return $array;
  100.     }
  101. }
  102. ?>

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