Completed
Push — develop ( 4092da...af8557 )
by
unknown
07:48
created

LoadActiveOrganizations   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 8
dl 0
loc 47
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B __invoke() 0 32 3
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 Jobs\Listener;
12
13
use Core\Listener\Events\AjaxEvent;
14
15
/**
16
 * Listener paginates through the list of active organizations.
17
 * 
18
 * @author Mathias Gelhausen <[email protected]>
19
 * @since 0.30
20
 */
21
class LoadActiveOrganizations 
22
{
23
    /**
24
     * The paginator.
25
     *
26
     * @var \Zend\Paginator\Paginator
27
     */
28
    private $paginator;
29
30
    public function __construct($paginator)
31
    {
32
        $this->paginator = $paginator;
33
    }
34
35
    public function __invoke(AjaxEvent $event)
36
    {
37
        $request = $event->getRequest();
38
        $query   = $request->getQuery();
39
        $page    = $query->get('page', 1);
40
41
        $this->paginator->setCurrentPageNumber($page)
42
                        ->setItemCountPerPage(30);
43
44
        $options = [];
45
        foreach ($this->paginator as $org) {
46
            /* @var $org \Organizations\Entity\Organization */
47
48
            $name     = $org->getOrganizationName()->getName();
49
            $contact  = $org->getContact();
50
            $image    = $org->getImage();
0 ignored issues
show
Deprecated Code introduced by
The method Organizations\Entity\Organization::getImage() has been deprecated with message: since 0.29; use $this->getImages()->get()

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
51
            $imageUrl = $image ? $image->getUri() : '';
52
53
            $options[] = [ 'id' => $org->getId(),
54
                           'text' => $name . '|'
55
                                      . $contact->getCity() . '|'
56
                                      . $contact->getStreet() . '|'
57
                                      . $contact->getHouseNumber() . '|'
58
                                      . $imageUrl
59
            ];
60
        }
61
62
        return [
63
            'items' => $options,
64
            'count' => $this->paginator->getTotalItemCount(),
65
        ];
66
    }
67
}