0c3a354a12445481bb899bcc31caafeece1c0470
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / attachment / AbstractAttachmentObjectType.class.php
1 <?php
2 namespace wcf\system\attachment;
3 use wcf\system\attachment\IAttachmentObjectType;
4 use wcf\system\WCF;
5 use wcf\util\ArrayUtil;
6
7 /**
8 * Provides a default implementation for attachment object types.
9 *
10 * @author Marcel Werk
11 * @copyright 2001-2015 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package com.woltlab.wcf
14 * @subpackage system.attachment
15 * @category Community Framework
16 */
17 abstract class AbstractAttachmentObjectType implements IAttachmentObjectType {
18 /**
19 * cached objects
20 * @var array<\wcf\data\DatabaseObject>
21 */
22 protected $cachedObjects = array();
23
24 /**
25 * @see \wcf\system\attachment\IAttachmentObjectType::getMaxSize()
26 */
27 public function getMaxSize() {
28 return WCF::getSession()->getPermission('user.attachment.maxSize');
29 }
30
31 /**
32 * @see \wcf\system\attachment\IAttachmentObjectType::getAllowedExtensions()
33 */
34 public function getAllowedExtensions() {
35 return ArrayUtil::trim(explode("\n", WCF::getSession()->getPermission('user.attachment.allowedExtensions')));
36 }
37
38 /**
39 * @see \wcf\system\attachment\IAttachmentObjectType::getMaxCount()
40 */
41 public function getMaxCount() {
42 return WCF::getSession()->getPermission('user.attachment.maxCount');
43 }
44
45 /**
46 * @see \wcf\system\attachment\IAttachmentObjectType::canViewPreview()
47 */
48 public function canViewPreview($objectID) {
49 return $this->canDownload($objectID);
50 }
51
52 /**
53 * @see \wcf\system\attachment\IAttachmentObjectType::getObject()
54 */
55 public function getObject($objectID) {
56 if (isset($this->cachedObjects[$objectID])) return $this->cachedObjects[$objectID];
57
58 return null;
59 }
60
61 /**
62 * @see \wcf\system\attachment\IAttachmentObjectType::setCachedObjects()
63 */
64 public function setCachedObjects(array $objects) {
65 foreach ($objects as $id => $object) {
66 $this->cachedObjects[$id] = $object;
67 }
68 }
69
70 /**
71 * @see \wcf\system\attachment\IAttachmentObjectType::getObject()
72 */
73 public function cacheObjects(array $objectIDs) {}
74
75 /**
76 * @see \wcf\system\attachment\IAttachmentObjectType::setPermissions()
77 */
78 public function setPermissions(array $attachments) {
79 foreach ($attachments as $attachment) {
80 $attachment->setPermissions(array(
81 'canDownload' => $this->canDownload($attachment->objectID),
82 'canViewPreview' => $this->canViewPreview($attachment->objectID)
83 ));
84 }
85 }
86 }