Code Coverage  | 
      ||||||||||
Lines  | 
       Functions and Methods  | 
       Classes and Traits  | 
      ||||||||
| Total |         | 
       97.44%  | 
       38 / 39  | 
               | 
       75.00%  | 
       3 / 4  | 
       CRAP |         | 
       0.00%  | 
       0 / 1  | 
      
| Preferences |         | 
       97.44%  | 
       38 / 39  | 
               | 
       75.00%  | 
       3 / 4  | 
       8 |         | 
       0.00%  | 
       0 / 1  | 
      
| readProperty |         | 
       100.00%  | 
       9 / 9  | 
               | 
       100.00%  | 
       1 / 1  | 
       2 | |||
| readChangeDateTime |         | 
       92.31%  | 
       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\Zmsdb; | 
| 4 | |
| 5 | class Preferences extends Base | 
| 6 | { | 
| 7 | const REPLACE_SKIPPED = 'skipped'; | 
| 8 | |
| 9 | public function readProperty($entityName, $entityId, $groupName, $name, $forUpdate = false) | 
| 10 | { | 
| 11 | $sql = Query\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($entityName, $entityId, $groupName, $name, $forUpdate = false) | 
| 24 | { | 
| 25 | $sql = Query\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\Zmsdb\Connection\Select::$connectionTimezone; | 
| 39 | } | 
| 40 | return new \DateTimeImmutable($timeString); | 
| 41 | } | 
| 42 | |
| 43 | public function replaceProperty($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(Query\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 Resource Status | 
| 63 | */ | 
| 64 | public function deleteProperty($entityName, $entityId, $groupName, $name) | 
| 65 | { | 
| 66 | return $this->perform(Query\Preferences::QUERY_DELETE_PROPERTY, [ | 
| 67 | "entityName" => $entityName, | 
| 68 | "entityId" => $entityId, | 
| 69 | "groupName" => $groupName, | 
| 70 | "name" => $name, | 
| 71 | ]); | 
| 72 | } | 
| 73 | } |