forked from alchemy-fr/Phlickr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
AuthedPhotoset.php
147 lines (136 loc) · 4.24 KB
/
AuthedPhotoset.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
137
138
139
140
141
142
143
144
145
146
147
<?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
*/
/**
* This class extends Phlickr_Photoset.
*/
require_once dirname(__FILE__) . '/Photoset.php';
/**
* Phlickr_AuthedPhotoset represents a Flickr photoset.
*
* Sample usage:
* <code>
* <?php
* include_once '/Api.php';
* include_once '/AuthedPhotosetList.php';
*
* $api = new Phlickr_Api(FLICKR_API_KEY, FLICKR_API_SECRET, FLICKR_TOKEN);
*
* // get a list of your photosets
* $apsl = Phlickr_AuthedPhotosetList($api);
*
* // build an array of ids of your photos (by uploading perhaps?)
* $photo_ids = array(1, 3, 4, 99);
*
* // use the first image for simplicity.
* $aps = $apsl->create('title', 'description', $photo_ids[0]);
* // add the rest of the photos and change the primary photo.
* $aps->editPhotos($photo_ids[2], $photo_ids);
*
* // change the title and description
* $aps->setMeta('a new title', 'a longer description');
* ?>
* </code>
*
* @package Phlickr
* @author Andrew Morton <[email protected]>
* @see Phlickr_Photoset
* @since 0.2.0
*/
class Phlickr_AuthedPhotoset extends Phlickr_Photoset {
/**
* The name of the XML element in the response that defines the object.
*
* @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.getInfo';
/**
* Constructor.
*
* You can construct a photoset from an Id or XML.
*
* @param object Phlickr_Api $api This object must have valid
* authentication information or an exception will be thrown.
* @param mixed $source integer Id, object SimpleXMLElement
* @throws Phlickr_Exception, Phlickr_ConnectionException,
* Phlickr_XmlParseException
*/
function __construct(Phlickr_Api $api, $source) {
assert($api->isAuthValid());
parent::__construct($api, $source);
}
/**
* Set the photoset's title and description.
*
* @param string $title
* @param string $description
* @return void
* @throws Phlickr_Exception
* @see getTitle(), getDescription()
*/
public function setMeta($title, $description) {
$resp = $this->getApi()->executeMethod(
'flickr.photosets.editMeta',
array('photoset_id' => $this->getId(),
'title' => $title,
'description' => $description
)
);
$this->refresh();
}
/**
* Edit photos in the photoset.
*
* The primary photo must be in the set. All photos must be owned by the
* current authenticated user.
*
* @param integer $primaryId Id of the set's primary photo. This id must
* be in the array of photos.
* @param array $photoIds An array of photo ids in the order desired. The
* array must contain the primary photo.
* @return object Phlickr_PhotosetPhotoList
* @throws Phlickr_Exception
* @see getPrimaryId(), Phlickr_PhotosetPhotoList::getIds()
*/
public function editPhotos($primaryId, $photoIds) {
$req = $this->getApi()->executeMethod('flickr.photosets.editPhotos',
array('photoset_id' => $this->getId(),
'primary_photo_id' => $primaryId,
'photo_ids' => implode(',', $photoIds)
)
);
$this->refresh();
// call refresh to clear out the cached photo list
$ret = $this->getPhotoList();
$ret->refresh();
return $ret;
}
/**
* Add a photo to the photoset.
*
* Photo is added to the end of the photoset. Photo must be owned by the
* current authenticated user.
*
* @param integer $photoId ID of the photo to add.
*/
public function addPhoto($photoId) {
$req = $this->getApi()->executeMethod('flickr.photosets.addPhoto',
array(
'photoset_id' => $this->getId(),
'photo_id' => $photoId
)
);
$this->refresh();
}
}