Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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