Adresar   A
last analyzed

Complexity

Total Complexity 36

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 36
eloc 54
c 1
b 0
f 0
dl 0
loc 118
rs 9.52

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getBankAccountNumber() 0 7 4
B getNotificationEmailAddress() 0 20 10
B getCellPhoneNumber() 0 20 9
C getAnyPhoneNumber() 0 29 13
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
use FlexiPeeHP\Adresar;
12
use FlexiPeeHP\Firma;
13
use FlexiPeeHP\RW;
14
use FlexiPeeHP\Stitky;
15
use FlexiPeeHP\SubItems;
16
/**
17
 * Adresář
18
 *
19
 * @link https://demo.flexibee.eu/c/demo/adresar/properties položky evidence
20
 */
21
class Adresar extends RW
22
{
23
    use Stitky;
24
    use SubItems;
25
    use Firma;
26
    
27
    /**
28
     * Evidence užitá objektem.
29
     *
30
     * @var string
31
     */
32
    public $evidence = 'adresar';
33
34
    /**
35
     * get Email address for Customer with primary contact prefered
36
     * 
37
     * @return string email of primary contact or address email or null
38
     */
39
    public function getNotificationEmailAddress()
40
    {
41
        $email     = null;
42
        $emailsRaw = $this->getFlexiData($this->getApiURL(),
43
            ['detail' => 'custom:id,email,kontakty(primarni,email)', 'relations' => 'kontakty']);
44
        if (is_array($emailsRaw) && !empty($emailsRaw[0])) {
45
            $emails = $emailsRaw[0];
46
            if (array_key_exists('email', $emails) && strlen(trim($emails['email']))) {
47
                $email = $emails['email'];
48
            }
49
            if (array_key_exists('kontakty', $emails) && !empty($emails['kontakty'])) {
50
                foreach ($emails['kontakty'] as $kontakt) {
51
                    if (($kontakt['primarni'] == 'true') && strlen(trim($kontakt['email']))) {
52
                        $email = $kontakt['email'];
53
                        break;
54
                    }
55
                }
56
            }
57
        }
58
        return $email;
59
    }
60
61
    /**
62
     * get cell phone Number for Customer with primary contact prefered
63
     * 
64
     * @return string cell phone number of primary contact or address cell number or null
65
     */
66
    public function getCellPhoneNumber()
67
    {
68
        $mobil     = null;
69
        $mobilsRaw = $this->getFlexiData($this->getApiURL(),
70
            ['detail' => 'custom:id,mobil,kontakty(primarni,mobil)', 'relations' => 'kontakty']);
71
        if (is_array($mobilsRaw)) {
0 ignored issues
show
introduced by
The condition is_array($mobilsRaw) is always true.
Loading history...
72
            $mobils = $mobilsRaw[0];
73
            if (array_key_exists('mobil', $mobils) && strlen(trim($mobils['mobil']))) {
74
                $mobil = $mobils['mobil'];
75
            }
76
            if (array_key_exists('kontakty', $mobils) && !empty($mobils['kontakty'])) {
77
                foreach ($mobils['kontakty'] as $kontakt) {
78
                    if (($kontakt['primarni'] == 'true') && strlen(trim($kontakt['mobil']))) {
79
                        $mobil = $kontakt['mobil'];
80
                        break;
81
                    }
82
                }
83
            }
84
        }
85
        return $mobil;
86
    }
87
    
88
    /**
89
     * get any phone Number for Customer with primary contact prefered
90
     * 
91
     * @return string phone number of primary contact or address's phone number or null
92
     */
93
    public function getAnyPhoneNumber()
94
    {
95
        $phoneNo    = null;
96
        $numbersRaw = $this->getFlexiData($this->getApiURL(),
97
            ['detail' => 'custom:id,mobil,tel,kontakty(primarni,mobil,tel)', 'relations' => 'kontakty']);
98
        if (is_array($numbersRaw) && !empty($numbersRaw[0])) {
99
            $numbers = $numbersRaw[0];
100
            if (array_key_exists('mobil', $numbers) && strlen(trim($numbers['mobil']))) {
101
                $phoneNo = $numbers['mobil'];
102
            }
103
            if (array_key_exists('tel', $numbers) && strlen(trim($numbers['tel']))) {
104
                $phoneNo = $numbers['tel'];
105
            }
106
            if (array_key_exists('kontakty', $numbers) && !empty($numbers['kontakty'])) {
107
                foreach ($numbers['kontakty'] as $kontakt) {
108
                    if ($kontakt['primarni'] == 'true') {
109
                        
110
                    }
111
                    if (strlen(trim($kontakt['mobil']))) {
112
                        $phoneNo = $kontakt['mobil'];
113
                        break;
114
                    } elseif (strlen(trim($kontakt['mobil']))) {
115
                        $phoneNo = $kontakt['mobil'];
116
                        break;
117
                    }
118
                }
119
            }
120
        }
121
        return $phoneNo;
122
    }
123
    
124
    
125
    /**
126
     * 
127
     * 
128
     * @param Adresar|string|int $address
129
     * 
130
     * @return array bank account details
131
     */
132
    public function getBankAccountNumber($address = null)
133
    {
134
        if (is_null($address)) {
135
            $address = $this->getMyKey();
136
        }
137
        $bucRaw = $this->getColumnsFromAbraFlexi(['buc', 'smerKod'], ['firma'=> $address ,'evidence' => 'adresar-bankovni-ucet']);
138
        return (!empty($bucRaw) && array_key_exists(0, $bucRaw)) ? $bucRaw : [];
139
    }
140
    
141
}
142