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