Drop `@package` tag in *.php
[GitHub/WoltLab/com.woltlab.wcf.conversation.git] / files / lib / data / modification / log / ConversationLogModificationLogList.class.php
1 <?php
2
3 namespace wcf\data\modification\log;
4
5 use wcf\system\cache\runtime\UserProfileRuntimeCache;
6 use wcf\system\log\modification\ConversationModificationLogHandler;
7 use wcf\system\WCF;
8
9 /**
10 * Represents a list of modification logs for conversation log page.
11 *
12 * @author Alexander Ebert
13 * @copyright 2001-2019 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 *
16 * @method ViewableConversationModificationLog current()
17 * @method ViewableConversationModificationLog[] getObjects()
18 * @method ViewableConversationModificationLog|null getSingleObject()
19 * @method ViewableConversationModificationLog|null search($objectID)
20 * @property ViewableConversationModificationLog[] $objects
21 */
22 class ConversationLogModificationLogList extends ModificationLogList
23 {
24 /**
25 * @inheritDoc
26 */
27 public function __construct($conversationID)
28 {
29 parent::__construct();
30
31 // set conditions
32 $this->getConditionBuilder()->add(
33 'modification_log.objectTypeID = ?',
34 [ConversationModificationLogHandler::getInstance()->getObjectType('com.woltlab.wcf.conversation.conversation')->objectTypeID]
35 );
36 $this->getConditionBuilder()->add(
37 'modification_log.objectID = ?',
38 [$conversationID]
39 );
40 }
41
42 /**
43 * @inheritDoc
44 */
45 public function readObjects()
46 {
47 $sql = "SELECT modification_log.*
48 FROM wcf" . WCF_N . "_modification_log modification_log
49 " . $this->getConditionBuilder() . "
50 " . (!empty($this->sqlOrderBy) ? "ORDER BY " . $this->sqlOrderBy : '');
51 $statement = WCF::getDB()->prepareStatement($sql, $this->sqlLimit, $this->sqlOffset);
52 $statement->execute($this->getConditionBuilder()->getParameters());
53 $this->objects = $statement->fetchObjects(($this->objectClassName ?: $this->className));
54
55 // use table index as array index
56 $objects = $userIDs = [];
57 foreach ($this->objects as $object) {
58 $objectID = $object->{$this->getDatabaseTableIndexName()};
59 $objects[$objectID] = $object;
60
61 $this->indexToObject[] = $objectID;
62
63 if ($object->userID) {
64 $userIDs[] = $object->userID;
65 }
66 }
67 $this->objectIDs = $this->indexToObject;
68 $this->objects = $objects;
69
70 if (!empty($userIDs)) {
71 UserProfileRuntimeCache::getInstance()->cacheObjectIDs($userIDs);
72 }
73
74 foreach ($this->objects as &$object) {
75 $object = new ViewableConversationModificationLog($object);
76 }
77 unset($object);
78 }
79
80 /**
81 * Returns all log entries created before given point of time. Applicable entries
82 * will be returned and removed from collection.
83 *
84 * @param int $time
85 * @return ViewableConversationModificationLog[]
86 */
87 public function getEntriesUntil($time)
88 {
89 $entries = [];
90 foreach ($this->objects as $index => $entry) {
91 if ($entry->time < $time) {
92 $entries[] = $entry;
93 unset($this->objects[$index]);
94 }
95 }
96
97 if (!empty($entries)) {
98 $this->indexToObject = \array_keys($this->objects);
99 }
100
101 return $entries;
102 }
103 }