tablepress
/
libraries
/
vendor
/
PhpSpreadsheet
/
Worksheet
/
PivotTable
/
PivotCacheDefinition.php
PivotCacheDefinition.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Worksheet/PivotTable/PivotCacheDefinition.php
| 1 | <?php |
| 2 | |
| 3 | namespace TablePress\PhpOffice\PhpSpreadsheet\Worksheet\PivotTable; |
| 4 | |
| 5 | /** |
| 6 | * Read-only representation of a pivot cache definition. |
| 7 | * |
| 8 | * The pivot cache describes where a pivot table's data comes from (the source |
| 9 | * worksheet and range) and the list of fields available from that source. A |
| 10 | * single cache can be shared by more than one pivot table. |
| 11 | * |
| 12 | * @see PivotTable |
| 13 | */ |
| 14 | class PivotCacheDefinition |
| 15 | { |
| 16 | /** |
| 17 | * The cache id, as registered in the workbook <pivotCaches> element. |
| 18 | */ |
| 19 | private ?int $cacheId; |
| 20 | |
| 21 | /** |
| 22 | * Name of the worksheet the source data lives on (worksheet source only). |
| 23 | */ |
| 24 | private ?string $sourceWorksheet = null; |
| 25 | |
| 26 | /** |
| 27 | * Source data range on that worksheet, e.g. "A1:D50" (worksheet source only). |
| 28 | */ |
| 29 | private ?string $sourceRange = null; |
| 30 | |
| 31 | /** |
| 32 | * Names of the cache fields, in declaration order. The index into this |
| 33 | * array is the field index referenced by the pivot table. |
| 34 | * |
| 35 | * @var string[] |
| 36 | */ |
| 37 | private array $cacheFields = []; |
| 38 | |
| 39 | /** |
| 40 | * Distinct values ("shared items") per field name, used when generating a |
| 41 | * cache definition for a newly created pivot table. |
| 42 | * |
| 43 | * @var array<string, string[]> |
| 44 | */ |
| 45 | private array $sharedItems = []; |
| 46 | |
| 47 | /** |
| 48 | * Grouping configuration per field name, when a field is grouped. |
| 49 | * |
| 50 | * @var array<string, PivotFieldGroup> |
| 51 | */ |
| 52 | private array $fieldGroups = []; |
| 53 | |
| 54 | public function __construct(?int $cacheId = null) |
| 55 | { |
| 56 | $this->cacheId = $cacheId; |
| 57 | } |
| 58 | |
| 59 | public function getCacheId(): ?int |
| 60 | { |
| 61 | return $this->cacheId; |
| 62 | } |
| 63 | |
| 64 | public function setCacheId(?int $cacheId): self |
| 65 | { |
| 66 | $this->cacheId = $cacheId; |
| 67 | |
| 68 | return $this; |
| 69 | } |
| 70 | |
| 71 | public function getSourceWorksheet(): ?string |
| 72 | { |
| 73 | return $this->sourceWorksheet; |
| 74 | } |
| 75 | |
| 76 | public function setSourceWorksheet(?string $sourceWorksheet): self |
| 77 | { |
| 78 | $this->sourceWorksheet = $sourceWorksheet; |
| 79 | |
| 80 | return $this; |
| 81 | } |
| 82 | |
| 83 | public function getSourceRange(): ?string |
| 84 | { |
| 85 | return $this->sourceRange; |
| 86 | } |
| 87 | |
| 88 | public function setSourceRange(?string $sourceRange): self |
| 89 | { |
| 90 | $this->sourceRange = $sourceRange; |
| 91 | |
| 92 | return $this; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * @return string[] |
| 97 | */ |
| 98 | public function getCacheFields(): array |
| 99 | { |
| 100 | return $this->cacheFields; |
| 101 | } |
| 102 | |
| 103 | public function addCacheField(string $name): self |
| 104 | { |
| 105 | $this->cacheFields[] = $name; |
| 106 | |
| 107 | return $this; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * @param string[] $cacheFields |
| 112 | */ |
| 113 | public function setCacheFields(array $cacheFields): self |
| 114 | { |
| 115 | $this->cacheFields = array_values($cacheFields); |
| 116 | |
| 117 | return $this; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Return the name of the cache field at the given zero-based index, or null. |
| 122 | */ |
| 123 | public function getCacheFieldName(int $index): ?string |
| 124 | { |
| 125 | return $this->cacheFields[$index] ?? null; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Set the distinct values recorded for a field (used when generating a new |
| 130 | * cache definition). |
| 131 | * |
| 132 | * @param string[] $items |
| 133 | */ |
| 134 | public function setSharedItems(string $fieldName, array $items): self |
| 135 | { |
| 136 | $this->sharedItems[$fieldName] = array_values($items); |
| 137 | |
| 138 | return $this; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * @return string[] |
| 143 | */ |
| 144 | public function getSharedItems(string $fieldName): array |
| 145 | { |
| 146 | return $this->sharedItems[$fieldName] ?? []; |
| 147 | } |
| 148 | |
| 149 | public function setFieldGroup(string $fieldName, PivotFieldGroup $group): self |
| 150 | { |
| 151 | $this->fieldGroups[$fieldName] = $group; |
| 152 | |
| 153 | return $this; |
| 154 | } |
| 155 | |
| 156 | public function getFieldGroup(string $fieldName): ?PivotFieldGroup |
| 157 | { |
| 158 | return $this->fieldGroups[$fieldName] ?? null; |
| 159 | } |
| 160 | } |
| 161 |