EditDonors   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addNotices() 0 9 3
A __invoke() 0 17 3
A doActions() 0 2 1
1
<?php
2
/**
3
 * Edit donors page controller class file
4
 *
5
 * @package    EBloodBank
6
 * @subpackage Controllers
7
 * @since      1.0
8
 */
9
namespace EBloodBank\Controllers;
10
11
use EBloodBank\Notices;
12
13
/**
14
 * Edit donors page controller class
15
 *
16
 * @since 1.0
17
 */
18
class EditDonors extends ViewDonors
19
{
20
    /**
21
     * @return void
22
     * @since 1.0
23
     */
24
    public function __invoke()
25
    {
26
        if ($this->hasAuthenticatedUser() && $this->getAcl()->isUserAllowed($this->getAuthenticatedUser(), 'Donor', 'edit')) {
27
            $this->doActions();
28
            $this->addNotices();
29
            $view = $this->viewFactory->forgeView('edit-donors', [
30
                'donors'             => $this->getQueriedDonors(),
31
                'pagination.total'   => $this->getPagesTotal(),
32
                'pagination.current' => $this->getCurrentPage(),
33
                'filter.criteria'    => $this->getFilterCriteria(),
34
                'cityRepository'     => $this->getCityRepository(),
35
                'districtRepository' => $this->getDistrictRepository(),
36
            ]);
37
        } else {
38
            $view = $this->viewFactory->forgeView('error-403');
39
        }
40
        $view();
41
    }
42
43
    /**
44
     * @return void
45
     * @since 1.0
46
     */
47
    protected function doActions()
48
    {
49
    }
50
51
    /**
52
     * @return void
53
     * @since 1.0
54
     */
55
    protected function addNotices()
56
    {
57
        if (filter_has_var(INPUT_GET, 'flag-approved')) {
58
            $approved = (int) filter_input(INPUT_GET, 'flag-approved');
59
            Notices::addNotice('approved', sprintf(n__('%d donor approved.', '%d donors approved.', $approved), $approved), 'success');
60
        }
61
        if (filter_has_var(INPUT_GET, 'flag-deleted')) {
62
            $deleted = (int) filter_input(INPUT_GET, 'flag-deleted');
63
            Notices::addNotice('deleted', sprintf(n__('%d donor permanently deleted.', '%d donors permanently deleted.', $deleted), $deleted), 'success');
64
        }
65
    }
66
}
67