Completed
Push — FVSv2 ( 9d1e1c...673865 )
by Patrick
06:55 queued 38s
created

VolunteerProfile::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 15
loc 15
rs 9.7666
c 0
b 0
f 0
1
<?php
2
class VolunteerProfile
3
{
4
    protected $dbData;
5
6 View Code Duplication
    public function __construct($uid, $dbData = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
7
    {
8
        if($dbData === null)
9
        {
10
            $dataTable = DataSetFactory::getDataTableByNames('fvs', 'participants');
11
            $filter = new \Data\Filter("uid eq '$uid'");
12
            $profile = $dataTable->read($filter);
13
            if(empty($profile))
14
            {
15
                throw new Exception('Unable to locate user with ID '.$uid);
16
            }
17
            $dbData = $profile[0];
18
        }
19
        $this->dbData = $dbData;
20
    }
21
22
    public function __get($propName)
23
    {
24
        switch($propName)
25
        {
26
            case 'certs':
27
                if(!isset($this->dbData['certs']))
28
                {
29
                    return array();
30
                }
31
                return $this->dbData['certs'];
32
            default:
33
                return $this->dbData[$propName];
34
        }
35
    }
36
37
    public function getDisplayName($type = 'webName')
38
    {
39
        switch($this->dbData[$type])
40
        {
41
            case 'anonymous':
42
                return 'Anonymous';
43
            case 'full':
44
                return $this->dbData['firstName'].' "'.$this->dbData['burnerName'].'" '.$this->dbData['lastName'];
45
            case 'burnerLast':
46
                return $this->dbData['burnerName'].' '.$this->dbData['lastName'];
47
            case 'firstBurner':
48
                return $this->dbData['firstName'].' '.$this->dbData['burnerName'];
49
            case 'burner':
50
                return $this->dbData['burnerName'];
51
        }
52
    }
53
54
    public function isEEAvailable()
55
    {
56
        return isset($this->dbData['firstName']) && isset($this->dbData['lastName']);
57
    }
58
59
    public function userInEmailList($list)
60
    {
61
        if(!isset($this->dbData['email']))
62
        {
63
            return false;
64
        }
65
        if(in_array($this->dbData['email'], $list))
66
        {
67
            return true;
68
        }
69
        return false;
70
    }
71
}
72