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;
6 use wcf\util\ArrayUtil;
9 * IMessageEmbeddedObjectHandler implementation for attachments.
12 * @copyright 2001-2016 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package com.woltlab.wcf
15 * @subpackage system.message.embedded.object
16 * @category Community Framework
18 class AttachmentMessageEmbeddedObjectHandler extends AbstractMessageEmbeddedObjectHandler {
22 public function parse(HtmlInputProcessor $htmlInputProcessor, array $embeddedData) {
23 if (empty($embeddedData['attach'])) {
28 for ($i = 0, $length = count($embeddedData['attach']); $i < $length; $i++) {
29 $attributes = $embeddedData['attach'][$i];
30 $attachmentID = (!empty($attributes[0])) ? intval($attributes[0]) : 0;
32 if ($attachmentID > 0) {
33 $attachmentIDs[] = $attachmentID;
37 if (!empty($attachmentIDs)) {
38 $attachmentList = new AttachmentList();
39 $attachmentList->getConditionBuilder()->add("attachment.attachmentID IN (?)", [$attachmentIDs]);
40 $attachmentList->readObjectIDs();
42 return $attachmentList->getObjectIDs();
51 public function loadObjects(array $objectIDs) {
52 $attachmentList = new AttachmentList();
53 $attachmentList->setObjectIDs($objectIDs);
54 $attachmentList->readObjects();
56 // group attachments by object type
57 $groupedAttachments = [];
58 foreach ($attachmentList->getObjects() as $attachment) {
59 if (!isset($groupedAttachments[$attachment->objectTypeID])) $groupedAttachments[$attachment->objectTypeID] = [];
60 $groupedAttachments[$attachment->objectTypeID][] = $attachment;
64 foreach ($groupedAttachments as $objectTypeID => $attachments) {
65 $processor = ObjectTypeCache::getInstance()->getObjectType($objectTypeID)->getProcessor();
66 if ($processor !== null) {
67 $processor->setPermissions($attachments);
71 return $attachmentList->getObjects();