関数
GroupItem::reorderGroupItems( int $groupId, int[] $itemIds )
パラメータ パラメータ
- $groupId
(数値) (必須)
- $itemIds
(int[]) (必須)
true
if anything was reordered, false
otherwiseファイル: src/API/GroupItem.php
public static function reorderGroupItems($groupId, $itemIds) { global $wpdb; $groupId = (int)$groupId; $itemIds = !empty($itemIds) ? (array)$itemIds : []; $updated = false; $wpdb->query('START TRANSACTION'); foreach ($itemIds as $position => $itemId) { $item = self::getGroupItemById($itemId); if ($item === null || $item->getGroupId() !== $groupId || $item->getPosition() === $position) { continue; } $updated = true; $res = $wpdb->update( Schema::getComboSetGroupItemsTable(), [ 'position' => $position, 'updated_at' => Utils::getCurrentUTCDateTimeString(), ], [ 'group_id' => $groupId, 'id' => $itemId, ], ['%d', '%s'], ['%d', '%d'] ); if ($res === false) { $wpdb->query('ROLLBACK'); return Master::getErrorStore()->getErrorResponse(ErrorStore::INTERNAL_SERVER_ERROR); } } $wpdb->query('COMMIT'); return $updated; }