1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | namespace Aurora\Modules\MailSaveAttachmentsToFilesPlugin; |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | |
18: | |
19: | class Module extends \Aurora\System\Module\AbstractModule |
20: | { |
21: | |
22: | |
23: | |
24: | public $oApiFilecacheManager = null; |
25: | |
26: | public function getFilecacheManager() |
27: | { |
28: | if ($this->oApiFilecacheManager === null) { |
29: | $this->oApiFilecacheManager = new \Aurora\System\Managers\Filecache(); |
30: | } |
31: | |
32: | return $this->oApiFilecacheManager; |
33: | } |
34: | |
35: | public function init() {} |
36: | |
37: | |
38: | |
39: | |
40: | public static function getInstance() |
41: | { |
42: | return parent::getInstance(); |
43: | } |
44: | |
45: | |
46: | |
47: | |
48: | public static function Decorator() |
49: | { |
50: | return parent::Decorator(); |
51: | } |
52: | |
53: | |
54: | |
55: | |
56: | public function getModuleSettings() |
57: | { |
58: | return $this->oModuleSettings; |
59: | } |
60: | |
61: | |
62: | |
63: | |
64: | |
65: | public function Save($UserId, $AccountID, $Attachments = [], $Storage = 'personal', $Path = '') |
66: | { |
67: | $mResult = false; |
68: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
69: | |
70: | $oMailModuleDecorator = \Aurora\Modules\Mail\Module::Decorator(); |
71: | if ($oMailModuleDecorator) { |
72: | $aTempFiles = $oMailModuleDecorator->SaveAttachmentsAsTempFiles($AccountID, $Attachments); |
73: | if (\is_array($aTempFiles)) { |
74: | $sUUID = \Aurora\System\Api::getUserUUIDById($UserId); |
75: | foreach ($aTempFiles as $sTempName => $sData) { |
76: | $aData = \Aurora\System\Api::DecodeKeyValues($sData); |
77: | if (\is_array($aData) && isset($aData['FileName'])) { |
78: | $sFileName = (string) $aData['FileName']; |
79: | $rResource = $this->getFilecacheManager()->getFile($sUUID, $sTempName); |
80: | if ($rResource) { |
81: | $aArgs = array( |
82: | 'UserId' => $UserId, |
83: | 'Type' => $Storage, |
84: | 'Path' => $Path, |
85: | 'Name' => $sFileName, |
86: | 'Data' => $rResource, |
87: | 'Overwrite' => false, |
88: | 'RangeType' => 0, |
89: | 'Offset' => 0, |
90: | 'ExtendedProps' => array() |
91: | ); |
92: | \Aurora\System\Api::GetModuleManager()->broadcastEvent( |
93: | 'Files', |
94: | 'CreateFile', |
95: | $aArgs, |
96: | $mResult |
97: | ); |
98: | } |
99: | } |
100: | } |
101: | } |
102: | } |
103: | |
104: | return $mResult; |
105: | } |
106: | } |
107: | |