CommunityID/modules/users/controllers/UserslistController.php

78 lines
3.1 KiB
PHP
Raw Normal View History

2019-07-17 20:19:00 +00:00
<?php
2019-07-17 20:08:50 +00:00
/*
* @copyright Copyright (C) 2005-2010 Keyboard Monkeys Ltd. http://www.kb-m.com
2019-07-17 20:08:50 +00:00
* @license http://creativecommons.org/licenses/BSD/ BSD License
* @author Keyboard Monkey Ltd
* @since CommunityID 0.9
* @package CommunityID
* @packager Keyboard Monkeys
*/
2019-07-17 20:16:19 +00:00
class Users_UserslistController extends CommunityID_Controller_Action
2019-07-17 20:08:50 +00:00
{
public function indexAction()
{
$this->_helper->viewRenderer->setNeverRender(true);
2019-07-17 20:16:19 +00:00
$users = new Users_Model_Users();
2019-07-17 20:08:50 +00:00
switch($this->_getParam('filter')) {
case 'confirmed':
2019-07-17 20:16:19 +00:00
$where = "accepted_eula=1 AND role != '".Users_Model_User::ROLE_ADMIN."'";
2019-07-17 20:08:50 +00:00
break;
case 'unconfirmed':
2019-07-17 20:16:19 +00:00
$where = "accepted_eula=0 AND role != '".Users_Model_User::ROLE_ADMIN."'";
2019-07-17 20:08:50 +00:00
break;
default:
$where = false;
break;
}
// This retrieves user data from the users table, even if using LDAP. This means the user's full name
// might be out of sync with what it's in LDAP. No biggie since user's names rarely change ;)
// However do know that a given user name is synced with LDAP every time he logs in.
2019-07-17 20:08:50 +00:00
$usersRows = $users->getUsers(
$this->_getParam('startIndex'),
$this->_getParam('results'),
$this->_getParam('sort', 'registration'),
2019-07-17 20:16:19 +00:00
$this->_getParam('dir', Users_Model_Users::DIR_DESC),
$where,
trim($this->_getParam('search')));
2019-07-17 20:08:50 +00:00
$jsonObj = new StdClass();
$jsonObj->recordsReturned = count($usersRows);
2019-07-17 20:16:19 +00:00
$jsonObj->totalRecords = $users->getNumUsers($where, trim($this->_getParam('search')));
$jsonObj->totalUsers = $users->getNumUsers();
2019-07-17 20:08:50 +00:00
$jsonObj->totalUnconfirmedUsers = $users->getNumUnconfirmedUsers();
2019-07-17 20:16:19 +00:00
$jsonObj->startIndex = $this->_getParam('startIndex');
2019-07-17 20:08:50 +00:00
$jsonObj->sort = $this->_getParam('sort');
$jsonObj->dir = $this->_getParam('dir');
$jsonObj->records = array();
foreach ($usersRows as $user) {
2019-07-17 20:16:19 +00:00
if ($user->role == Users_Model_User::ROLE_ADMIN) {
if ($this->_config->ldap->enabled && $user->username != $this->_config->ldap->admin) {
// this is the admin created during the installation, that is not used when ldap is enabled
continue;
}
2019-07-17 20:08:50 +00:00
$status = $this->view->translate('admin');
} else if ($user->accepted_eula) {
$status = $this->view->translate('confirmed');
} else {
$status = $this->view->translate('unconfirmed');
}
$jsonObjUser = new StdClass();
$jsonObjUser->id = $user->id;
$jsonObjUser->name = $user->getFullName();
$jsonObjUser->registration = $user->registration_date;
$jsonObjUser->role = $user->role;
$jsonObjUser->status = $status;
$jsonObjUser->reminders = $user->accepted_eula? 0 : $user->reminders;
2019-07-17 20:08:50 +00:00
$jsonObj->records[] = $jsonObjUser;
}
echo Zend_Json::encode($jsonObj);
}
}