/**
  * @see	\wcf\data\DatabaseObjectList::readObjects()
  */
 public function readObjects()
 {
     parent::readObjects();
     // group by object id
     foreach ($this->objects as $attachmentID => $attachment) {
         if (!isset($this->groupedObjects[$attachment->objectID])) {
             $this->groupedObjects[$attachment->objectID] = array();
         }
         $this->groupedObjects[$attachment->objectID][$attachmentID] = $attachment;
     }
 }
 /**
  * @see \wcf\system\message\embedded\object\IMessageEmbeddedObjectHandler::parseMessage()
  */
 public function parseMessage($message)
 {
     // yes i know... but what i can do diffrent to the parent class? ;) I am only need xattach... Stupid!
     $return = false;
     $parsedIDs = array_unique(ArrayUtil::toIntegerArray(self::getFirstParameters($message, 'xattach')));
     if (!empty($parsedIDs)) {
         $attachmentIDs = array();
         foreach ($parsedIDs as $attachmentID) {
             if ($attachmentID) {
                 $attachmentIDs[] = $attachmentID;
             }
         }
         if (!empty($attachmentIDs)) {
             $attachmentList = new AttachmentList();
             $attachmentList->getConditionBuilder()->add("attachment.attachmentID IN (?)", array($attachmentIDs));
             $attachmentList->readObjectIDs();
             $return = $attachmentList->getObjectIDs();
         }
     }
     return $return;
 }
 /**
  * @see	\wcf\system\message\embedded\object\IMessageEmbeddedObjectHandler::loadObjects()
  */
 public function loadObjects(array $objectIDs)
 {
     $attachmentList = new AttachmentList();
     $attachmentList->setObjectIDs($objectIDs);
     $attachmentList->readObjects();
     // group attachments by object type
     $groupedAttachments = array();
     foreach ($attachmentList->getObjects() as $attachment) {
         if (!isset($groupedAttachments[$attachment->objectTypeID])) {
             $groupedAttachments[$attachment->objectTypeID] = array();
         }
         $groupedAttachments[$attachment->objectTypeID][] = $attachment;
     }
     // check permissions
     foreach ($groupedAttachments as $objectTypeID => $attachments) {
         $processor = ObjectTypeCache::getInstance()->getObjectType($objectTypeID)->getProcessor();
         if ($processor !== null) {
             $processor->setPermissions($attachments);
         }
     }
     return $attachmentList->getObjects();
 }
 /**
  * @see	\wcf\data\DatabaseObjectList::readObjects()
  */
 public function readObjects()
 {
     parent::readObjects();
     // cache objects
     $groupedObjectIDs = array();
     foreach ($this->objects as $attachment) {
         if (!isset($groupedObjectIDs[$attachment->objectTypeID])) {
             $groupedObjectIDs[$attachment->objectTypeID] = array();
         }
         $groupedObjectIDs[$attachment->objectTypeID][] = $attachment->objectID;
     }
     foreach ($groupedObjectIDs as $objectTypeID => $objectIDs) {
         $objectType = ObjectTypeCache::getInstance()->getObjectType($objectTypeID);
         $objectType->getProcessor()->cacheObjects($objectIDs);
     }
 }
 /**
  * Removes all attachments for given object ids by type.
  * 
  * @param	string		$objectType
  * @param	array<integer>	$objectIDs
  */
 public static function removeAttachments($objectType, array $objectIDs)
 {
     $attachmentList = new AttachmentList();
     $attachmentList->getConditionBuilder()->add("objectTypeID = ?", array(ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.attachment.objectType', $objectType)->objectTypeID));
     $attachmentList->getConditionBuilder()->add("objectID IN (?)", array($objectIDs));
     $attachmentList->readObjects();
     if (count($attachmentList)) {
         $attachmentAction = new AttachmentAction($attachmentList->getObjects(), 'delete');
         $attachmentAction->executeAction();
     }
 }
 /**
  * Copies attachments from one object id to another.
  */
 public function copy()
 {
     $sourceObjectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.attachment.objectType', $this->parameters['sourceObjectType']);
     $targetObjectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.attachment.objectType', $this->parameters['targetObjectType']);
     $attachmentList = new AttachmentList();
     $attachmentList->getConditionBuilder()->add("attachment.objectTypeID = ?", array($sourceObjectType->objectTypeID));
     $attachmentList->getConditionBuilder()->add("attachment.objectID = ?", array($this->parameters['sourceObjectID']));
     $attachmentList->readObjects();
     $newAttachmentIDs = array();
     foreach ($attachmentList as $attachment) {
         $newAttachment = AttachmentEditor::create(array('objectTypeID' => $targetObjectType->objectTypeID, 'objectID' => $this->parameters['targetObjectID'], 'userID' => $attachment->userID, 'filename' => $attachment->filename, 'filesize' => $attachment->filesize, 'fileType' => $attachment->fileType, 'fileHash' => $attachment->fileHash, 'isImage' => $attachment->isImage, 'width' => $attachment->width, 'height' => $attachment->height, 'tinyThumbnailType' => $attachment->tinyThumbnailType, 'tinyThumbnailSize' => $attachment->tinyThumbnailSize, 'tinyThumbnailWidth' => $attachment->tinyThumbnailWidth, 'tinyThumbnailHeight' => $attachment->tinyThumbnailHeight, 'thumbnailType' => $attachment->thumbnailType, 'thumbnailSize' => $attachment->thumbnailSize, 'thumbnailWidth' => $attachment->thumbnailWidth, 'thumbnailHeight' => $attachment->thumbnailHeight, 'downloads' => $attachment->downloads, 'lastDownloadTime' => $attachment->lastDownloadTime, 'uploadTime' => $attachment->uploadTime, 'showOrder' => $attachment->showOrder));
         // copy attachment
         @copy($attachment->getLocation(), $newAttachment->getLocation());
         if ($attachment->tinyThumbnailSize) {
             @copy($attachment->getTinyThumbnailLocation(), $newAttachment->getTinyThumbnailLocation());
         }
         if ($attachment->thumbnailSize) {
             @copy($attachment->getThumbnailLocation(), $newAttachment->getThumbnailLocation());
         }
         $newAttachmentIDs[$attachment->attachmentID] = $newAttachment->attachmentID;
     }
     return array('attachmentIDs' => $newAttachmentIDs);
 }