".$conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
- $updateVersions = [];
- while ($updateVersion = $statement->fetchObject(PackageUpdateVersion::class)) {
- $updateVersions[$updateVersion->packageUpdateVersionID] = $updateVersion;
- }
+
+ /** @var PackageUpdateVersion[] $updateVersions */
+ $updateVersions = $statement->fetchObjects(PackageUpdateVersion::class, 'packageUpdateVersionID');
// assign versions
foreach ($packageUpdates as $packageUpdateID => $packageUpdate) {
/**
* Fetches the all rows from a result set into database objects.
*
- * @param string $className
+ * @param string $className
+ * @param string|null $keyProperty
* @return DatabaseObject[]
*/
- public function fetchObjects($className) {
+ public function fetchObjects($className, $keyProperty = null) {
$objects = [];
while ($object = $this->fetchObject($className)) {
- $objects[] = $object;
+ if ($keyProperty === null) {
+ $objects[] = $object;
+ }
+ else {
+ $objects[$object->$keyProperty] = $object;
+ }
}
return $objects;
".$conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
- $boxes = [];
- /** @var Box $box */
- while ($box = $statement->fetchObject(Box::class)) {
- $boxes[$box->identifier] = $box;
- }
+ /** @var Box[] $boxes */
+ $boxes = $statement->fetchObjects(Box::class, 'identifier');
// save visibility exceptions
$sql = "DELETE FROM wcf".WCF_N."_box_to_page
".$conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
- $boxes = [];
- /** @var Box $box */
- while ($box = $statement->fetchObject(Box::class)) {
- $boxes[$box->identifier] = $box;
- }
+ /** @var Box[] $boxes */
+ $boxes = $statement->fetchObjects(Box::class, 'identifier');
// fetch all menus relevant
$menuList = new MenuList();
$statement = WCF::getDB()->prepareStatement($sql, $limit, $offset);
$statement->execute($conditions->getParameters());
- $notifications = [];
- while ($notification = $statement->fetchObject(UserNotification::class)) {
- $notifications[$notification->notificationID] = $notification;
- }
-
- return $notifications;
+ return $statement->fetchObjects(UserNotification::class, 'notificationID');
}
/**