| 1441 |
ariadna |
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 |
public function __construct(string $cellRange)
|
|
|
30 |
{
|
|
|
31 |
$this->cellRange = $cellRange;
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
public function newRule(string $ruleType): WizardInterface
|
|
|
35 |
{
|
|
|
36 |
return match ($ruleType) {
|
|
|
37 |
self::CELL_VALUE => new Wizard\CellValue($this->cellRange),
|
|
|
38 |
self::TEXT_VALUE => new Wizard\TextValue($this->cellRange),
|
|
|
39 |
self::BLANKS => new Wizard\Blanks($this->cellRange, true),
|
|
|
40 |
self::NOT_BLANKS => new Wizard\Blanks($this->cellRange, false),
|
|
|
41 |
self::ERRORS => new Wizard\Errors($this->cellRange, true),
|
|
|
42 |
self::NOT_ERRORS => new Wizard\Errors($this->cellRange, false),
|
|
|
43 |
self::EXPRESSION, self::FORMULA => new Wizard\Expression($this->cellRange),
|
|
|
44 |
self::DATES_OCCURRING => new Wizard\DateValue($this->cellRange),
|
|
|
45 |
self::DUPLICATES => new Wizard\Duplicates($this->cellRange, false),
|
|
|
46 |
self::UNIQUE => new Wizard\Duplicates($this->cellRange, true),
|
|
|
47 |
default => throw new Exception('No wizard exists for this CF rule type'),
|
|
|
48 |
};
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
public static function fromConditional(Conditional $conditional, string $cellRange = 'A1'): WizardInterface
|
|
|
52 |
{
|
|
|
53 |
$conditionalType = $conditional->getConditionType();
|
|
|
54 |
|
|
|
55 |
return match ($conditionalType) {
|
|
|
56 |
Conditional::CONDITION_CELLIS => Wizard\CellValue::fromConditional($conditional, $cellRange),
|
|
|
57 |
Conditional::CONDITION_CONTAINSTEXT, Conditional::CONDITION_NOTCONTAINSTEXT, Conditional::CONDITION_BEGINSWITH, Conditional::CONDITION_ENDSWITH => Wizard\TextValue::fromConditional($conditional, $cellRange),
|
|
|
58 |
Conditional::CONDITION_CONTAINSBLANKS, Conditional::CONDITION_NOTCONTAINSBLANKS => Wizard\Blanks::fromConditional($conditional, $cellRange),
|
|
|
59 |
Conditional::CONDITION_CONTAINSERRORS, Conditional::CONDITION_NOTCONTAINSERRORS => Wizard\Errors::fromConditional($conditional, $cellRange),
|
|
|
60 |
Conditional::CONDITION_TIMEPERIOD => Wizard\DateValue::fromConditional($conditional, $cellRange),
|
|
|
61 |
Conditional::CONDITION_EXPRESSION => Wizard\Expression::fromConditional($conditional, $cellRange),
|
|
|
62 |
Conditional::CONDITION_DUPLICATES, Conditional::CONDITION_UNIQUE => Wizard\Duplicates::fromConditional($conditional, $cellRange),
|
|
|
63 |
default => throw new Exception('No wizard exists for this CF rule type'),
|
|
|
64 |
};
|
|
|
65 |
}
|
|
|
66 |
}
|