2 namespace wcf\data\attachment
;
3 use wcf\data\
object\type\ObjectTypeCache
;
7 * Represents a list of attachments.
10 * @copyright 2001-2019 WoltLab GmbH
11 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
12 * @package WoltLabSuite\Core\Data\Attachment
14 * @method AdministrativeAttachment current()
15 * @method AdministrativeAttachment[] getObjects()
16 * @method AdministrativeAttachment|null search($objectID)
17 * @property AdministrativeAttachment[] $objects
19 class AdministrativeAttachmentList
extends AttachmentList
{
23 public $decoratorClassName = AdministrativeAttachment
::class;
26 * Creates a new AdministrativeAttachmentList object.
28 public function __construct() {
29 parent
::__construct();
31 $this->sqlSelects
= 'user_table.username';
32 $this->sqlJoins
= " LEFT JOIN wcf".WCF_N
."_user user_table ON (user_table.userID = attachment.userID)";
38 public function readObjects() {
39 parent
::readObjects();
42 $groupedObjectIDs = [];
43 foreach ($this->objects
as $attachment) {
44 if (!isset($groupedObjectIDs[$attachment->objectTypeID
])) $groupedObjectIDs[$attachment->objectTypeID
] = [];
45 $groupedObjectIDs[$attachment->objectTypeID
][] = $attachment->objectID
;
48 foreach ($groupedObjectIDs as $objectTypeID => $objectIDs) {
49 $objectType = ObjectTypeCache
::getInstance()->getObjectType($objectTypeID);
50 $objectType->getProcessor()->cacheObjects($objectIDs);
55 * Returns a list of available mime types.
59 public function getAvailableFileTypes() {
61 $sql = "SELECT DISTINCT attachment.fileType
62 FROM wcf".WCF_N
."_attachment attachment
63 ".$this->getConditionBuilder();
64 $statement = WCF
::getDB()->prepareStatement($sql);
65 $statement->execute($this->getConditionBuilder()->getParameters());
66 while ($row = $statement->fetchArray()) {
67 if ($row['fileType']) {
68 $fileTypes[$row['fileType']] = $row['fileType'];
78 * Returns attachment statistics.
82 public function getStats() {
83 $sql = "SELECT COUNT(*) AS count,
84 COALESCE(SUM(attachment.filesize), 0) AS size,
85 COALESCE(SUM(downloads), 0) AS downloads
86 FROM wcf".WCF_N
."_attachment attachment
87 ".$this->getConditionBuilder();
88 $statement = WCF
::getDB()->prepareStatement($sql);
89 $statement->execute($this->getConditionBuilder()->getParameters());
91 return $statement->fetchArray();