1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* FlexiPeeHP - Objekt kontaktu. |
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
|
|
|
* Příloha |
13
|
|
|
* |
14
|
|
|
* @link https://www.flexibee.eu/api/dokumentace/ref/attachments/ |
15
|
|
|
* @link https://demo.flexibee.eu/c/demo/priloha/properties |
16
|
|
|
*/ |
17
|
|
|
class Priloha extends FlexiBeeRW |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Evidence užitá objektem. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
public $evidence = 'priloha'; |
25
|
|
|
public static $relatedEvidence = [ |
26
|
|
|
'prodejka' => 'doklFak', 'pohledavka' => 'doklFak', 'zavazek' => 'doklFak', |
27
|
|
|
'faktura-prijata' => 'doklFak', 'faktura-vydana' => 'doklFak', |
28
|
|
|
'interni-doklad' => 'doklInt', 'pokladni-pohyb' => 'doklInt', 'vzajemny-zapocet' => 'doklInt', |
29
|
|
|
'banka' => 'doklInt', |
30
|
|
|
'poptavka-vydana' => 'doklObch', 'poptavka-prijata' => 'doklObch', 'objednavka-prijata' => 'doklObch', |
31
|
|
|
'nabidka-vydana' => 'doklObch', |
32
|
|
|
'objednavka-vydana' => 'doklObch', 'nabidka-prijata' => 'doklObch', |
33
|
|
|
'skladovy-pohyb' => 'doklSklad', |
34
|
|
|
'cenik' => 'cenik', |
35
|
|
|
'adresar' => 'adresar', 'kontakt' => 'kontakt' |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
public function attachFile($filepath, $attachmentData = []) |
39
|
|
|
{ |
40
|
|
|
if (file_exists($filepath)) { |
41
|
|
|
$attachmentData['nazSoub'] = basename($filepath); |
42
|
|
|
$attachmentData['contentType'] = mime_content_type($filepath); |
43
|
|
|
$attachmentData['dataSize'] = filesize($filepath); |
44
|
|
|
$attachmentData['dataHash'] = md5_file($filepath); |
45
|
|
|
|
46
|
|
|
switch ($attachmentData['contentType']) { |
47
|
|
|
case 'image/png': |
48
|
|
|
case 'image/gif': |
49
|
|
|
case 'image/jpeg': |
|
|
|
|
50
|
|
|
|
51
|
|
|
break; |
52
|
|
|
} |
53
|
|
|
$attachmentData['content'] = base64_encode(file_get_contents($filepath)); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Obtain url for Attachment Download |
59
|
|
|
* |
60
|
|
|
* @return string url |
61
|
|
|
*/ |
62
|
|
|
public static function getDownloadUrl($object) |
63
|
|
|
{ |
64
|
|
|
return $object->apiURL.'/content'; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getFirsAttachment($object) |
68
|
|
|
{ |
69
|
|
|
$attachments = self::getAttachmentsList($object); |
70
|
|
|
return count($attachments) ? current($attachments) : null; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public static function download($object, $attachmentID = null) |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
header('Content-Description: File Transfer'); |
76
|
|
|
header('Content-Type: application/octet-stream'); |
77
|
|
|
header('Content-Transfer-Encoding: binary'); |
78
|
|
|
header('Expires: 0'); |
79
|
|
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
80
|
|
|
header('Pragma: public'); |
81
|
|
|
header('Content-Disposition: attachment; filename='.$this->host->getName().'_nrpe.sh'); |
|
|
|
|
82
|
|
|
header('Content-Length: '.strlen($nrpesh)); |
|
|
|
|
83
|
|
|
echo $object; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public static function saveToFile($object, $filename, $attachmentID = null) |
|
|
|
|
87
|
|
|
{ |
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Add Attachment from File |
93
|
|
|
* |
94
|
|
|
* @param FlexiBeeRW $object |
95
|
|
|
* @param string $filename |
96
|
|
|
* |
97
|
|
|
* @return int HTTP response code |
98
|
|
|
*/ |
99
|
|
|
public static function addAttachmentFromFile($object, $filename) |
100
|
|
|
{ |
101
|
|
|
return self::addAttachment($object, basename($filename), |
102
|
|
|
file_get_contents($filename), mime_content_type($filename)); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Add Attachment related to current $object content |
107
|
|
|
* |
108
|
|
|
* @param FlexiBeeRW $object |
109
|
|
|
* @param string $filename |
110
|
|
|
* @param string $attachment Body |
111
|
|
|
* @param string $contentType Attachment Content-Type |
112
|
|
|
* |
113
|
|
|
* @return int HTTP Response code |
114
|
|
|
*/ |
115
|
|
|
public static function addAttachment($object, $filename, $attachment, |
116
|
|
|
$contentType) |
117
|
|
|
{ |
118
|
|
|
$headersBackup = $object->defaultHttpHeaders; |
119
|
|
|
$object->postFields = $attachment; |
120
|
|
|
$object->defaultHttpHeaders['Content-Type'] = $contentType; |
121
|
|
|
$url = $object->getFlexiBeeURL().'/prilohy/new/'.$filename; |
122
|
|
|
$response = $object->doCurlRequest($url, |
123
|
|
|
'PUT'); |
|
|
|
|
124
|
|
|
$object->defaultHttpHeaders = $headersBackup; |
125
|
|
|
return $response; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Obtain Record related attachments list |
130
|
|
|
* |
131
|
|
|
* @param FlexiBeeRO $object |
132
|
|
|
* @return array |
133
|
|
|
*/ |
134
|
|
|
public static function getAttachmentsList($object) |
135
|
|
|
{ |
136
|
|
|
return $object->getFlexiData($object->getFlexiBeeURL().'/prilohy'); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
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.