Fix typo in method documentation
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / data / attachment / AdministrativeAttachmentList.class.php
1 <?php
2
3 namespace wcf\data\attachment;
4
5 use wcf\data\object\type\ObjectTypeCache;
6 use wcf\system\WCF;
7
8 /**
9 * Represents a list of attachments.
10 *
11 * @author Marcel Werk
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
15 *
16 * @method AdministrativeAttachment current()
17 * @method AdministrativeAttachment[] getObjects()
18 * @method AdministrativeAttachment|null getSingleObject()
19 * @method AdministrativeAttachment|null search($objectID)
20 * @property AdministrativeAttachment[] $objects
21 */
22 class AdministrativeAttachmentList extends AttachmentList
23 {
24 /**
25 * @inheritDoc
26 */
27 public $decoratorClassName = AdministrativeAttachment::class;
28
29 /**
30 * Creates a new AdministrativeAttachmentList object.
31 */
32 public function __construct()
33 {
34 parent::__construct();
35
36 $this->sqlSelects = 'user_table.username';
37 $this->sqlJoins = "
38 LEFT JOIN wcf" . WCF_N . "_user user_table
39 ON user_table.userID = attachment.userID";
40 }
41
42 /**
43 * @inheritDoc
44 */
45 public function readObjects()
46 {
47 parent::readObjects();
48
49 // cache objects
50 $groupedObjectIDs = [];
51 foreach ($this->objects as $attachment) {
52 if (!isset($groupedObjectIDs[$attachment->objectTypeID])) {
53 $groupedObjectIDs[$attachment->objectTypeID] = [];
54 }
55 $groupedObjectIDs[$attachment->objectTypeID][] = $attachment->objectID;
56 }
57
58 foreach ($groupedObjectIDs as $objectTypeID => $objectIDs) {
59 $objectType = ObjectTypeCache::getInstance()->getObjectType($objectTypeID);
60 $objectType->getProcessor()->cacheObjects($objectIDs);
61 }
62 }
63
64 /**
65 * Returns a list of available mime types.
66 *
67 * @return string[]
68 */
69 public function getAvailableFileTypes()
70 {
71 $fileTypes = [];
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'];
80 }
81 }
82
83 \ksort($fileTypes);
84
85 return $fileTypes;
86 }
87
88 /**
89 * Returns attachment statistics.
90 *
91 * @return int[]
92 */
93 public function getStats()
94 {
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());
102
103 return $statement->fetchArray();
104 }
105 }