2 namespace wcf\system\message\embedded\object;
3 use wcf\data\attachment\AttachmentList;
4 use wcf\data\object\type\ObjectTypeCache;
5 use wcf\system\html\input\HtmlInputProcessor;
8 * IMessageEmbeddedObjectHandler implementation for attachments.
11 * @copyright 2001-2016 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package WoltLabSuite\Core\System\Message\Embedded\Object
15 class AttachmentMessageEmbeddedObjectHandler extends AbstractMessageEmbeddedObjectHandler {
19 public function parse(HtmlInputProcessor $htmlInputProcessor, array $embeddedData) {
20 if (empty($embeddedData['attach'])) {
25 for ($i = 0, $length = count($embeddedData['attach']); $i < $length; $i++) {
26 $attributes = $embeddedData['attach'][$i];
27 $attachmentID = (!empty($attributes[0])) ? intval($attributes[0]) : 0;
29 if ($attachmentID > 0) {
30 $attachmentIDs[] = $attachmentID;
34 if (!empty($attachmentIDs)) {
35 $attachmentList = new AttachmentList();
36 $attachmentList->getConditionBuilder()->add("attachment.attachmentID IN (?)", [$attachmentIDs]);
37 $attachmentList->readObjectIDs();
39 return $attachmentList->getObjectIDs();
48 public function loadObjects(array $objectIDs) {
49 $attachmentList = new AttachmentList();
50 $attachmentList->setObjectIDs($objectIDs);
51 $attachmentList->readObjects();
53 // group attachments by object type
54 $groupedAttachments = [];
55 foreach ($attachmentList->getObjects() as $attachment) {
56 if (!isset($groupedAttachments[$attachment->objectTypeID])) $groupedAttachments[$attachment->objectTypeID] = [];
57 $groupedAttachments[$attachment->objectTypeID][] = $attachment;
61 foreach ($groupedAttachments as $objectTypeID => $attachments) {
62 $processor = ObjectTypeCache::getInstance()->getObjectType($objectTypeID)->getProcessor();
63 if ($processor !== null) {
64 $processor->setPermissions($attachments);
68 return $attachmentList->getObjects();