FROM wcf".WCF_N."_style_variable";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute();
- while ($row = $statement->fetchArray()) {
- $this->variables[$row['variableName']] = $row['defaultValue'];
- }
+ $this->variables = $statement->fetchMap('variableName', 'defaultValue');
}
/**
".$conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
-
- $groups = [];
- while ($row = $statement->fetchArray()) {
- $groups[$row['userID']][] = $row['groupID'];
- }
+ $groups = $statement->fetchMap('userID', 'groupID', false);
foreach ($this->users as $user) {
if (!UserGroup::isAccessibleGroup($groups[$user->userID])) {
".$conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
- while ($row = $statement->fetchArray()) {
- $this->values[$row['groupID']] = $row['optionValue'];
- }
+ $this->values = $statement->fetchMap('groupID', 'optionValue');
}
// create form elements for each group
// get user data
if (!empty($userIDs)) {
- $userToGroups = [];
-
// get group ids
$conditions = new PreparedStatementConditionBuilder();
$conditions->add("user_table.userID IN (?)", [$userIDs]);
".$conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
- while ($row = $statement->fetchArray()) {
- $userToGroups[$row['userID']][] = $row['groupID'];
- }
+ $userToGroups = $statement->fetchMap('userID', 'groupID', false);
$sql = "SELECT user_avatar.*, option_value.*, user_table.*
FROM wcf".WCF_N."_user user_table
}
// get objects type ids
- $responses = [];
$conditionBuilder = new PreparedStatementConditionBuilder();
$conditionBuilder->add('comment_response.responseID IN (?)', [$responseIDs]);
$sql = "SELECT comment.objectTypeID, comment_response.responseID
".$conditionBuilder;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditionBuilder->getParameters());
- while ($row = $statement->fetchArray()) {
- $responses[$row['responseID']] = $row['objectTypeID'];
- }
+ $responses = $statement->fetchMap('responseID', 'objectTypeID');
// group likes by object type id
$likeData = [];
FROM wcf".WCF_N."_option";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute();
- $optionIDs = [];
- while ($row = $statement->fetchArray()) {
- $optionIDs[$row['optionName']] = $row['optionID'];
- }
+ $optionIDs = $statement->fetchMap('optionName', 'optionID');
$newOptions = [];
foreach ($options as $name => $value) {
FROM wcf".WCF_N."_package";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute();
- $installedPackages = [];
- while ($row = $statement->fetchArray()) {
- $installedPackages[$row['package']] = $row['packageVersion'];
- }
+ $installedPackages = $statement->fetchMap('package', 'packageVersion');
// filter by version
$conditions = new PreparedStatementConditionBuilder();
WHERE pollID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute([$this->poll->pollID]);
- $voteData = [];
- while ($row = $statement->fetchArray()) {
- if (!isset($voteData[$row['optionID']])) {
- $voteData[$row['optionID']] = [];
- }
-
- $voteData[$row['optionID']][] = $row['userID'];
- }
+ $voteData = $statement->fetchMap('optionID', 'userID', false);
// assign user ids
foreach ($voteData as $optionID => $userIDs) {
WHERE language_item.languageItem = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute([$this->styleDescription]);
- $styleDescriptions = [];
- while ($row = $statement->fetchArray()) {
- $styleDescriptions[$row['languageCode']] = $row['languageItemValue'];
- }
+ $styleDescriptions = $statement->fetchMap('languageCode', 'languageItemValue');
// create style info file
$xml = new XMLWriter();
public function getGroupOption($name) {
if ($this->groupOptions === null) {
// get all options and filter options with low priority
- $this->groupOptions = $groupOptionIDs = [];
+ $this->groupOptions = [];
$sql = "SELECT optionName, optionID
FROM wcf".WCF_N."_user_group_option";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute();
-
- while ($row = $statement->fetchArray()) {
- $groupOptionIDs[$row['optionName']] = $row['optionID'];
- }
+ $groupOptionIDs = $statement->fetchMap('optionName', 'optionID');
if (!empty($groupOptionIDs)) {
$conditions = new PreparedStatementConditionBuilder();
".$conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
- while ($row = $statement->fetchArray()) {
- $this->groupOptions[$row['optionName']] = $row['optionValue'];
- }
+ $this->groupOptions = $statement->fetchMap('optionName', 'optionValue');
}
}
$statement->execute();
}
- $optionValues = [];
- while ($row = $statement->fetchArray()) {
- $optionValues[$row['optionID']] = $row['optionValue'];
- }
+ $optionValues = $statement->fetchMap('optionID', 'optionValue');
$groupAction = new UserGroupAction([], 'create', [
'data' => [
FROM wcf".WCF_N."_package_installation_queue";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute();
- $queues = [];
- while ($row = $statement->fetchArray()) {
- $queues[$row['queueID']] = $row['parentQueueID'];
- }
+ $queues = $statement->fetchMap('queueID', 'parentQueueID');
$queueIDs = [];
/** @noinspection PhpUndefinedVariableInspection */
".$conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
-
- while ($row = $statement->fetchArray()) {
- $data['user']['label'][$row['userID']] = $row['username'];
- }
+ $data['user']['label'] = $statement->fetchMap('userID', 'username');
}
}
}
".$conditionBuilder;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditionBuilder->getParameters());
-
- $groupIDs = [];
- while ($row = $statement->fetchArray()) {
- if (!isset($groupIDs[$row['userID']])) {
- $groupIDs[$row['userID']] = [];
- }
-
- $groupIDs[$row['userID']][] = $row['groupID'];
- }
+ $groupIDs = $statement->fetchMap('userID', 'groupID', false);
$users = [];
foreach ($userList as $user) {
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute();
- $data = [];
- while ($row = $statement->fetchArray()) {
- if (!isset($data[$row['pageClassName']])) {
- $data[$row['pageClassName']] = [];
- }
-
- $data[$row['pageClassName']][] = $row['actionID'];
- }
-
- return $data;
+ return $statement->fetchMap('pageClassName', 'actionID', false);
}
}
if (!empty($this->objectTypeIDs)) {
// get tag ids
- $tagIDs = [];
$conditionBuilder = new PreparedStatementConditionBuilder();
$conditionBuilder->add('object.objectTypeID IN (?)', [$this->objectTypeIDs]);
$conditionBuilder->add('object.languageID IN (?)', [$this->languageIDs]);
ORDER BY counter DESC";
$statement = WCF::getDB()->prepareStatement($sql, 500);
$statement->execute($conditionBuilder->getParameters());
- while ($row = $statement->fetchArray()) {
- $tagIDs[$row['tagID']] = $row['counter'];
- }
+ $tagIDs = $statement->fetchMap('tagID', 'counter');
// get tags
if (!empty($tagIDs)) {
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
- $userToGroup = [];
- while ($row = $statement->fetchArray()) {
- if (!isset($userToGroup[$row['userID']])) {
- $userToGroup[$row['userID']] = [];
- }
-
- $userToGroup[$row['userID']][] = $row['groupID'];
- }
+ $userToGroup = $statement->fetchMap('userID', 'groupID', false);
// validate if user's group is accessible for current user
foreach ($userIDs as $userID) {
return $objects;
}
+ /**
+ * Returns a map of all fetched rows using one column as key and another column as value.
+ *
+ * @param string $keyColumn name of the key column
+ * @param string $valueColumn name of the value column
+ * @param boolean $uniqueKey if `true`, a one-dimensional array is returned, otherwise, for each key an array of fetched values is returned
+ * @return string[]|string[][]
+ */
+ public function fetchMap($keyColumn, $valueColumn, $uniqueKey = true) {
+ $map = [];
+
+ while (($row = $this->fetchArray())) {
+ $key = $row[$keyColumn];
+ $value = $row[$valueColumn];
+
+ if ($uniqueKey) {
+ $map[$key] = $value;
+ }
+ else {
+ if (!isset($map[$key])) {
+ $map[$key] = [];
+ }
+
+ $map[$key][] = $value;
+ }
+ }
+
+ return $map;
+ }
+
/**
* Counts number of affected rows by the last sql statement (INSERT, UPDATE or DELETE).
*
".$conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
-
- $users = [];
- while ($row = $statement->fetchArray()) {
- $users[$row['userID']] = $row['username'];
- }
+ $users = $statement->fetchMap('userID', 'username');
// sort usernames with the longest one being first
uasort($users, function($a, $b) {
WHERE objectTypeID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute([$this->objectTypeID]);
- while ($row = $statement->fetchArray()) {
- $this->options[$row['optionName']] = $row['optionID'];
- }
+ $this->options = $statement->fetchMap('optionName', 'optionID');
}
/**
".$conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
-
- $labels = [];
- while ($row = $statement->fetchArray()) {
- if (!isset($labels[$row['labelID']])) {
- $labels[$row['labelID']] = [];
- }
-
- $labels[$row['labelID']][] = $row['objectID'];
- }
+ $labels = $statement->fetchMap('labelID', 'objectID', false);
// optionally filter out labels without permissions
if ($validatePermissions) {
".$conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
- $languageItemIDs = [];
- while ($row = $statement->fetchArray()) {
- $languageItemIDs[$row['languageID']] = $row['languageItemID'];
- }
+ $languageItemIDs = $statement->fetchMap('languageID', 'languageItemID');
$insertLanguageIDs = $updateLanguageIDs = [];
foreach ($languageIDs as $languageID) {
".$conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
-
- $lockedFiles = [];
- while ($row = $statement->fetchArray()) {
- $lockedFiles[$row['templateName']] = $row['packageID'];
- }
+ $lockedFiles = $statement->fetchMap('templateName', 'packageID');
// check if acp templates from the package beeing
// installed are in conflict with already installed
".$conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
- $lockedFiles = [];
- while ($row = $statement->fetchArray()) {
- $lockedFiles[$row['filename']] = $row['packageID'];
- }
+ $lockedFiles = $statement->fetchMap('filename', 'packageID');
// check delivered files
if (!empty($lockedFiles)) {
AND sqlIndex = ''";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute();
- while ($row = $statement->fetchArray()) {
- $this->knownTables[$row['sqlTable']] = $row['packageID'];
- }
+ $this->knownTables = $statement->fetchMap('sqlTable', 'packageID');
}
/**
unset($file);
// get existing templates
- $existingTemplates = $updateTemplateIDs = [];
+ $updateTemplateIDs = [];
$sql = "SELECT templateName, templateID
FROM wcf".WCF_N."_template
WHERE packageID = ?
AND templateGroupID IS NULL";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute([$packageID, $this->application]);
- while ($row = $statement->fetchArray()) {
- $existingTemplates[$row['templateName']] = $row['templateID'];
- }
+ $existingTemplates = $statement->fetchMap('templateName', 'templateID');
// save new templates
$sql = "INSERT INTO wcf".WCF_N."_template
WHERE packageID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute([$this->installation->getPackageID()]);
-
- $files = [];
- while ($row = $statement->fetchArray()) {
- if (!isset($files[$row['application']])) {
- $files[$row['application']] = [];
- }
-
- $files[$row['application']][] = $row['filename'];
- }
+ $files = $statement->fetchMap('application', 'filename', false);
foreach ($files as $application => $filenames) {
/** @noinspection PhpUndefinedMethodInspection */
ORDER BY languageItemValue ASC";
$statement = WCF::getDB()->prepareStatement($sql); // don't use a limit here
$statement->execute($conditions->getParameters());
- $languageItems = [];
- while ($row = $statement->fetchArray()) {
- $languageItems[$row['languageItem']] = $row['languageItemValue'];
- }
+ $languageItems = $statement->fetchMap('languageItem', 'languageItemValue');
if (empty($languageItems)) {
return [];
".$conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
- $notifications = [];
- while ($row = $statement->fetchArray()) {
- $notifications[$row['userID']] = $row['notificationID'];
- }
+ $notifications = $statement->fetchMap('userID', 'notificationID');
// check if event supports stacking and author should be added
if (!empty($notifications) && $event->isStackable()) {
// cache does not exist or is outdated
if ($data === null) {
- $this->userVisits = [];
$sql = "SELECT objectTypeID, visitTime
FROM wcf".WCF_N."_tracked_visit_type
WHERE userID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute([WCF::getUser()->userID]);
- while ($row = $statement->fetchArray()) {
- $this->userVisits[$row['objectTypeID']] = $row['visitTime'];
- }
+ $this->userVisits = $statement->fetchMap('objectTypeID', 'visitTime');
// update storage data
UserStorageHandler::getInstance()->update(WCF::getUser()->userID, 'trackedUserVisits', serialize($this->userVisits));
".$conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
- $cumulativeLikes = [];
-
- /** @noinspection PhpAssignmentInConditionInspection */
- while ($row = $statement->fetchArray()) {
- $cumulativeLikes[$row['objectID']] = $row['cumulativeLikes'];
- }
+ $cumulativeLikes = $statement->fetchMap('objectID', 'cumulativeLikes');
foreach ($this->objectList as $article) {
$editor = new ArticleEditor($article);
".$conditions;
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
- $usernames = [];
- while ($row = $statement->fetchArray()) {
- $usernames[$row['userID']] = $row['username'];
- }
+ $usernames = $statement->fetchMap('userID', 'username');
// update like objects
$sql = "UPDATE wcf".WCF_N."_like_object