Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
93.75% |
15 / 16 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| GenerisUserService | |
93.75% |
15 / 16 |
|
66.67% |
2 / 3 |
4.00 | |
0.00% |
0 / 1 |
| findUser | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| getUser | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUsers | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2020-2021 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\tao\model\user; |
| 23 | |
| 24 | use oat\oatbox\user\UserService; |
| 25 | use oat\oatbox\service\ConfigurableService; |
| 26 | use oat\tao\model\search\SearchProxy; |
| 27 | use oat\tao\model\search\SearchQuery; |
| 28 | use oat\tao\model\TaoOntology; |
| 29 | use oat\generis\model\OntologyAwareTrait; |
| 30 | |
| 31 | class GenerisUserService extends ConfigurableService implements UserService |
| 32 | { |
| 33 | use OntologyAwareTrait; |
| 34 | |
| 35 | /** |
| 36 | * {@inheritDoc} |
| 37 | * @see \oat\oatbox\user\UserService::findUser() |
| 38 | */ |
| 39 | public function findUser($searchString) |
| 40 | { |
| 41 | /** @var SearchProxy $searchProxy */ |
| 42 | $searchProxy = $this->getServiceLocator()->get(SearchProxy::SERVICE_ID); |
| 43 | |
| 44 | $query = new SearchQuery( |
| 45 | $searchString, |
| 46 | TaoOntology::CLASS_URI_TAO_USER, |
| 47 | TaoOntology::CLASS_URI_TAO_USER, |
| 48 | 0, |
| 49 | 10, |
| 50 | 1 |
| 51 | ); |
| 52 | |
| 53 | $result = $searchProxy->searchByQuery($query); |
| 54 | return $this->getUsers(array_column($result['data'] ?? [], 'id')); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * {@inheritDoc} |
| 59 | * @see \oat\oatbox\user\UserService::getUser() |
| 60 | */ |
| 61 | public function getUser($userId) |
| 62 | { |
| 63 | return new \core_kernel_users_GenerisUser($this->getResource($userId)); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * {@inheritDoc} |
| 68 | * @see \oat\oatbox\user\UserService::getUsers() |
| 69 | */ |
| 70 | public function getUsers($userIds) |
| 71 | { |
| 72 | $users = []; |
| 73 | foreach ($userIds as $id) { |
| 74 | $users[$id] = $this->getUser($id); |
| 75 | } |
| 76 | return $users; |
| 77 | } |
| 78 | } |