Passed
Push — master ( 6902f8...25d1e0 )
by Xavier
02:04
created

AdminController::findStudent()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 4
nop 2
1
<?php
2
3
/*
4
 * @author  Xavier Chopin <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Admin\Controller;
11
12
use App\Model\User;
13
use Respect\Validation\Validator as V;
14
use Slim\Http\Request;
15
use Slim\Http\Response;
16
use App\Controller\Controller;
17
18
class AdminController extends Controller
19
{
20
21
    public function findStudent(Request $request, Response $response)
22
    {
23
        if ($request->isPost()) {
24
25
            $keyword = $request->getParam('name');
26
            $filter = '(&(businesscategory=E*)(displayname=*' . $keyword . '*))';
27
            $res = [];
28
29
            foreach($this->ldap($filter, ['displayname', 'uid']) as $student) {
30
                if ($student['uid'][0] != null)
31
                    $res += [ $student['uid'][0] => $student['displayname'][0] ];
32
            }
33
34
            return $this->json($response, $res);
35
        }
36
37
        return $this->view->render($response, 'find-student.twig');
38
    }
39
}
40