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';
36 $this->sqlJoins
= " LEFT JOIN wcf" . WCF_N
. "_user user_table ON (user_table.userID = attachment.userID)";
42 public function readObjects()
44 parent
::readObjects();
47 $groupedObjectIDs = [];
48 foreach ($this->objects
as $attachment) {
49 if (!isset($groupedObjectIDs[$attachment->objectTypeID
])) {
50 $groupedObjectIDs[$attachment->objectTypeID
] = [];
52 $groupedObjectIDs[$attachment->objectTypeID
][] = $attachment->objectID
;
55 foreach ($groupedObjectIDs as $objectTypeID => $objectIDs) {
56 $objectType = ObjectTypeCache
::getInstance()->getObjectType($objectTypeID);
57 $objectType->getProcessor()->cacheObjects($objectIDs);
62 * Returns a list of available mime types.
66 public function getAvailableFileTypes()
69 $sql = "SELECT DISTINCT attachment.fileType
70 FROM wcf" . WCF_N
. "_attachment attachment
71 " . $this->getConditionBuilder();
72 $statement = WCF
::getDB()->prepareStatement($sql);
73 $statement->execute($this->getConditionBuilder()->getParameters());
74 while ($row = $statement->fetchArray()) {
75 if ($row['fileType']) {
76 $fileTypes[$row['fileType']] = $row['fileType'];
86 * Returns attachment statistics.
90 public function getStats()
92 $sql = "SELECT COUNT(*) AS count,
93 COALESCE(SUM(attachment.filesize), 0) AS size,
94 COALESCE(SUM(downloads), 0) AS downloads
95 FROM wcf" . WCF_N
. "_attachment attachment
96 " . $this->getConditionBuilder();
97 $statement = WCF
::getDB()->prepareStatement($sql);
98 $statement->execute($this->getConditionBuilder()->getParameters());
100 return $statement->fetchArray();