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
40 var $cnt = self::MAXCOUNT;
43 * Take arguments for running
45 * @param array $args $_REQUEST args
47 * @return boolean success flag
49 function prepare($args)
51 parent::prepare($args);
53 $id = $this->trimmed('id');
55 $this->original = Notice::staticGet('id', $id);
57 if (empty($this->original)) {
58 // TRANS: Client error displayed trying to display redents of a non-exiting notice.
59 $this->clientError(_('No such notice.'), 400, $this->format);
63 $cnt = $this->trimmed('count');
65 if (empty($cnt) || !is_integer($cnt)) {
68 $this->cnt = min((int)$cnt, self::MAXCOUNT);
77 * Get favs and return them as json object
79 * @param array $args $_REQUEST data (unused)
83 function handle($args)
85 parent::handle($args);
89 $fave->selectAdd('user_id');
90 $fave->notice_id = $this->original->id;
91 $fave->orderBy('modified');
92 if (!is_null($this->cnt)) {
93 $fave->limit(0, $this->cnt);
96 $ids = $fave->fetchAll('user_id');
98 // get nickname and profile image
99 $ids_with_profile_data = array();
101 foreach($ids as $id) {
102 $profile = Profile::staticGet('id', $id);
103 $ids_with_profile_data[$i]['user_id'] = $id;
104 $ids_with_profile_data[$i]['nickname'] = $profile->nickname;
105 $ids_with_profile_data[$i]['fullname'] = $profile->fullname;
106 $ids_with_profile_data[$i]['profileurl'] = $profile->profileurl;
107 $profile = new Profile();
109 $avatarurl = $profile->avatarUrl(24);
110 $ids_with_profile_data[$i]['avatarurl'] = $avatarurl;
114 $this->initDocument('json');
115 $this->showJsonObjects($ids_with_profile_data);
116 $this->endDocument('json');
120 * Return true if read only.
124 * @param array $args other arguments
126 * @return boolean is read only action?
129 function isReadOnly($args)