forked from alchemy-fr/Phlickr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
UserList.php
116 lines (110 loc) · 3.17 KB
/
UserList.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
<?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_User objects.
*/
require_once dirname(__FILE__) . '/User.php';
/**
* Phlickr_UserList simply holds a list of users.
*
* Flickr is rather inconsistent in the naming of elements in the XML they
* return so you can pass the name of the list element and the member element
* to the constructor.
*
* Sample usage:
* <code>
* <?php
* include_once '/Api.php';
*
* // insert sample code here
*
* ?>
* </code>
*
* @package Phlickr
* @author Andrew Morton <[email protected]>
* @see Phlickr_User
* @since 0.2.1
* @todo Add sample code.
*/
class Phlickr_UserList extends Phlickr_Framework_ListBase {
/**
* The name of the XML element in the response that defines the list object.
*
* @var string
*/
const XML_RESPONSE_LIST_ELEMENT = 'contacts';
/**
* The name of the XML element in the response that defines a member of the
* list.
*
* @var string
*/
const XML_RESPONSE_ELEMENT = 'contact';
/**
* Constructor.
*
* Unlike most other lists the user list lets you specify the name of the
* XML list and member elements. This is because Flickr uses many different
* names depending on the context (users/user, online/user,
* contacts/contact, etc).
*
* @param object Phlickr_Request $request
* @param string $responseElement Name of the XML element in the response
* that defines this list's members.
* @param string $responseListElement Name of the XML element in the
* response that defines this list.
*/
function __construct(Phlickr_Request $request,
$responseElement = self::XML_RESPONSE_ELEMENT,
$responseListElement = self::XML_RESPONSE_LIST_ELEMENT)
{
parent::__construct($request, $responseElement, $responseListElement);
}
/**
* Return an array of the ids in this list.
*
* Override the base class because these id's are strings.
*
* @return array
*/
public function getIds() {
if (!isset($this->_cachedXml->{$this->getResponseElement()})) {
$this->refresh();
}
$ret = array();
foreach ($this->_cachedXml->{$this->getResponseElement()} as $xml) {
$ret[] = (string) $xml['nsid'];
}
return $ret;
}
/**
* Return an array of Phlickr_User objects.
*
* @return array
*/
public function getUsers() {
if (!isset($this->_cachedXml->{$this->getResponseElement()})) {
$this->refresh();
}
$ret = array();
foreach ($this->_cachedXml->{$this->getResponseElement()} as $xml) {
$ret[] = new Phlickr_User($this->getApi(), $xml);;
}
return $ret;
}
}