1 | <?php |
||
18 | class AttachFile extends ChatAPI { |
||
19 | |||
20 | /** |
||
21 | * @var $userMapper \OCA\Chat\OCH\Db\UserMapper |
||
22 | */ |
||
23 | private $userMapper; |
||
24 | |||
25 | /** |
||
26 | * @var $attachmentMapper \OCA\Chat\OCH\Db\AttachmentMapper |
||
27 | */ |
||
28 | private $attachmentMapper; |
||
29 | |||
30 | /** |
||
31 | * @var $pushMessageMapper \OCA\Chat\OCH\Db\PushMessageMapper |
||
32 | */ |
||
33 | private $pushMessageMapper; |
||
34 | |||
35 | public function __construct( |
||
36 | Chat $app, |
||
37 | UserMapper $userMapper, |
||
38 | AttachmentMapper $attachmentMapper, |
||
39 | PushMessageMapper $pushMessageMapper |
||
40 | ){ |
||
41 | $this->app = $app; |
||
|
|||
42 | $this->userMapper = $userMapper; |
||
43 | $this->attachmentMapper = $attachmentMapper; |
||
44 | $this->pushMessageMapper = $pushMessageMapper; |
||
45 | } |
||
46 | |||
47 | /* |
||
48 | * @param $requestData['user'] String user id of the client |
||
49 | * @param $requestData['session_id'] String session_id of the client |
||
50 | * @param $requestData['timestamp'] Int timestamp when the command was send |
||
51 | */ |
||
52 | public function setRequestData(array $requestData){ |
||
55 | |||
56 | public function execute(){ |
||
57 | $paths = $this->requestData['paths']; |
||
58 | $users = $this->userMapper->findUsersInConv($this->requestData['conv_id']); |
||
59 | foreach ($paths as $path) { |
||
60 | $fileId = $this->app->getFileId($path); |
||
61 | $this->insertInDatabase( |
||
62 | $this->app->getUserId(), |
||
63 | $path, |
||
64 | $fileId, |
||
65 | $this->requestData['timestamp'], |
||
66 | $this->requestData['conv_id'] |
||
67 | ); |
||
68 | $this->sendPushMessage($path); |
||
69 | } |
||
70 | foreach ($users as $user) { |
||
71 | if ($user !== $this->app->getUserId()) { |
||
72 | foreach ($paths as $path) { |
||
73 | $fileId = $this->app->getFileId($path); |
||
74 | $this->share($fileId, $user); |
||
75 | } |
||
76 | } |
||
77 | } |
||
78 | } |
||
79 | |||
80 | private function sendPushMessage($path){ |
||
102 | |||
103 | /** |
||
104 | * Inserts the attachment into the DB |
||
105 | * @param $ownerId ownCloud user id |
||
106 | * @param $path path of the file |
||
107 | * @param $fileId |
||
108 | * @param $timestamp |
||
109 | * @param $convId |
||
110 | */ |
||
111 | private function insertInDatabase($ownerId, $path, $fileId, $timestamp, $convId){ |
||
120 | |||
121 | /** |
||
122 | * @param $fileId the fileId of the file |
||
123 | * @param $shareWIth the ownCloud user to share the file with |
||
124 | */ |
||
125 | private function share($fileId, $shareWIth){ |
||
132 | |||
133 | } |
||
134 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: