1: <?php
2:
3: namespace Scopus\Response;
4:
5: class Author
6: {
7: /** @var array */
8: protected $data;
9:
10: /** @var AuthorCoredata */
11: protected $coreData;
12:
13: /** @var Affiliation */
14: protected $affiliation;
15:
16: /** @var Affiliation[] */
17: protected $affiliation_history;
18:
19: /** @var AuthorSubjectArea[] */
20: protected $subject_areas;
21:
22: /** @var AuthorProfile */
23: protected $profile;
24:
25: public function __construct(array $data)
26: {
27: $this->data = $data;
28: }
29:
30: public function getCoreData()
31: {
32: if (!isset($this->data['coredata'])) {
33: return null;
34: }
35:
36: return $this->coreData ?? $this->coreData = new AuthorCoredata($this->data['coredata']);
37: }
38:
39: public function getHindex()
40: {
41: return isset($this->data['h-index']) ? $this->data['h-index'] : null;
42: }
43:
44: public function getCoAutorCount()
45: {
46: return isset($this->data['coauthor-count']) ? $this->data['coauthor-count'] : null;
47: }
48:
49: //non funziona
50: public function getAffiliation()
51: {
52: if (!isset($this->data['affiliation-current'])) {
53: return null;
54: }
55:
56: return $this->affiliation ?? $this->affiliation = new Affiliation($this->prepareAffiliationData($this->data['affiliation-current']));
57: }
58:
59: public function getAffiliationHistory(): array
60: {
61: if (isset($this->data['affiliation-history']['affiliation'])) {
62: return $this->affiliation_history ?? $this->affiliation_history = array_map(function ($affiliation) {
63: return new Affiliation($this->prepareAffiliationData($affiliation));
64: }, $this->data['affiliation-history']['affiliation']);
65: }
66:
67: return [];
68: }
69:
70: public function getSubjectAreas(): array
71: {
72: if (isset($this->data['subject-areas']['subject-area'])) {
73: return $this->subject_areas ?? $this->subject_areas = array_map(function ($area) {
74: return new AuthorSubjectArea($this->prepareSubjectArea($area));
75: }, $this->data['subject-areas']['subject-area']);
76: }
77:
78: return [];
79: }
80:
81: public function getProfile()
82: {
83: if (isset($this->data['author-profile'])) {
84: return $this->profile ?? $this->profile = new AuthorProfile($this->data['author-profile']);
85: }
86:
87: return null;
88: }
89:
90: protected function prepareAffiliationData($affiliation)
91: {
92: return [
93: 'afid' => isset($affiliation['@id']) ? $affiliation['@id'] : null,
94: 'affiliation-url' => isset($affiliation['@href']) ? $affiliation['@href'] : null
95: ];
96: }
97:
98: protected function prepareSubjectArea($area)
99: {
100: return [
101: 'abbrev' => isset($area['@abbrev']) ? $area['@abbrev'] : null,
102: 'code' => isset($area['@code']) ? $area['@code'] : null,
103: 'area' => isset($area['$']) ? $area['$'] : null
104: ];
105: }
106: }
107: