groupqueue.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * List of group members
  6. *
  7. * PHP version 5
  8. *
  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.
  13. *
  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.
  18. *
  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/>.
  21. *
  22. * @category Group
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@status.net>
  25. * @copyright 2008-2009 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. require_once(INSTALLDIR.'/lib/profilelist.php');
  33. require_once INSTALLDIR.'/lib/publicgroupnav.php';
  34. /**
  35. * List of group members
  36. *
  37. * @category Group
  38. * @package StatusNet
  39. * @author Evan Prodromou <evan@status.net>
  40. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  41. * @link http://status.net/
  42. */
  43. class GroupqueueAction extends GroupAction
  44. {
  45. var $page = null;
  46. function isReadOnly($args)
  47. {
  48. return true;
  49. }
  50. // @todo FIXME: most of this belongs in a base class, sounds common to most group actions?
  51. protected function prepare(array $args=array())
  52. {
  53. parent::prepare($args);
  54. $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
  55. $nickname_arg = $this->arg('nickname');
  56. $nickname = common_canonical_nickname($nickname_arg);
  57. // Permanent redirect on non-canonical nickname
  58. if ($nickname_arg != $nickname) {
  59. $args = array('nickname' => $nickname);
  60. if ($this->page != 1) {
  61. $args['page'] = $this->page;
  62. }
  63. common_redirect(common_local_url('groupqueue', $args), 301);
  64. }
  65. if (!$nickname) {
  66. // TRANS: Client error displayed when trying to view group members without providing a group nickname.
  67. $this->clientError(_('No nickname.'), 404);
  68. }
  69. $local = Local_group::getKV('nickname', $nickname);
  70. if (!$local) {
  71. // TRANS: Client error displayed when trying to view group members for a non-existing group.
  72. $this->clientError(_('No such group.'), 404);
  73. }
  74. $this->group = User_group::getKV('id', $local->group_id);
  75. if (!$this->group) {
  76. // TRANS: Client error displayed when trying to view group members for an object that is not a group.
  77. $this->clientError(_('No such group.'), 404);
  78. }
  79. $cur = common_current_user();
  80. if (!$cur || !$cur->isAdmin($this->group)) {
  81. // TRANS: Client error displayed when trying to approve group applicants without being a group administrator.
  82. $this->clientError(_('Only the group admin may approve users.'));
  83. }
  84. return true;
  85. }
  86. function title()
  87. {
  88. if ($this->page == 1) {
  89. // TRANS: Title of the first page showing pending group members still awaiting approval to join the group.
  90. // TRANS: %s is the name of the group.
  91. return sprintf(_('%s group members awaiting approval'),
  92. $this->group->nickname);
  93. } else {
  94. // TRANS: Title of all but the first page showing pending group members still awaiting approval to join the group.
  95. // TRANS: %1$s is the name of the group, %2$d is the page number of the members list.
  96. return sprintf(_('%1$s group members awaiting approval, page %2$d'),
  97. $this->group->nickname,
  98. $this->page);
  99. }
  100. }
  101. protected function handle()
  102. {
  103. parent::handle();
  104. $this->showPage();
  105. }
  106. function showPageNotice()
  107. {
  108. $this->element('p', 'instructions',
  109. // TRANS: Page notice for group members page.
  110. _('A list of users awaiting approval to join this group.'));
  111. }
  112. function showContent()
  113. {
  114. $offset = ($this->page-1) * PROFILES_PER_PAGE;
  115. $limit = PROFILES_PER_PAGE + 1;
  116. $cnt = 0;
  117. $members = $this->group->getRequests($offset, $limit);
  118. if ($members) {
  119. // @fixme change!
  120. $member_list = new GroupQueueList($members, $this->group, $this);
  121. $cnt = $member_list->show();
  122. }
  123. $members->free();
  124. $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
  125. $this->page, 'groupqueue',
  126. array('nickname' => $this->group->nickname));
  127. }
  128. }
  129. // @todo FIXME: documentation missing.
  130. class GroupQueueList extends GroupMemberList
  131. {
  132. function newListItem($profile)
  133. {
  134. return new GroupQueueListItem($profile, $this->group, $this->action);
  135. }
  136. }
  137. // @todo FIXME: documentation missing.
  138. class GroupQueueListItem extends GroupMemberListItem
  139. {
  140. function showActions()
  141. {
  142. $this->startActions();
  143. if (Event::handle('StartProfileListItemActionElements', array($this))) {
  144. $this->showApproveButtons();
  145. Event::handle('EndProfileListItemActionElements', array($this));
  146. }
  147. $this->endActions();
  148. }
  149. function showApproveButtons()
  150. {
  151. $this->out->elementStart('li', 'entity_approval');
  152. $form = new ApproveGroupForm($this->out, $this->group, $this->profile);
  153. $form->show();
  154. $this->out->elementEnd('li');
  155. }
  156. }