Completed
Push — master ( 44055e...b768aa )
by Vítězslav
02:31
created

Adresar::getBankAccountNumber()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
c 0
b 0
f 0
rs 10
cc 3
nc 4
nop 1
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) && !empty($emailsRaw[0])) {
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
    /**
80
     * get any phone Number for Customer with primary contact prefered
81
     * 
82
     * @return string phone number of primary contact or address's phone number or null
83
     */
84
    public function getAnyPhoneNumber()
85
    {
86
        $phoneNo    = null;
87
        $numbersRaw = $this->getFlexiData($this->getApiURL(),
88
            ['detail' => 'custom:id,mobil,tel,kontakty(primarni,mobil,tel)', 'relations' => 'kontakty']);
89
        if (is_array($numbersRaw) && !empty($numbersRaw[0])) {
90
            $numbers = $numbersRaw[0];
91
            if (array_key_exists('mobil', $numbers) && strlen(trim($numbers['mobil']))) {
92
                $phoneNo = $numbers['mobil'];
93
            }
94
            if (array_key_exists('tel', $numbers) && strlen(trim($numbers['tel']))) {
95
                $phoneNo = $numbers['tel'];
96
            }
97
            if (array_key_exists('kontakty', $numbers) && !empty($numbers['kontakty'])) {
98
                foreach ($numbers['kontakty'] as $kontakt) {
99
                    if ($kontakt['primarni'] == 'true') {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
100
                        
101
                    }
102
                    if (strlen(trim($kontakt['mobil']))) {
103
                        $phoneNo = $kontakt['mobil'];
104
                        break;
105
                    } elseif (strlen(trim($kontakt['mobil']))) {
106
                        $phoneNo = $kontakt['mobil'];
107
                        break;
108
                    }
109
                }
110
            }
111
        }
112
        return $phoneNo;
113
    }
114
    
115
    
116
    /**
117
     * 
118
     * 
119
     * @param Adresar|string|int $address
120
     * 
121
     * @return array bank account details
122
     */
123
    public function getBankAccountNumber($address = null)
124
    {
125
        if (is_null($address)) {
126
            $address = $this->getMyKey();
127
        }
128
        $bucRaw = $this->getColumnsFromFlexibee(['buc', 'smerKod'], ['firma'=> $address ,'evidence' => 'adresar-bankovni-ucet']);
129
        return array_key_exists(0, $bucRaw) ? $bucRaw : [];
130
    }
131
    
132
}
133