Passed
Push — master ( 21643f...a0935b )
by Vítězslav
04:01
created

Adresar::getCellPhoneNumber()   B

Complexity

Conditions 9
Paths 9

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 20
rs 8.0555
c 0
b 0
f 0
cc 9
nc 9
nop 0
1
<?php
2
/**
3
 * FlexiPeeHP - Objekt adresáře.
4
 *
5
 * @author     Vítězslav Dvořák <[email protected]>
6
 * @copyright  (C) 2015-2017 Spoje.Net
7
 */
8
9
namespace FlexiPeeHP;
10
11
/**
12
 * Adresář
13
 *
14
 * @link https://demo.flexibee.eu/c/demo/adresar/properties položky evidence
15
 */
16
class Adresar extends FlexiBeeRW
17
{
18
    /**
19
     * Evidence užitá objektem.
20
     *
21
     * @var string
22
     */
23
    public $evidence = 'adresar';
24
25
    /**
26
     * get Email address for Customer with primary contact prefered
27
     * 
28
     * @return string email of primary contact or address email or null
29
     */
30
    public function getNotificationEmailAddress()
31
    {
32
        $email     = null;
33
        $emailsRaw = $this->getFlexiData($this->getApiURL(),
34
            ['detail' => 'custom:id,email,kontakty(primarni,email)', 'relations' => 'kontakty']);
35
        if (is_array($emailsRaw)) {
0 ignored issues
show
introduced by
The condition is_array($emailsRaw) is always true.
Loading history...
36
            $emails = $emailsRaw[0];
37
            if (array_key_exists('email', $emails) && strlen(trim($emails['email']))) {
38
                $email = $emails['email'];
39
            }
40
            if (array_key_exists('kontakty', $emails) && !empty($emails['kontakty'])) {
41
                foreach ($emails['kontakty'] as $kontakt) {
42
                    if (($kontakt['primarni'] == 'true') && strlen(trim($kontakt['email']))) {
43
                        $email = $kontakt['email'];
44
                        break;
45
                    }
46
                }
47
            }
48
        }
49
        return $email;
50
    }
51
52
    /**
53
     * get cell phone Number for Customer with primary contact prefered
54
     * 
55
     * @return string cell phone number of primary contact or address cell number or null
56
     */
57
    public function getCellPhoneNumber()
58
    {
59
        $mobil     = null;
60
        $mobilsRaw = $this->getFlexiData($this->getApiURL(),
61
            ['detail' => 'custom:id,mobil,kontakty(primarni,mobil)', 'relations' => 'kontakty']);
62
        if (is_array($mobilsRaw)) {
0 ignored issues
show
introduced by
The condition is_array($mobilsRaw) is always true.
Loading history...
63
            $mobils = $mobilsRaw[0];
64
            if (array_key_exists('mobil', $mobils) && strlen(trim($mobils['mobil']))) {
65
                $mobil = $mobils['mobil'];
66
            }
67
            if (array_key_exists('kontakty', $mobils) && !empty($mobils['kontakty'])) {
68
                foreach ($mobils['kontakty'] as $kontakt) {
69
                    if (($kontakt['primarni'] == 'true') && strlen(trim($kontakt['mobil']))) {
70
                        $mobil = $kontakt['mobil'];
71
                        break;
72
                    }
73
                }
74
            }
75
        }
76
        return $mobil;
77
    }
78
}
79