PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Style / ConditionalFormatting / Wizard / Blanks.php

Blanks.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/Blanks.php

96 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\Wizard;
4
5 use TablePress\PhpOffice\PhpSpreadsheet\Exception;
6 use TablePress\PhpOffice\PhpSpreadsheet\Style\Conditional;
7 use TablePress\PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\Wizard;
8
9 /**
10 * @method Blanks notBlank()
11 * @method Blanks notEmpty()
12 * @method Blanks isBlank()
13 * @method Blanks isEmpty()
14 */
15 class Blanks extends WizardAbstract implements WizardInterface
16 {
17 protected const OPERATORS = [
18 'notBlank' => false,
19 'isBlank' => true,
20 'notEmpty' => false,
21 'empty' => true,
22 ];
23
24 protected const EXPRESSIONS = [
25 Wizard::NOT_BLANKS => 'LEN(TRIM(%s))>0',
26 Wizard::BLANKS => 'LEN(TRIM(%s))=0',
27 ];
28
29 protected bool $inverse;
30
31 public function __construct(string $cellRange, bool $inverse = false)
32 {
33 parent::__construct($cellRange);
34 $this->inverse = $inverse;
35 }
36
37 protected function inverse(bool $inverse): void
38 {
39 $this->inverse = $inverse;
40 }
41
42 protected function getExpression(): void
43 {
44 $this->expression = sprintf(
45 self::EXPRESSIONS[$this->inverse ? Wizard::BLANKS : Wizard::NOT_BLANKS],
46 $this->referenceCell
47 );
48 }
49
50 public function getConditional(): Conditional
51 {
52 $this->getExpression();
53
54 $conditional = new Conditional();
55 $conditional->setConditionType(
56 $this->inverse ? Conditional::CONDITION_CONTAINSBLANKS : Conditional::CONDITION_NOTCONTAINSBLANKS
57 );
58 $conditional->setConditions([$this->expression]);
59 $conditional->setStyle($this->getStyle());
60 $conditional->setStopIfTrue($this->getStopIfTrue());
61
62 return $conditional;
63 }
64
65 public static function fromConditional(Conditional $conditional, string $cellRange = 'A1'): WizardInterface
66 {
67 if (
68 $conditional->getConditionType() !== Conditional::CONDITION_CONTAINSBLANKS
69 && $conditional->getConditionType() !== Conditional::CONDITION_NOTCONTAINSBLANKS
70 ) {
71 throw new Exception('Conditional is not a Blanks CF Rule conditional');
72 }
73
74 $wizard = new self($cellRange);
75 $wizard->style = $conditional->getStyle();
76 $wizard->stopIfTrue = $conditional->getStopIfTrue();
77 $wizard->inverse = $conditional->getConditionType() === Conditional::CONDITION_CONTAINSBLANKS;
78
79 return $wizard;
80 }
81
82 /**
83 * @param mixed[] $arguments
84 */
85 public function __call(string $methodName, array $arguments): self
86 {
87 if (!array_key_exists($methodName, self::OPERATORS)) {
88 throw new Exception('Invalid Operation for Blanks CF Rule Wizard');
89 }
90
91 $this->inverse(self::OPERATORS[$methodName]);
92
93 return $this;
94 }
95 }
96