Passed
Push — master ( 51c72d...20f309 )
by Vítězslav
02:47
created

Adresar::getNotificationEmailAddress()   B

Complexity

Conditions 9
Paths 9

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 7.756
c 0
b 0
f 0
cc 9
eloc 13
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