123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <?php
- defined('GNUSOCIAL') || die();
- class ApiGroupListAllAction extends ApiPrivateAuthAction
- {
- public $groups = null;
-
- public function prepare(array $args = [])
- {
- parent::prepare($args);
- $this->user = $this->getTargetUser(null);
- $this->groups = $this->getGroups();
- return true;
- }
-
- public function handle()
- {
- parent::handle();
- $sitename = common_config('site', 'name');
-
- $title = sprintf(_("%s groups"), $sitename);
- $taguribase = TagURI::base();
- $id = "tag:$taguribase:Groups";
- $link = common_local_url('groups');
-
- $subtitle = sprintf(_("groups on %s"), $sitename);
- switch ($this->format) {
- case 'xml':
- $this->showXmlGroups($this->groups);
- break;
- case 'rss':
- $this->showRssGroups($this->groups, $title, $link, $subtitle);
- break;
- case 'atom':
- $selfuri = common_root_url() .
- 'api/statusnet/groups/list_all.atom';
- $this->showAtomGroups(
- $this->groups,
- $title,
- $id,
- $link,
- $subtitle,
- $selfuri
- );
- break;
- case 'json':
- $this->showJsonGroups($this->groups);
- break;
- default:
- $this->clientError(
-
- _('API method not found.'),
- 404,
- $this->format
- );
- break;
- }
- }
-
- public function getGroups()
- {
- $group = new User_group();
- $offset = intval($this->page - 1) * intval($this->count);
- $limit = intval($this->count);
- $group->query(
- 'SELECT user_group.* '.
- 'FROM user_group INNER JOIN local_group ' .
- 'ON user_group.id = local_group.group_id '.
- 'ORDER BY created DESC ' .
- 'LIMIT ' . $limit . ' OFFSET ' . $offset
- );
- $groups = array();
- while ($group->fetch()) {
- $groups[] = clone($group);
- }
- return $groups;
- }
-
- public function isReadOnly($args)
- {
- return true;
- }
-
- public function lastModified()
- {
- if (!empty($this->groups) && (count($this->groups) > 0)) {
- return strtotime($this->groups[0]->created);
- }
- return null;
- }
-
- public function etag()
- {
- if (!empty($this->groups) && (count($this->groups) > 0)) {
- $last = count($this->groups) - 1;
- return '"' . implode(
- ':',
- array($this->arg('action'),
- common_user_cache_hash($this->auth_user),
- common_language(),
- strtotime($this->groups[0]->created),
- strtotime($this->groups[$last]->created))
- )
- . '"';
- }
- return null;
- }
- }
|