forked from alchemy-fr/Phlickr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
PhotosetList.php
136 lines (128 loc) · 3.67 KB
/
PhotosetList.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/**
* @version $Id$
* @author Andrew Morton <[email protected]>
* @license http://opensource.org/licenses/lgpl-license.php
* GNU Lesser General Public License, Version 2.1
* @package Phlickr
*/
/**
* Phlickr_Api includes the core classes.
*/
require_once dirname(__FILE__) . '/Api.php';
/**
* This class extends Phlickr_ListBase.
*/
require_once dirname(__FILE__) . '/Framework/ListBase.php';
/**
* One or more methods returns Phlickr_Photoset objects.
*/
require_once dirname(__FILE__) . '/Photoset.php';
/**
* Phlickr_PhotosetList is a read-only list of a users's photosets.
*
* This class allows the viewing user's photosets. If you need to add, remove,
* or reorder photosets, use the Phlickr_AuthedPhotosetList class instead.
*
* @todo Add sample code.
* @package Phlickr
* @author Andrew Morton <[email protected]>
* @see Phlickr_AuthedPhotosetList
*/
class Phlickr_PhotosetList extends Phlickr_Framework_ListBase {
/**
* The name of the XML element in the response that defines the object.
*
* @var string
*/
const XML_RESPONSE_LIST_ELEMENT = 'photosets';
/**
* The name of the XML element in the response that defines a member of the list.
*
* @var string
*/
const XML_RESPONSE_ELEMENT = 'photoset';
/**
* The name of the Flickr API method that provides the info on this object.
*
* @var string
*/
const XML_METHOD_NAME = 'flickr.photosets.getList';
/**
* Flickr user id
*
* @var string
*/
private $_userId = null;
/**
* Constructor
*
* The PhotosetList requires a User Id. If $userId is null the class will
* try to use the $api->getUserId().
*
* @param object Phlickr_API $api
* @param string $userId User Id. If this isn't provided, the API's User
* Id will be used instead.
* @throws Phlickr_Exception
*/
function __construct(Phlickr_Api $api, $userId = null) {
if (isset($userId)) {
$this->_userId = $userId;
} else {
$this->_userId = $api->getUserId();
}
if (is_null($this->_userId)) {
throw new Phlickr_Exception('The photoset needs a User Id.');
}
parent::__construct(
$api->createRequest(
self::getRequestMethodName(),
self::getRequestMethodParams($this->_userId)
),
self::XML_RESPONSE_ELEMENT,
self::XML_RESPONSE_LIST_ELEMENT
);
}
/**
* Returns the name of this object's getInfo API method.
*
* @return string
*/
static function getRequestMethodName() {
return self::XML_METHOD_NAME;
}
/**
* Returns an array of parameters to be used when creating a
* Phlickr_Request to call this object's getInfo API method.
*
* @param string $userId The user id of the photoset's owner.
* @return array
*/
static function getRequestMethodParams($userId) {
return array('user_id' => (string) $userId);
}
/**
* Return an array of Phlickr_Photosets.
*
* @return array
*/
public function getPhotosets() {
if (!isset($this->_cachedXml->{$this->getResponseElement()})) {
$this->load();
}
$ret = array();
foreach ($this->_cachedXml->{$this->getResponseElement()} as $xml) {
$set = new Phlickr_Photoset($this->getApi(), $xml);
$ret[] = $set;
}
return $ret;
}
/**
* Return the User Id that owns these photosets.
*
* @return string
*/
function getUserId() {
return $this->_userId;
}
}