2 namespace wcf\system\message\embedded\object;
3 use wcf\data\attachment\AttachmentList;
4 use wcf\data\object\type\ObjectTypeCache;
5 use wcf\util\ArrayUtil;
8 * IMessageEmbeddedObjectHandler implementation for attachments.
11 * @copyright 2001-2015 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package com.woltlab.wcf
14 * @subpackage system.message.embedded.object
15 * @category Community Framework
17 class AttachmentMessageEmbeddedObjectHandler extends AbstractMessageEmbeddedObjectHandler {
19 * @see \wcf\system\message\embedded\object\IMessageEmbeddedObjectHandler::parseMessage()
21 public function parseMessage($message) {
22 $parsedAttachmentIDs = array_unique(ArrayUtil::toIntegerArray(array_merge(self::getFirstParameters($message, 'attach'), self::getTextParameters($message, 'attach'))));
23 if (!empty($parsedAttachmentIDs)) {
24 $attachmentIDs = array();
25 foreach ($parsedAttachmentIDs as $parsedAttachmentID) {
26 if ($parsedAttachmentID) $attachmentIDs[] = $parsedAttachmentID;
29 if (!empty($attachmentIDs)) {
30 $attachmentList = new AttachmentList();
31 $attachmentList->getConditionBuilder()->add("attachment.attachmentID IN (?)", array($attachmentIDs));
32 $attachmentList->readObjectIDs();
34 return $attachmentList->getObjectIDs();
42 * @see \wcf\system\message\embedded\object\IMessageEmbeddedObjectHandler::loadObjects()
44 public function loadObjects(array $objectIDs) {
45 $attachmentList = new AttachmentList();
46 $attachmentList->setObjectIDs($objectIDs);
47 $attachmentList->readObjects();
49 // group attachments by object type
50 $groupedAttachments = array();
51 foreach ($attachmentList->getObjects() as $attachment) {
52 if (!isset($groupedAttachments[$attachment->objectTypeID])) $groupedAttachments[$attachment->objectTypeID] = array();
53 $groupedAttachments[$attachment->objectTypeID][] = $attachment;
57 foreach ($groupedAttachments as $objectTypeID => $attachments) {
58 $processor = ObjectTypeCache::getInstance()->getObjectType($objectTypeID)->getProcessor();
59 if ($processor !== null) {
60 $processor->setPermissions($attachments);
64 return $attachmentList->getObjects();