1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Scriptotek\Alma\Users; |
4
|
|
|
|
5
|
|
|
use Scriptotek\Alma\Client; |
6
|
|
|
|
7
|
|
|
class User |
8
|
|
|
{ |
9
|
|
|
protected $_user_id; |
10
|
|
|
protected $client; |
11
|
|
|
protected $data; |
12
|
|
|
|
13
|
|
|
public function __construct(Client $client = null, $user_id = null, $data = []) |
14
|
|
|
{ |
15
|
|
|
$this->_user_id = $user_id; |
16
|
|
|
$this->client = $client; |
17
|
|
|
$this->data = $data; |
18
|
|
|
// $this->rows = new Rows($this->path, $this->client); |
|
|
|
|
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public static function fromResponse(Client $client = null, $data) |
22
|
|
|
{ |
23
|
|
|
return new User($client, $data->primary_id, $data); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function hasFullRecord() |
27
|
|
|
{ |
28
|
|
|
return isset($this->data->user_identifier); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function fetch() |
32
|
|
|
{ |
33
|
|
|
if ($this->hasFullRecord()) { |
34
|
|
|
return; |
35
|
|
|
} |
36
|
|
|
$data = $this->client->getJSON('/users/' . $this->_user_id); |
37
|
|
|
$this->data = $data; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function getData() |
41
|
|
|
{ |
42
|
|
|
return $this->data; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getIdOfType($id_type) |
46
|
|
|
{ |
47
|
|
|
foreach ($this->user_identifier as $identifier) { |
|
|
|
|
48
|
|
|
if ($identifier->id_type->value == $id_type) { |
49
|
|
|
return $identifier->value; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
return null; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getBarcode() |
56
|
|
|
{ |
57
|
|
|
return $this->getIdOfType('BARCODE'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getUniversityId() |
61
|
|
|
{ |
62
|
|
|
return $this->getIdOfType('UNIV_ID'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getIds() |
66
|
|
|
{ |
67
|
|
|
$ids = [$this->primary_id]; |
|
|
|
|
68
|
|
|
foreach ($this->user_identifier as $identifier) { |
|
|
|
|
69
|
|
|
$ids[] = $identifier->value; |
70
|
|
|
} |
71
|
|
|
return $ids; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function __get($key) |
75
|
|
|
{ |
76
|
|
|
$method = 'get' . ucfirst($key); |
77
|
|
|
if (method_exists($this, $method)) { |
78
|
|
|
return $this->$method(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
if (isset($this->data->{$key})) { |
82
|
|
|
return $this->data->{$key}; |
83
|
|
|
} else { |
84
|
|
|
// If initialized from a search, we don't have the full record. |
85
|
|
|
// Let's fetch it. |
86
|
|
|
$this->fetch(); |
87
|
|
|
if (isset($this->data->{$key})) { |
88
|
|
|
return $this->data->{$key}; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.