|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Inventory Boolean Field Class. |
|
5
|
|
|
* |
|
6
|
|
|
* @package InventoryField |
|
7
|
|
|
* |
|
8
|
|
|
* @copyright YetiForce S.A. |
|
9
|
|
|
* @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com) |
|
10
|
|
|
* @author Mariusz Krzaczkowski <[email protected]> |
|
11
|
|
|
* @author Radosław Skrzypczak <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class Vtiger_Boolean_InventoryField extends Vtiger_Basic_InventoryField |
|
14
|
|
|
{ |
|
15
|
|
|
protected $type = 'Boolean'; |
|
16
|
|
|
protected $defaultLabel = 'LBL_BOOLEAN'; |
|
17
|
|
|
protected $columnName = 'bool'; |
|
18
|
|
|
protected $dbType = \yii\db\Schema::TYPE_BOOLEAN; |
|
19
|
|
|
protected $onlyOne = false; |
|
20
|
|
|
protected $purifyType = \App\Purifier::BOOL; |
|
21
|
|
|
|
|
22
|
|
|
/** {@inheritdoc} */ |
|
23
|
|
|
public function validate($value, string $columnName, bool $isUserFormat, $originalValue = null) |
|
24
|
|
|
{ |
|
25
|
|
|
if (!\in_array($value, [0, 1, '1', '0', 'on'])) { |
|
26
|
|
|
throw new \App\Exceptions\Security("ERR_ILLEGAL_FIELD_VALUE||$columnName||$value", 406); |
|
27
|
|
|
} |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** {@inheritdoc} */ |
|
31
|
|
|
public function getDisplayValue($value, array $rowData = [], bool $rawText = false) |
|
32
|
|
|
{ |
|
33
|
|
|
return (bool) $value ? App\Language::translate('LBL_YES', '_Base', null, !$rawText) : App\Language::translate('LBL_NO', '_Base', null, !$rawText); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** {@inheritdoc} */ |
|
37
|
|
|
public function compare($value, $prevValue, string $column): bool |
|
38
|
|
|
{ |
|
39
|
|
|
return (int) $prevValue === (int) $value; |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|