79003b5a7bf49648b32effa5a37bf48499dd23d5
[GitHub/WoltLab/WCF.git] /
1 <?php
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;
6
7 /**
8 * IMessageEmbeddedObjectHandler implementation for attachments.
9 *
10 * @author Marcel Werk
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
16 */
17 class AttachmentMessageEmbeddedObjectHandler extends AbstractMessageEmbeddedObjectHandler {
18 /**
19 * @see \wcf\system\message\embedded\object\IMessageEmbeddedObjectHandler::parseMessage()
20 */
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;
27 }
28
29 $attachmentList = new AttachmentList();
30 $attachmentList->getConditionBuilder()->add("attachment.attachmentID IN (?)", array($attachmentIDs));
31 $attachmentList->readObjectIDs();
32 return $attachmentList->getObjectIDs();
33 }
34
35 return false;
36 }
37
38 /**
39 * @see \wcf\system\message\embedded\object\IMessageEmbeddedObjectHandler::loadObjects()
40 */
41 public function loadObjects(array $objectIDs) {
42 $attachmentList = new AttachmentList();
43 $attachmentList->setObjectIDs($objectIDs);
44 $attachmentList->readObjects();
45
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;
51 }
52
53 // check permissions
54 foreach ($groupedAttachments as $objectTypeID => $attachments) {
55 $processor = ObjectTypeCache::getInstance()->getObjectType($objectTypeID)->getProcessor();
56 if ($processor !== null) {
57 $processor->setPermissions($attachments);
58 }
59 }
60
61 return $attachmentList->getObjects();
62 }
63 }