Version 1
[yaffs-website] / vendor / php-instagram-api / php-instagram-api / Instagram / User.php
1 <?php
2
3 /**
4 * Instagram PHP
5 * @author Galen Grover <galenjr@gmail.com>
6 * @license http://opensource.org/licenses/mit-license.php The MIT License
7 */
8
9 namespace Instagram;
10
11 use \Instagram\Collection\MediaCollection;
12 use \Instagram\Collection\UserCollection;
13
14 /**
15  * User class
16  *
17  * @see \Instagram\Instagram->getUser()
18  * {@link https://github.com/galen/PHP-Instagram-API/blob/master/Examples/user.php}
19  * {@link http://galengrover.com/projects/instagram/?example=user.php}
20  */
21 class User extends \Instagram\Core\BaseObjectAbstract {
22
23     /**
24      * Get the user's username
25      *
26      * @return string
27      * @access public
28      */
29     public function getUserName() {
30         return $this->data->username;
31     }
32
33     /**
34      * Get the user's full name
35      *
36      * @return string|null
37      * @access public
38      */
39     public function getFullName() {
40         return isset( $this->data->full_name ) ? $this->data->full_name : null;
41     }
42
43     /**
44      * Get the user's profile picture
45      *
46      * @return string
47      * @access public
48      */
49     public function getProfilePicture() {
50         return $this->data->profile_picture;
51     }
52
53     /**
54      * Get the user's biography
55      *
56      * @return string
57      * @access public
58      */
59     public function getBio() {
60         return $this->data->bio;
61     }
62
63     /**
64      * Get the user's website
65      *
66      * @return string
67      * @access public
68      */
69     public function getWebsite() {
70         return $this->data->website;
71     }
72
73     /**
74      * Get the user's counts
75      *
76      * @return StdClass|null
77      * @access public
78      */
79     public function getCounts() {
80         if ( !$this->isCompleteUser() ) {
81             $this->updateData();
82         }
83         return isset( $this->data->counts ) ? $this->data->counts : null;
84     }
85
86     /**
87      * Get the user's following count
88      *
89      * @return int
90      * @access public
91      */
92     public function getFollowsCount() {
93         return (int)$this->getCounts()->follows;
94     }
95
96     /**
97      * Get the user's followers count
98      *
99      * @return int
100      * @access public
101      */
102     public function getFollowersCount() {
103         return (int)$this->getCounts()->followed_by;
104     }
105
106     /**
107      * Get the user's media count
108      *
109      * @return int
110      * @access public
111      */
112     public function getMediaCount() {
113         return (int)$this->getCounts()->media;
114     }
115
116     /**
117      * Update user data
118      *
119      * Sometimes user object are incomplete. For instance when getting a media object's comments
120      * the users associated with the comments won't have all their data
121      *
122      * @access public
123      */
124     public function updateData() {
125         $this->setData( $this->proxy->getUser( $this->getApiId() ) );
126     }
127
128     /**
129      * Return if the user is complete
130      *
131      * @see User::updateData()
132      *
133      * @return bool
134      * @access protected
135      */
136     protected function isCompleteUser() {
137         return isset( $this->data->counts );
138     }
139
140     /**
141      * Get the user's media
142      *
143      * This can be paginated with the next_max_id param obtained from MediaCollection->getNext()
144      *
145      * @return\Instagram\Collection\MediaCollection
146      * @access public
147      */
148     public function getMedia( array $params = null ) {
149         return new MediaCollection( $this->proxy->getUserMedia( $this->getApiId(), $params ), $this->proxy );
150     }
151
152     /**
153      * Get the users that the user follows
154      *
155      * This can be paginated with the next_cursor param obtained from UserCollection->getNext()
156      *
157      * @return\Instagram\Collection\UserCollection
158      * @access public
159      */
160     public function getFollows( array $params = null ) {
161         return new UserCollection( $this->proxy->getUserFollows( $this->getApiId(), $params ), $this->proxy );
162     }
163
164     /**
165      * Get the user's that follow this user
166      *
167      * This can be paginated with the next_cursor param obtained from UserCollection->getNext()
168      *
169      * @return\Instagram\Collection\UserCollection
170      * @access public
171      */
172     public function getFollowers( array $params = null ) {
173         return new UserCollection( $this->proxy->getUserFollowers( $this->getApiId(), $params ), $this->proxy );
174     }
175
176     /**
177      * Magic toString method
178      * 
179      * Get the user's username
180      *
181      * @return\Instagram\Collection\Collection
182      * @access public
183      */
184     public function __toString() {
185         return $this->getUserName();
186     }
187
188 }