Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
 
3
namespace PhpOffice\PhpSpreadsheet\Style;
4
 
5
use PhpOffice\PhpSpreadsheet\IComparable;
6
use PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\ConditionalColorScale;
7
use PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\ConditionalDataBar;
8
 
9
class Conditional implements IComparable
10
{
11
    // Condition types
12
    const CONDITION_NONE = 'none';
13
    const CONDITION_BEGINSWITH = 'beginsWith';
14
    const CONDITION_CELLIS = 'cellIs';
15
    const CONDITION_COLORSCALE = 'colorScale';
16
    const CONDITION_CONTAINSBLANKS = 'containsBlanks';
17
    const CONDITION_CONTAINSERRORS = 'containsErrors';
18
    const CONDITION_CONTAINSTEXT = 'containsText';
19
    const CONDITION_DATABAR = 'dataBar';
20
    const CONDITION_ENDSWITH = 'endsWith';
21
    const CONDITION_EXPRESSION = 'expression';
22
    const CONDITION_NOTCONTAINSBLANKS = 'notContainsBlanks';
23
    const CONDITION_NOTCONTAINSERRORS = 'notContainsErrors';
24
    const CONDITION_NOTCONTAINSTEXT = 'notContainsText';
25
    const CONDITION_TIMEPERIOD = 'timePeriod';
26
    const CONDITION_DUPLICATES = 'duplicateValues';
27
    const CONDITION_UNIQUE = 'uniqueValues';
28
 
29
    private const CONDITION_TYPES = [
30
        self::CONDITION_BEGINSWITH,
31
        self::CONDITION_CELLIS,
32
        self::CONDITION_COLORSCALE,
33
        self::CONDITION_CONTAINSBLANKS,
34
        self::CONDITION_CONTAINSERRORS,
35
        self::CONDITION_CONTAINSTEXT,
36
        self::CONDITION_DATABAR,
37
        self::CONDITION_DUPLICATES,
38
        self::CONDITION_ENDSWITH,
39
        self::CONDITION_EXPRESSION,
40
        self::CONDITION_NONE,
41
        self::CONDITION_NOTCONTAINSBLANKS,
42
        self::CONDITION_NOTCONTAINSERRORS,
43
        self::CONDITION_NOTCONTAINSTEXT,
44
        self::CONDITION_TIMEPERIOD,
45
        self::CONDITION_UNIQUE,
46
    ];
47
 
48
    // Operator types
49
    const OPERATOR_NONE = '';
50
    const OPERATOR_BEGINSWITH = 'beginsWith';
51
    const OPERATOR_ENDSWITH = 'endsWith';
52
    const OPERATOR_EQUAL = 'equal';
53
    const OPERATOR_GREATERTHAN = 'greaterThan';
54
    const OPERATOR_GREATERTHANOREQUAL = 'greaterThanOrEqual';
55
    const OPERATOR_LESSTHAN = 'lessThan';
56
    const OPERATOR_LESSTHANOREQUAL = 'lessThanOrEqual';
57
    const OPERATOR_NOTEQUAL = 'notEqual';
58
    const OPERATOR_CONTAINSTEXT = 'containsText';
59
    const OPERATOR_NOTCONTAINS = 'notContains';
60
    const OPERATOR_BETWEEN = 'between';
61
    const OPERATOR_NOTBETWEEN = 'notBetween';
62
 
63
    const TIMEPERIOD_TODAY = 'today';
64
    const TIMEPERIOD_YESTERDAY = 'yesterday';
65
    const TIMEPERIOD_TOMORROW = 'tomorrow';
66
    const TIMEPERIOD_LAST_7_DAYS = 'last7Days';
67
    const TIMEPERIOD_LAST_WEEK = 'lastWeek';
68
    const TIMEPERIOD_THIS_WEEK = 'thisWeek';
69
    const TIMEPERIOD_NEXT_WEEK = 'nextWeek';
70
    const TIMEPERIOD_LAST_MONTH = 'lastMonth';
71
    const TIMEPERIOD_THIS_MONTH = 'thisMonth';
72
    const TIMEPERIOD_NEXT_MONTH = 'nextMonth';
73
 
74
    /**
75
     * Condition type.
76
     */
77
    private string $conditionType = self::CONDITION_NONE;
78
 
79
    /**
80
     * Operator type.
81
     */
82
    private string $operatorType = self::OPERATOR_NONE;
83
 
84
    /**
85
     * Text.
86
     */
87
    private string $text = '';
88
 
89
    /**
90
     * Stop on this condition, if it matches.
91
     */
92
    private bool $stopIfTrue = false;
93
 
94
    /**
95
     * Condition.
96
     *
97
     * @var (bool|float|int|string)[]
98
     */
99
    private array $condition = [];
100
 
101
    private ?ConditionalDataBar $dataBar = null;
102
 
103
    private ?ConditionalColorScale $colorScale = null;
104
 
105
    private Style $style;
106
 
107
    private bool $noFormatSet = false;
108
 
109
    private int $priority = 0;
110
 
111
    /**
112
     * Create a new Conditional.
113
     */
114
    public function __construct()
115
    {
116
        // Initialise values
117
        $this->style = new Style(false, true);
118
    }
119
 
120
    public function getPriority(): int
121
    {
122
        return $this->priority;
123
    }
124
 
125
    public function setPriority(int $priority): self
126
    {
127
        $this->priority = $priority;
128
 
129
        return $this;
130
    }
131
 
132
    public function getNoFormatSet(): bool
133
    {
134
        return $this->noFormatSet;
135
    }
136
 
137
    public function setNoFormatSet(bool $noFormatSet): self
138
    {
139
        $this->noFormatSet = $noFormatSet;
140
 
141
        return $this;
142
    }
143
 
144
    /**
145
     * Get Condition type.
146
     */
147
    public function getConditionType(): string
148
    {
149
        return $this->conditionType;
150
    }
151
 
152
    /**
153
     * Set Condition type.
154
     *
155
     * @param string $type Condition type, see self::CONDITION_*
156
     *
157
     * @return $this
158
     */
159
    public function setConditionType(string $type): static
160
    {
161
        $this->conditionType = $type;
162
 
163
        return $this;
164
    }
165
 
166
    /**
167
     * Get Operator type.
168
     */
169
    public function getOperatorType(): string
170
    {
171
        return $this->operatorType;
172
    }
173
 
174
    /**
175
     * Set Operator type.
176
     *
177
     * @param string $type Conditional operator type, see self::OPERATOR_*
178
     *
179
     * @return $this
180
     */
181
    public function setOperatorType(string $type): static
182
    {
183
        $this->operatorType = $type;
184
 
185
        return $this;
186
    }
187
 
188
    /**
189
     * Get text.
190
     */
191
    public function getText(): string
192
    {
193
        return $this->text;
194
    }
195
 
196
    /**
197
     * Set text.
198
     *
199
     * @return $this
200
     */
201
    public function setText(string $text): static
202
    {
203
        $this->text = $text;
204
 
205
        return $this;
206
    }
207
 
208
    /**
209
     * Get StopIfTrue.
210
     */
211
    public function getStopIfTrue(): bool
212
    {
213
        return $this->stopIfTrue;
214
    }
215
 
216
    /**
217
     * Set StopIfTrue.
218
     *
219
     * @return $this
220
     */
221
    public function setStopIfTrue(bool $stopIfTrue): static
222
    {
223
        $this->stopIfTrue = $stopIfTrue;
224
 
225
        return $this;
226
    }
227
 
228
    /**
229
     * Get Conditions.
230
     *
231
     * @return (bool|float|int|string)[]
232
     */
233
    public function getConditions(): array
234
    {
235
        return $this->condition;
236
    }
237
 
238
    /**
239
     * Set Conditions.
240
     *
241
     * @param bool|(bool|float|int|string)[]|float|int|string $conditions Condition
242
     *
243
     * @return $this
244
     */
245
    public function setConditions($conditions): static
246
    {
247
        if (!is_array($conditions)) {
248
            $conditions = [$conditions];
249
        }
250
        $this->condition = $conditions;
251
 
252
        return $this;
253
    }
254
 
255
    /**
256
     * Add Condition.
257
     *
258
     * @param bool|float|int|string $condition Condition
259
     *
260
     * @return $this
261
     */
262
    public function addCondition($condition): static
263
    {
264
        $this->condition[] = $condition;
265
 
266
        return $this;
267
    }
268
 
269
    /**
270
     * Get Style.
271
     */
272
    public function getStyle(): Style
273
    {
274
        return $this->style;
275
    }
276
 
277
    /**
278
     * Set Style.
279
     *
280
     * @return $this
281
     */
282
    public function setStyle(Style $style): static
283
    {
284
        $this->style = $style;
285
 
286
        return $this;
287
    }
288
 
289
    public function getDataBar(): ?ConditionalDataBar
290
    {
291
        return $this->dataBar;
292
    }
293
 
294
    public function setDataBar(ConditionalDataBar $dataBar): static
295
    {
296
        $this->dataBar = $dataBar;
297
 
298
        return $this;
299
    }
300
 
301
    public function getColorScale(): ?ConditionalColorScale
302
    {
303
        return $this->colorScale;
304
    }
305
 
306
    public function setColorScale(ConditionalColorScale $colorScale): static
307
    {
308
        $this->colorScale = $colorScale;
309
 
310
        return $this;
311
    }
312
 
313
    /**
314
     * Get hash code.
315
     *
316
     * @return string Hash code
317
     */
318
    public function getHashCode(): string
319
    {
320
        return md5(
321
            $this->conditionType
322
            . $this->operatorType
323
            . implode(';', $this->condition)
324
            . $this->style->getHashCode()
325
            . __CLASS__
326
        );
327
    }
328
 
329
    /**
330
     * Implement PHP __clone to create a deep clone, not just a shallow copy.
331
     */
332
    public function __clone()
333
    {
334
        $vars = get_object_vars($this);
335
        foreach ($vars as $key => $value) {
336
            if (is_object($value)) {
337
                $this->$key = clone $value;
338
            } else {
339
                $this->$key = $value;
340
            }
341
        }
342
    }
343
 
344
    /**
345
     * Verify if param is valid condition type.
346
     */
347
    public static function isValidConditionType(string $type): bool
348
    {
349
        return in_array($type, self::CONDITION_TYPES);
350
    }
351
}