3 * StatusNet, the distributed open-source microblogging tool
5 * Show up to 100 favs of a notice
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Hannes Mannerheim <h@nnesmannerhe.im>
25 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
26 * @link http://www.gnu.org/software/social/
29 if (!defined('GNUSOCIAL')) { exit(1); }
32 * Show up to 100 favs of a notice
35 class ApiStatusesFavsAction extends ApiAuthAction
39 var $original = null; // Notice object for which to retrieve favs
40 var $cnt = self::MAXCOUNT;
43 * Take arguments for running
45 * @param array $args $_REQUEST args
47 * @return boolean success flag
49 protected function prepare(array $args=array())
51 parent::prepare($args);
53 if ($this->format !== 'json') {
54 $this->clientError('This method currently only serves JSON.', 415);
57 $id = $this->trimmed('id');
59 $this->original = Notice::getKV('id', $id);
61 if (!($this->original instanceof Notice)) {
62 // TRANS: Client error displayed trying to display redents of a non-exiting notice.
63 $this->clientError(_('No such notice.'), 400);
66 $cnt = $this->trimmed('count');
68 if (empty($cnt) || !is_integer($cnt)) {
71 $this->cnt = min((int)$cnt, self::MAXCOUNT);
80 * Get favs and return them as json object
82 * @param array $args $_REQUEST data (unused)
86 protected function handle()
92 $fave->selectAdd('user_id');
93 $fave->notice_id = $this->original->id;
94 $fave->orderBy('modified');
95 if (!is_null($this->cnt)) {
96 $fave->limit(0, $this->cnt);
99 $ids = $fave->fetchAll('user_id');
101 // get nickname and profile image
102 $ids_with_profile_data = array();
104 foreach($ids as $id) {
105 $profile = Profile::getKV('id', $id);
106 $ids_with_profile_data[$i]['user_id'] = $id;
107 $ids_with_profile_data[$i]['nickname'] = $profile->nickname;
108 $ids_with_profile_data[$i]['fullname'] = $profile->fullname;
109 $ids_with_profile_data[$i]['profileurl'] = $profile->profileurl;
110 $profile = new Profile();
112 $avatarurl = $profile->avatarUrl(24);
113 $ids_with_profile_data[$i]['avatarurl'] = $avatarurl;
117 $this->initDocument('json');
118 $this->showJsonObjects($ids_with_profile_data);
119 $this->endDocument('json');
123 * Return true if read only.
127 * @param array $args other arguments
129 * @return boolean is read only action?
132 function isReadOnly($args)