Lines
97.43%
38 / 39
Functions and Methods
75.00%
3 / 4
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Preferences | 97.43% | 38 / 39 | 75.00% | 3 / 4 | 8 | 0.00% | 0 / 1 | |||
| readProperty | 100.00% | 9 / 9 | 100.00% | 1 / 1 | 2 | |||||
| readChangeDateTime | 92.30% | 12 / 13 | 0.00% | 0 / 1 | 3.00 | |||||
| replaceProperty | 100.00% | 11 / 11 | 100.00% | 1 / 1 | 2 | |||||
| deleteProperty | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | namespace BO\Zmsbackend\Preferences\Service; | |
| 4 | ||
| 5 | class Preferences extends \BO\Zmsbackend\Base | |
| 6 | { | |
| 7 | const string REPLACE_SKIPPED = 'skipped'; | |
| 8 | ||
| 9 | public function readProperty(string $entityName, $entityId, string $groupName, string $name, bool $forUpdate = false) | |
| 10 | { | |
| 11 | $sql = \BO\Zmsbackend\Preferences\Repository\Preferences::QUERY_SELECT_PROPERTY; | |
| 12 | if ($forUpdate) { | |
| 13 | $sql .= " FOR UPDATE"; | |
| 14 | } | |
| 15 | return $this->fetchValue($sql, [ | |
| 16 | "entityName" => $entityName, | |
| 17 | "entityId" => $entityId, | |
| 18 | "groupName" => $groupName, | |
| 19 | "name" => $name, | |
| 20 | ]); | |
| 21 | } | |
| 22 | ||
| 23 | public function readChangeDateTime(string $entityName, $entityId, string $groupName, string $name, bool $forUpdate = false): \DateTimeImmutable | |
| 24 | { | |
| 25 | $sql = \BO\Zmsbackend\Preferences\Repository\Preferences::QUERY_SELECT_TIMESTAMP; | |
| 26 | if ($forUpdate) { | |
| 27 | $sql .= " FOR UPDATE"; | |
| 28 | } | |
| 29 | $timeString = $this->fetchValue($sql, [ | |
| 30 | "entityName" => $entityName, | |
| 31 | "entityId" => $entityId, | |
| 32 | "groupName" => $groupName, | |
| 33 | "name" => $name, | |
| 34 | ]); | |
| 35 | if (!$timeString) { | |
| 36 | $timeString = 'now'; | |
| 37 | } else { | |
| 38 | $timeString .= ' ' . \BO\Zmsbackend\Connection\Select::$connectionTimezone; | |
| 39 | } | |
| 40 | return new \DateTimeImmutable($timeString); | |
| 41 | } | |
| 42 | ||
| 43 | public function replaceProperty(string $entityName, $entityId, $groupName, $name, $value) | |
| 44 | { | |
| 45 | $this->getWriter(); | |
| 46 | $currentValue = $this->readProperty($entityName, $entityId, $groupName, $name, true); | |
| 47 | if ($currentValue != $value) { | |
| 48 | return $this->perform(\BO\Zmsbackend\Preferences\Repository\Preferences::QUERY_REPLACE_PROPERTY, [ | |
| 49 | "entityName" => $entityName, | |
| 50 | "entityId" => $entityId, | |
| 51 | "groupName" => $groupName, | |
| 52 | "name" => $name, | |
| 53 | "value" => $value, | |
| 54 | ]); | |
| 55 | } | |
| 56 | return static::REPLACE_SKIPPED; | |
| 57 | } | |
| 58 | ||
| 59 | /** | |
| 60 | * remove Preferences data | |
| 61 | * | |
| 62 | * @return bool | |
| 63 | * | |
| 64 | * @param key-of<TArray> $name | |
| 65 | * | |
| 66 | */ | |
| 67 | public function deleteProperty(string $entityName, $entityId, $groupName, $name) | |
| 68 | { | |
| 69 | return $this->perform(\BO\Zmsbackend\Preferences\Repository\Preferences::QUERY_DELETE_PROPERTY, [ | |
| 70 | "entityName" => $entityName, | |
| 71 | "entityId" => $entityId, | |
| 72 | "groupName" => $groupName, | |
| 73 | "name" => $name, | |
| 74 | ]); | |
| 75 | } | |
| 76 | } |