RegisterUserElementSources   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 38
ccs 0
cts 29
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 32 4
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/patron/license
6
 * @link       https://www.flipboxfactory.com/software/patron/
7
 */
8
9
namespace flipbox\organizations\events\handlers;
10
11
use craft\events\RegisterElementSourcesEvent;
12
use flipbox\organizations\Organizations;
13
use flipbox\organizations\records\UserType;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
class RegisterUserElementSources
20
{
21
    /**
22
     * @param RegisterElementSourcesEvent $event
23
     */
24
    public static function handle(RegisterElementSourcesEvent $event)
25
    {
26
        if ($event->context === 'organizations') {
27
            $event->sources[] = [
28
                'heading' => "Organization Types"
29
            ];
30
31
            $types = UserType::findAll([]);
32
            foreach ($types as $type) {
33
                $event->sources[] = [
34
                    'key' => 'type:' . $type->id,
35
                    'label' => \Craft::t('organizations', $type->name),
36
                    'criteria' => ['organization' => ['userType' => $type->id]],
37
                    'hasThumbs' => true
38
                ];
39
            }
40
41
            $event->sources[] = [
42
                'heading' => "Organization States"
43
            ];
44
45
            $states = Organizations::getInstance()->getSettings()->getUserStates();
46
            foreach ($states as $state => $label) {
47
                $event->sources[] = [
48
                    'key' => 'state:' . $state,
49
                    'label' => $label,
50
                    'criteria' => ['organization' => ['userState' => $state]],
51
                    'hasThumbs' => true
52
                ];
53
            }
54
        }
55
    }
56
}
57