| Total Complexity | 6 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | class TemporaryBarcodeExists implements Rule |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Create a new rule instance. |
||
| 12 | * |
||
| 13 | * @return void |
||
| 14 | */ |
||
| 15 | public function __construct(AlmaClient $alma) |
||
| 16 | { |
||
| 17 | $this->alma = $alma; |
||
|
|
|||
| 18 | $this->normalizedValue = null; |
||
| 19 | } |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Determine if the validation rule passes. |
||
| 23 | * |
||
| 24 | * @param string $attribute |
||
| 25 | * @param mixed $value |
||
| 26 | * @return bool |
||
| 27 | */ |
||
| 28 | public function passes($attribute, $value) |
||
| 29 | { |
||
| 30 | if (empty($value)) { |
||
| 31 | return true; |
||
| 32 | } |
||
| 33 | |||
| 34 | $almaUser = $this->alma->users->findOne('ALL~' . $value); |
||
| 35 | if (!is_null($almaUser)) { |
||
| 36 | $this->normalizedValue = $almaUser->getPrimaryId(); |
||
| 37 | return true; |
||
| 38 | } |
||
| 39 | |||
| 40 | return false; |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Get the validation error message. |
||
| 45 | * |
||
| 46 | * @return string |
||
| 47 | */ |
||
| 48 | public function message() |
||
| 49 | { |
||
| 50 | return 'Det midlertidige lånekortet må eksistere i Alma.'; |
||
| 51 | } |
||
| 52 | |||
| 53 | public function getNormalizedValue() |
||
| 56 | } |
||
| 57 | } |
||
| 58 |