Add the new variable `FileProcessorFormField::$bigPreview` with getter and setter.
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / data / ad / AdEditor.class.php
1 <?php
2
3 namespace wcf\data\ad;
4
5 use wcf\data\DatabaseObjectEditor;
6 use wcf\data\IEditableCachedObject;
7 use wcf\data\object\type\ObjectTypeCache;
8 use wcf\system\cache\builder\AdCacheBuilder;
9 use wcf\system\cache\builder\ConditionCacheBuilder;
10 use wcf\system\WCF;
11
12 /**
13 * Provides functions to edit ads.
14 *
15 * @author Matthias Schmidt
16 * @copyright 2001-2019 WoltLab GmbH
17 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
18 *
19 * @method static Ad create(array $parameters = [])
20 * @method Ad getDecoratedObject()
21 * @mixin Ad
22 */
23 class AdEditor extends DatabaseObjectEditor implements IEditableCachedObject
24 {
25 /**
26 * @inheritDoc
27 */
28 protected static $baseClass = Ad::class;
29
30 /**
31 * Sets the show order of the ad.
32 *
33 * @param int $showOrder
34 */
35 public function setShowOrder($showOrder = 0)
36 {
37 $sql = "SELECT MAX(showOrder)
38 FROM wcf" . WCF_N . "_ad
39 WHERE objectTypeID = ?";
40 $statement = WCF::getDB()->prepareStatement($sql);
41 $statement->execute([
42 $this->objectTypeID,
43 ]);
44 $maxShowOrder = $statement->fetchSingleColumn();
45 if (!$maxShowOrder) {
46 $maxShowOrder = 0;
47 }
48
49 if (!$showOrder || $showOrder > $maxShowOrder) {
50 $newShowOrder = $maxShowOrder + 1;
51 } else {
52 // shift other ads
53 $sql = "UPDATE wcf" . WCF_N . "_ad
54 SET showOrder = showOrder + 1
55 WHERE objectTypeID = ?
56 AND showOrder >= ?";
57 $statement = WCF::getDB()->prepareStatement($sql);
58 $statement->execute([
59 $this->objectTypeID,
60 $showOrder,
61 ]);
62
63 $newShowOrder = $showOrder;
64 }
65
66 $this->update([
67 'showOrder' => $newShowOrder,
68 ]);
69 }
70
71 /**
72 * @inheritDoc
73 */
74 public static function resetCache()
75 {
76 AdCacheBuilder::getInstance()->reset();
77 ConditionCacheBuilder::getInstance()->reset([
78 'definitionID' => ObjectTypeCache::getInstance()
79 ->getDefinitionByName('com.woltlab.wcf.condition.ad')
80 ->definitionID,
81 ]);
82 }
83 }