Completed
Push — develop ( 8cb156...27be84 )
by
unknown
17:07
created

JobSelectValues   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 6
dl 0
loc 40
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B __invoke() 0 25 2
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2017 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace Applications\Listener;
12
13
use Applications\Paginator\JobSelectPaginator;
14
use Core\Listener\Events\AjaxEvent;
15
16
/**
17
 * Listener to load the job title for JobSelect element via Ajax
18
 * 
19
 * @author Mathias Gelhausen <[email protected]>
20
 * @since 0.29.2
21
 */
22
class JobSelectValues 
23
{
24
    /**
25
     * The job paginator.
26
     *
27
     * @var JobSelectPaginator
28
     */
29
    private $paginator;
30
31
    public function __construct($paginator)
32
    {
33
        $this->paginator = $paginator;
34
    }
35
36
    public function __invoke(AjaxEvent $event)
37
    {
38
        $request = $event->getRequest();
39
        $query   = $request->getQuery();
40
        $q       = $query->get('q');
41
        $p       = $query->get('page');
42
43
        $this->paginator->search($q)
44
                        ->setCurrentPageNumber($p)
45
                        ->setItemCountPerPage(30);
46
47
        $options = [['id' => 0, 'text' => '']];
48
        foreach ($this->paginator as $job) {
49
            /* @var \Jobs\Entity\Job $job */
50
            $options[] = [
51
                'id' => $job->getId(),
52
                'text' => $job->getTitle()
53
            ];
54
        }
55
56
        return [
57
            'items' => $options,
58
            'count' => $this->paginator->getTotalItemCount()
59
        ];
60
    }
61
}