3 namespace wcf\data\attachment
;
5 use wcf\data\
object\type\ObjectTypeCache
;
9 * Represents a list of attachments.
12 * @copyright 2001-2019 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package WoltLabSuite\Core\Data\Attachment
16 * @method AdministrativeAttachment current()
17 * @method AdministrativeAttachment[] getObjects()
18 * @method AdministrativeAttachment|null getSingleObject()
19 * @method AdministrativeAttachment|null search($objectID)
20 * @property AdministrativeAttachment[] $objects
22 class AdministrativeAttachmentList
extends AttachmentList
27 public $decoratorClassName = AdministrativeAttachment
::class;
30 * Creates a new AdministrativeAttachmentList object.
32 public function __construct()
34 parent
::__construct();
36 $this->sqlSelects
= 'user_table.username';
38 LEFT JOIN wcf" . WCF_N
. "_user user_table
39 ON user_table.userID = attachment.userID";
45 public function readObjects()
47 parent
::readObjects();
50 $groupedObjectIDs = [];
51 foreach ($this->objects
as $attachment) {
52 if (!isset($groupedObjectIDs[$attachment->objectTypeID
])) {
53 $groupedObjectIDs[$attachment->objectTypeID
] = [];
55 $groupedObjectIDs[$attachment->objectTypeID
][] = $attachment->objectID
;
58 foreach ($groupedObjectIDs as $objectTypeID => $objectIDs) {
59 $objectType = ObjectTypeCache
::getInstance()->getObjectType($objectTypeID);
60 $objectType->getProcessor()->cacheObjects($objectIDs);
65 * Returns a list of available mime types.
69 public function getAvailableFileTypes()
72 $sql = "SELECT DISTINCT attachment.fileType
73 FROM wcf" . WCF_N
. "_attachment attachment
74 " . $this->getConditionBuilder();
75 $statement = WCF
::getDB()->prepareStatement($sql);
76 $statement->execute($this->getConditionBuilder()->getParameters());
77 while ($row = $statement->fetchArray()) {
78 if ($row['fileType']) {
79 $fileTypes[$row['fileType']] = $row['fileType'];
89 * Returns attachment statistics.
93 public function getStats()
95 $sql = "SELECT COUNT(*) AS count,
96 COALESCE(SUM(attachment.filesize), 0) AS size,
97 COALESCE(SUM(downloads), 0) AS downloads
98 FROM wcf" . WCF_N
. "_attachment attachment
99 " . $this->getConditionBuilder();
100 $statement = WCF
::getDB()->prepareStatement($sql);
101 $statement->execute($this->getConditionBuilder()->getParameters());
103 return $statement->fetchArray();