forked from wbobeirne/Phlickr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GroupList.php
115 lines (109 loc) · 2.99 KB
/
GroupList.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
<?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_Group objects.
*/
require_once dirname(__FILE__) . '/Group.php';
/**
* Phlickr_GroupList
*
* Sample usage:
* <code>
* <?php
* include_once '/Api.php';
* include_once '/User.php';
* include_once '/Group.php';
*
* $api = new Phlickr_Api(FLICKR_API_KEY, FLICKR_API_SECRET, FLICKR_TOKEN);
* $user = Phlickr_User::findByUrl($api, 'http://flickr.com/people/drewish/');
*
* $grouplist = $user->getGroupList();
*
* // print out the user's groups
* foreach ($grouplist->getGroups() as $group) {
* print "Group: {$group->getName()} ({$group->buildUrl()})\n";
* }
* ?>
* </code>
*
* @package Phlickr
* @author Andrew Morton <[email protected]>
* @see Phlickr_Group
* @since 0.1.4
*/
class Phlickr_GroupList 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 = 'groups';
/**
* The name of the XML element in the response that defines a member of the
* list.
*
* @var string
*/
const XML_RESPONSE_ELEMENT = 'group';
/**
* Constructor.
*
* @param object Phlickr_Request $request
*/
function __construct(Phlickr_Request $request) {
parent::__construct($request, self::XML_RESPONSE_ELEMENT,
self::XML_RESPONSE_LIST_ELEMENT);
}
/**
* 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) {
// most of the xml as the id in the "id" attribute but
// flickr.people.getPublicGroups returns it in the "nsid" attribute
if (isset($xml['id'])) {
$ret[] = (string) $xml['id'];
} else {
$ret[] = (string) $xml['nsid'];
}
}
return $ret;
}
/**
* Return an array of Phlickr_Group objects.
*
* @return array
*/
public function getGroups() {
if (!isset($this->_cachedXml->{$this->getResponseElement()})) {
$this->refresh();
}
$ret = array();
foreach ($this->_cachedXml->{$this->getResponseElement()} as $xml) {
$ret[] = new Phlickr_Group($this->getApi(), $xml);
}
return $ret;
}
}