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-2014 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 $attachmentList = new AttachmentList();
30 $attachmentList->getConditionBuilder()->add("attachment.attachmentID IN (?)", array($attachmentIDs));
31 $attachmentList->readObjectIDs();
32 return $attachmentList->getObjectIDs();
39 * @see \wcf\system\message\embedded\object\IMessageEmbeddedObjectHandler::loadObjects()
41 public function loadObjects(array $objectIDs) {
42 $attachmentList = new AttachmentList();
43 $attachmentList->setObjectIDs($objectIDs);
44 $attachmentList->readObjects();
46 // group attachments by object type
47 $groupedAttachments = array();
48 foreach ($attachmentList->getObjects() as $attachment) {
49 if (!isset($groupedAttachments[$attachment->objectTypeID])) $groupedAttachments[$attachment->objectTypeID] = array();
50 $groupedAttachments[$attachment->objectTypeID][] = $attachment;
54 foreach ($groupedAttachments as $objectTypeID => $attachments) {
55 $processor = ObjectTypeCache::getInstance()->getObjectType($objectTypeID)->getProcessor();
56 if ($processor !== null) {
57 $processor->setPermissions($attachments);
61 return $attachmentList->getObjects();