|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace wcf\system\event\listener; |
| 4 | + |
| 5 | +use wcf\data\wsdb\database\DatabaseList; |
| 6 | +use wcf\data\wsdb\record\connection\RecordConnectionList; |
| 7 | +use wcf\page\WsdbRecordPage; |
| 8 | +use wcf\system\WCF; |
| 9 | + |
| 10 | +final class ConnectionWsdbRecordPageListener extends AbstractEventListener |
| 11 | +{ |
| 12 | + protected function onAssignVariables(WsdbRecordPage $eventObj): void |
| 13 | + { |
| 14 | + if (!$eventObj->getDatabase()->enableConnection) { |
| 15 | + return; |
| 16 | + } |
| 17 | + |
| 18 | + $connectionList = new RecordConnectionList(); |
| 19 | + $connectionList->getConditionBuilder()->add('recordID = ?', [$eventObj->getRecord()->recordID]); |
| 20 | + $connectionList->sqlSelects .= "( |
| 21 | + SELECT title |
| 22 | + FROM wcf1_wsdb_record_content |
| 23 | + WHERE recordID = wsdb_record_connection.referencedRecordID |
| 24 | + AND ( |
| 25 | + languageID IS NULL |
| 26 | + OR languageID = " . WCF::getLanguage()->languageID . " |
| 27 | + ) |
| 28 | + LIMIT 1 |
| 29 | + ) AS title"; |
| 30 | + $connectionList->sqlOrderBy = 'title ASC'; |
| 31 | + $connectionList->readObjects(); |
| 32 | + |
| 33 | + $groupedConnections = []; |
| 34 | + foreach ($connectionList as $connection) { |
| 35 | + $record = $connection->getReferencedRecord(); |
| 36 | + if (!$record->canRead()) { |
| 37 | + continue; |
| 38 | + } |
| 39 | + $groupedConnections[$connection->referencedDatabaseID][] = $record; |
| 40 | + } |
| 41 | + |
| 42 | + $databaseList = new DatabaseList(); |
| 43 | + $databaseList->readObjects(); |
| 44 | + |
| 45 | + WCF::getTPL()->assign([ |
| 46 | + 'groupedConnections' => $groupedConnections, |
| 47 | + 'connectionDatabases' => $databaseList->getObjects(), |
| 48 | + ]); |
| 49 | + } |
| 50 | +} |
0 commit comments