1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Exception; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Style\Conditional; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\Wizard\WizardInterface; |
8
|
|
|
|
9
|
|
|
class Wizard |
10
|
|
|
{ |
11
|
|
|
public const CELL_VALUE = 'cellValue'; |
12
|
|
|
public const TEXT_VALUE = 'textValue'; |
13
|
|
|
public const BLANKS = Conditional::CONDITION_CONTAINSBLANKS; |
14
|
|
|
public const NOT_BLANKS = Conditional::CONDITION_NOTCONTAINSBLANKS; |
15
|
|
|
public const ERRORS = Conditional::CONDITION_CONTAINSERRORS; |
16
|
|
|
public const NOT_ERRORS = Conditional::CONDITION_NOTCONTAINSERRORS; |
17
|
|
|
public const EXPRESSION = Conditional::CONDITION_EXPRESSION; |
18
|
|
|
public const FORMULA = Conditional::CONDITION_EXPRESSION; |
19
|
|
|
public const DATES_OCCURRING = 'DateValue'; |
20
|
|
|
public const DUPLICATES = Conditional::CONDITION_DUPLICATES; |
21
|
|
|
public const UNIQUE = Conditional::CONDITION_UNIQUE; |
22
|
|
|
|
23
|
|
|
public const VALUE_TYPE_LITERAL = 'value'; |
24
|
|
|
public const VALUE_TYPE_CELL = 'cell'; |
25
|
|
|
public const VALUE_TYPE_FORMULA = 'formula'; |
26
|
|
|
|
27
|
|
|
protected string $cellRange; |
28
|
|
|
|
29
|
97 |
|
public function __construct(string $cellRange) |
30
|
|
|
{ |
31
|
97 |
|
$this->cellRange = $cellRange; |
32
|
|
|
} |
33
|
|
|
|
34
|
79 |
|
public function newRule(string $ruleType): WizardInterface |
35
|
|
|
{ |
36
|
79 |
|
return match ($ruleType) { |
37
|
79 |
|
self::CELL_VALUE => new Wizard\CellValue($this->cellRange), |
38
|
79 |
|
self::TEXT_VALUE => new Wizard\TextValue($this->cellRange), |
39
|
79 |
|
self::BLANKS => new Wizard\Blanks($this->cellRange, true), |
40
|
79 |
|
self::NOT_BLANKS => new Wizard\Blanks($this->cellRange, false), |
41
|
79 |
|
self::ERRORS => new Wizard\Errors($this->cellRange, true), |
42
|
79 |
|
self::NOT_ERRORS => new Wizard\Errors($this->cellRange, false), |
43
|
79 |
|
self::EXPRESSION, self::FORMULA => new Wizard\Expression($this->cellRange), |
44
|
79 |
|
self::DATES_OCCURRING => new Wizard\DateValue($this->cellRange), |
45
|
79 |
|
self::DUPLICATES => new Wizard\Duplicates($this->cellRange, false), |
46
|
79 |
|
self::UNIQUE => new Wizard\Duplicates($this->cellRange, true), |
47
|
79 |
|
default => throw new Exception('No wizard exists for this CF rule type'), |
48
|
79 |
|
}; |
49
|
|
|
} |
50
|
|
|
|
51
|
62 |
|
public static function fromConditional(Conditional $conditional, string $cellRange = 'A1'): WizardInterface |
52
|
|
|
{ |
53
|
62 |
|
$conditionalType = $conditional->getConditionType(); |
54
|
|
|
|
55
|
62 |
|
return match ($conditionalType) { |
56
|
62 |
|
Conditional::CONDITION_CELLIS => Wizard\CellValue::fromConditional($conditional, $cellRange), |
57
|
62 |
|
Conditional::CONDITION_CONTAINSTEXT, Conditional::CONDITION_NOTCONTAINSTEXT, Conditional::CONDITION_BEGINSWITH, Conditional::CONDITION_ENDSWITH => Wizard\TextValue::fromConditional($conditional, $cellRange), |
58
|
62 |
|
Conditional::CONDITION_CONTAINSBLANKS, Conditional::CONDITION_NOTCONTAINSBLANKS => Wizard\Blanks::fromConditional($conditional, $cellRange), |
59
|
62 |
|
Conditional::CONDITION_CONTAINSERRORS, Conditional::CONDITION_NOTCONTAINSERRORS => Wizard\Errors::fromConditional($conditional, $cellRange), |
60
|
62 |
|
Conditional::CONDITION_TIMEPERIOD => Wizard\DateValue::fromConditional($conditional, $cellRange), |
61
|
62 |
|
Conditional::CONDITION_EXPRESSION => Wizard\Expression::fromConditional($conditional, $cellRange), |
62
|
62 |
|
Conditional::CONDITION_DUPLICATES, Conditional::CONDITION_UNIQUE => Wizard\Duplicates::fromConditional($conditional, $cellRange), |
63
|
62 |
|
default => throw new Exception('No wizard exists for this CF rule type'), |
64
|
62 |
|
}; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|