summaryrefslogtreecommitdiffstats
path: root/tests/Stubs/Location.php
blob: 6a513f331e8ae3019ca1b77af9874c0b82c9d7b1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php

class Location
{
	// Configurable stub state
	public static array $rootChains = []; // [locationid => [ancestors...]]
	public static array $assoc = []; // [id => ['children' => [ids...]]]
	public static array $allIds = []; // cache for getAllLocationIds per id
	public static array $tree = []; // for getTree()
	public static array $flat = []; // for getLocations()

	public static function reset(): void
	{
		self::$rootChains = [];
		self::$assoc = [];
		self::$allIds = [];
		self::$tree = [];
		self::$flat = [];
	}

	public static function getLocationRootChain(int $locationid): array
	{
		return self::$rootChains[$locationid] ?? [$locationid];
	}

	public static function getLocationsAssoc(): array
	{
		return self::$assoc;
	}

	public static function getAllLocationIds(int $startId, bool $includeZero = false): array
	{
		if ($startId === 0) {
			$ids = array_keys(self::$assoc);
			if ($includeZero) array_unshift($ids, 0);
			return $ids;
		}
		if (isset(self::$assoc[$startId])) {
			return array_merge([$startId], self::$assoc[$startId]['children'] ?? []);
		}
		return [$startId];
	}

	public static function getTree(): array
	{
		return self::$tree;
	}

	public static function getLocations(int $start, int $depth, bool $includeSublocations, bool $assocOnly): array
	{
		return self::$flat;
	}
}