1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* FlexiPeeHP - Objekt kontaktu. |
5
|
|
|
* |
6
|
|
|
* @author Vítězslav Dvořák <[email protected]> |
7
|
|
|
* @copyright (C) 2015-2017 Spoje.Net |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace FlexiPeeHP; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Příloha |
14
|
|
|
* |
15
|
|
|
* @link https://www.flexibee.eu/api/dokumentace/ref/attachments/ |
16
|
|
|
* @link https://demo.flexibee.eu/c/demo/priloha/properties |
17
|
|
|
*/ |
18
|
|
|
class Priloha extends FlexiBeeRW |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Evidence užitá objektem. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
public $evidence = 'priloha'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Evidence s přílohami |
30
|
|
|
* |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
public static $relatedEvidence = [ |
34
|
|
|
'prodejka' => 'doklFak', 'pohledavka' => 'doklFak', 'zavazek' => 'doklFak', |
35
|
|
|
'faktura-prijata' => 'doklFak', 'faktura-vydana' => 'doklFak', |
36
|
|
|
'interni-doklad' => 'doklInt', 'pokladni-pohyb' => 'doklInt', 'vzajemny-zapocet' => 'doklInt', |
37
|
|
|
'banka' => 'doklInt', |
38
|
|
|
'poptavka-vydana' => 'doklObch', 'poptavka-prijata' => 'doklObch', 'objednavka-prijata' => 'doklObch', |
39
|
|
|
'nabidka-vydana' => 'doklObch', |
40
|
|
|
'objednavka-vydana' => 'doklObch', 'nabidka-prijata' => 'doklObch', |
41
|
|
|
'skladovy-pohyb' => 'doklSklad', |
42
|
|
|
'cenik' => 'cenik', |
43
|
|
|
'adresar' => 'adresar', 'kontakt' => 'kontakt' |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Přilož Soubor |
48
|
|
|
* |
49
|
|
|
* @param string $filepath |
50
|
|
|
* @param array $attachmentData |
51
|
|
|
*/ |
52
|
|
|
public function attachFile($filepath, $attachmentData = []) |
53
|
|
|
{ |
54
|
|
|
if (file_exists($filepath)) { |
55
|
|
|
$attachmentData['nazSoub'] = basename($filepath); |
56
|
|
|
$attachmentData['contentType'] = mime_content_type($filepath); |
57
|
|
|
$attachmentData['dataSize'] = filesize($filepath); |
58
|
|
|
$attachmentData['dataHash'] = md5_file($filepath); |
59
|
|
|
|
60
|
|
|
switch ($attachmentData['contentType']) { |
61
|
|
|
case 'image/png': |
62
|
|
|
case 'image/gif': |
63
|
|
|
case 'image/jpeg': |
|
|
|
|
64
|
|
|
|
65
|
|
|
break; |
66
|
|
|
} |
67
|
|
|
$attachmentData['content'] = base64_encode(file_get_contents($filepath)); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Obtain url for Attachment Download |
73
|
|
|
* |
74
|
|
|
* @return string url |
75
|
|
|
*/ |
76
|
|
|
public static function getDownloadUrl($object) |
77
|
|
|
{ |
78
|
|
|
return $object->apiURL . '/content'; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Obtain first attachment for given object |
83
|
|
|
* |
84
|
|
|
* @param FlexiBeeRO $object |
85
|
|
|
* @return array |
86
|
|
|
*/ |
87
|
|
|
public static function getFirstAttachment($object) |
88
|
|
|
{ |
89
|
|
|
$attachments = self::getAttachmentsList($object); |
90
|
|
|
return count($attachments) ? current($attachments) : null; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Send "download" headers first and then file itself |
95
|
|
|
* |
96
|
|
|
* @param FlexiBeeRO $object |
97
|
|
|
* @param int|string $attachmentID |
98
|
|
|
*/ |
99
|
|
|
public static function download($object, $attachmentID = null) |
|
|
|
|
100
|
|
|
{ |
101
|
|
|
header('Content-Description: File Transfer'); |
102
|
|
|
header('Content-Type: application/octet-stream'); |
103
|
|
|
header('Content-Transfer-Encoding: binary'); |
104
|
|
|
header('Expires: 0'); |
105
|
|
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
106
|
|
|
header('Pragma: public'); |
107
|
|
|
header('Content-Disposition: attachment; filename=' . $object->getName() . '_nrpe.sh'); |
|
|
|
|
108
|
|
|
header('Content-Length: ' . strlen($nrpesh)); |
|
|
|
|
109
|
|
|
echo $object; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public static function saveToFile($object, $filename, $attachmentID = null) |
|
|
|
|
113
|
|
|
{ |
114
|
|
|
|
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Add Attachment from File |
119
|
|
|
* |
120
|
|
|
* @param FlexiBeeRW $object |
121
|
|
|
* @param string $filename |
122
|
|
|
* |
123
|
|
|
* @return int HTTP response code |
124
|
|
|
*/ |
125
|
|
|
public static function addAttachmentFromFile($object, $filename) |
126
|
|
|
{ |
127
|
|
|
return self::addAttachment($object, basename($filename), file_get_contents($filename), mime_content_type($filename)); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Add Attachment related to current $object content |
132
|
|
|
* |
133
|
|
|
* @param FlexiBeeRW $object |
134
|
|
|
* @param string $filename |
135
|
|
|
* @param string $attachment Body |
136
|
|
|
* @param string $contentType Attachment Content-Type |
137
|
|
|
* |
138
|
|
|
* @return int HTTP Response code |
139
|
|
|
*/ |
140
|
|
|
public static function addAttachment($object, $filename, $attachment, $contentType) |
141
|
|
|
{ |
142
|
|
|
$headersBackup = $object->defaultHttpHeaders; |
143
|
|
|
$object->postFields = $attachment; |
144
|
|
|
$object->defaultHttpHeaders['Content-Type'] = $contentType; |
145
|
|
|
$url = $object->getFlexiBeeURL() . '/prilohy/new/' . $filename; |
146
|
|
|
$response = $object->doCurlRequest($url, 'PUT'); |
|
|
|
|
147
|
|
|
$object->defaultHttpHeaders = $headersBackup; |
148
|
|
|
return $response; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Obtain Record related attachments list |
153
|
|
|
* |
154
|
|
|
* @param FlexiBeeRO $object |
155
|
|
|
* @return array |
156
|
|
|
*/ |
157
|
|
|
public static function getAttachmentsList($object) |
158
|
|
|
{ |
159
|
|
|
$fburl = $object->getFlexiBeeURL(); |
160
|
|
|
$attachments = $object->getFlexiData($fburl . '/prilohy'); |
161
|
|
|
if (count($attachments)) { |
162
|
|
|
foreach ($attachments as $attachmentID => $attachmentData) { |
163
|
|
|
$attachments[$attachmentID]['url'] = $object->url . '/c/' . $object->company . '/priloha/' . $attachmentData['id']; |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
return $attachments; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
} |
170
|
|
|
|
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.