|
21 | 21 | */ |
22 | 22 | trait lock |
23 | 23 | { |
| 24 | + /** |
| 25 | + * Check if record is locked. |
| 26 | + * |
| 27 | + * @throws \InvalidArgumentException if zamekK is not set |
| 28 | + */ |
24 | 29 | public function locked(): bool |
25 | 30 | { |
26 | 31 | $lockValue = $this->getDataValue('zamekK'); |
27 | | - if(is_null($lockValue)){ |
28 | | - throw new \InvalidArgumentException('unset zamekK',1); |
| 32 | + |
| 33 | + if (null === $lockValue) { |
| 34 | + throw new \InvalidArgumentException('unset zamekK', 1); |
29 | 35 | } |
30 | | - return $lockValue === 'zamek.otevreno'; |
| 36 | + |
| 37 | + return $lockValue !== 'zamek.otevreno'; |
31 | 38 | } |
32 | 39 |
|
| 40 | + /** |
| 41 | + * Get lock type. Value of zamekK without "zamek." |
| 42 | + * Most common values are "otevreno" and "uzamceno". |
| 43 | + * |
| 44 | + * @throws \InvalidArgumentException if zamekK is not set |
| 45 | + */ |
33 | 46 | public function getLockType(): string |
34 | 47 | { |
35 | 48 | $lockValue = $this->getDataValue('zamekK'); |
36 | | - if(is_null($lockValue)){ |
37 | | - throw new \InvalidArgumentException('unset zamekK',1); |
| 49 | + |
| 50 | + if (null === $lockValue) { |
| 51 | + throw new \InvalidArgumentException('unset zamekK', 1); |
38 | 52 | } |
| 53 | + |
39 | 54 | return str_replace('zamek.', '', $lockValue); |
40 | 55 | } |
41 | 56 |
|
| 57 | + /** |
| 58 | + * Locks the current record. |
| 59 | + * |
| 60 | + * @return bool true on success, false on failure |
| 61 | + */ |
42 | 62 | public function lock(): bool |
43 | 63 | { |
44 | | - return $this->performAction('unlock'); |
| 64 | + return $this->performAction('lock'); |
45 | 65 | } |
46 | 66 |
|
| 67 | + /** |
| 68 | + * Unlocks the current record. |
| 69 | + * |
| 70 | + * @return bool true on success, false on failure |
| 71 | + */ |
47 | 72 | public function unlock(): bool |
48 | 73 | { |
49 | 74 | return $this->performAction('unlock'); |
|
0 commit comments