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 search($objectID)
19 * @property AdministrativeAttachment[] $objects
21 class AdministrativeAttachmentList
extends AttachmentList
26 public $decoratorClassName = AdministrativeAttachment
::class;
29 * Creates a new AdministrativeAttachmentList object.
31 public function __construct()
33 parent
::__construct();
35 $this->sqlSelects
= 'user_table.username';
37 LEFT JOIN wcf" . WCF_N
. "_user user_table
38 ON user_table.userID = attachment.userID";
44 public function readObjects()
46 parent
::readObjects();
49 $groupedObjectIDs = [];
50 foreach ($this->objects
as $attachment) {
51 if (!isset($groupedObjectIDs[$attachment->objectTypeID
])) {
52 $groupedObjectIDs[$attachment->objectTypeID
] = [];
54 $groupedObjectIDs[$attachment->objectTypeID
][] = $attachment->objectID
;
57 foreach ($groupedObjectIDs as $objectTypeID => $objectIDs) {
58 $objectType = ObjectTypeCache
::getInstance()->getObjectType($objectTypeID);
59 $objectType->getProcessor()->cacheObjects($objectIDs);
64 * Returns a list of available mime types.
68 public function getAvailableFileTypes()
71 $sql = "SELECT DISTINCT attachment.fileType
72 FROM wcf" . WCF_N
. "_attachment attachment
73 " . $this->getConditionBuilder();
74 $statement = WCF
::getDB()->prepareStatement($sql);
75 $statement->execute($this->getConditionBuilder()->getParameters());
76 while ($row = $statement->fetchArray()) {
77 if ($row['fileType']) {
78 $fileTypes[$row['fileType']] = $row['fileType'];
88 * Returns attachment statistics.
92 public function getStats()
94 $sql = "SELECT COUNT(*) AS count,
95 COALESCE(SUM(attachment.filesize), 0) AS size,
96 COALESCE(SUM(downloads), 0) AS downloads
97 FROM wcf" . WCF_N
. "_attachment attachment
98 " . $this->getConditionBuilder();
99 $statement = WCF
::getDB()->prepareStatement($sql);
100 $statement->execute($this->getConditionBuilder()->getParameters());
102 return $statement->fetchArray();