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: return $this->coreData ?: $this->coreData = new AuthorCoredata($this->data['coredata']);
33: }
34:
35: public function getHindex()
36: {
37: return isset($this->data['h-index']) ? $this->data['h-index'] : null;
38: }
39:
40: public function getCoAutorCount()
41: {
42: return isset($this->data['coauthor-count']) ? $this->data['coauthor-count'] : null;
43: }
44:
45: //non funziona
46: public function getAffiliation()
47: {
48: return $this->affiliation ?: $this->affiliation = new Affiliation($this->prepareAffiliationData($this->data['affiliation-current']));
49: }
50:
51: public function getAffiliationHistory()
52: {
53: if (isset($this->data['affiliation-history'])) {
54: return $this->affiliation_history ?: $this->affiliation_history = array_map(function ($affiliation) {
55: return new Affiliation($this->prepareAffiliationData($affiliation));
56: }, $this->data['affiliation-history']['affiliation']);
57: }
58: }
59:
60: public function getSubjectAreas()
61: {
62: if (isset($this->data['subject-areas'])) {
63: return $this->subject_areas ?: $this->subject_areas = array_map(function ($area) {
64: return new AuthorSubjectArea($this->prepareSubjectArea($area));
65: }, $this->data['subject-areas']['subject-area']);
66: }
67: }
68:
69: public function getProfile()
70: {
71: if (isset($this->data['author-profile'])) {
72: return $this->profile ?: $this->profile = new AuthorProfile($this->data['author-profile']);
73: }
74: }
75:
76: protected function prepareAffiliationData($affiliation)
77: {
78: return [
79: 'afid' => $affiliation['@id'],
80: 'affiliation-url' => $affiliation['@href']
81: ];
82: }
83:
84: protected function prepareSubjectArea($area)
85: {
86: return [
87: 'abbrev' => $area['@abbrev'],
88: 'code' => $area['@code'],
89: 'area' => $area['$']
90: ];
91: }
92: }
93: