1: <?php
2:
3: namespace Scopus\Response;
4:
5: class AuthorProfile
6: {
7: /** @var array */
8: protected $data;
9:
10: /** @var AuthorName */
11: protected $preferredName;
12:
13: /** @var AuthorName[] */
14: protected $nameVariants;
15:
16: /** @var Journal[] */
17: protected $journalHistory;
18:
19: /** @var AuthorAffiliation */
20: protected $affiliationCurrent;
21:
22: public function __construct(array $data)
23: {
24: $this->data = $data;
25: }
26:
27: public function getDataCreated()
28: {
29: if (isset($this->data['date-created'])) {
30: $dateCreat = $this->data['date-created'];
31: return $dateCreat['@year'] . '-' . $dateCreat['@month'] . '-' . $dateCreat['@day'];
32: }
33: return null;
34: }
35:
36: public function getPreferredName()
37: {
38: if (!isset($this->data['preferred-name'])) {
39: return null;
40: }
41:
42: return $this->preferredName ?? $this->preferredName = new AuthorName($this->data['preferred-name']);
43: }
44:
45: public function getNameVariants(): array
46: {
47: return $this->nameVariants ?? $this->nameVariants = array_map(function ($nameVariant) {
48: return new AuthorName($nameVariant);
49: }, isset($this->data['name-variant']) ?
50: isset($this->data['name-variant']['indexed-name']) ? [$this->data['name-variant']] : $this->data['name-variant'] : []);
51: }
52:
53: //getClassificationgroup
54:
55: public function getPublicationRange()
56: {
57: if (isset($this->data['publication-range'])) {
58: $pubRange = $this->data['publication-range'];
59: return $pubRange['@start'] . '-' . $pubRange['@end'];
60: }
61: return null;
62: }
63:
64: //to try
65: public function getJournalHistory(): array
66: {
67: if (isset($this->data['journal-history'])) {
68: return $this->journalHistory ?? $this->journalHistory = array_map(function ($journal) {
69: return new Journal($this->prepareJournalHistory($journal));
70: }, $this->data['journal-history']);
71: }
72:
73: return [];
74: }
75:
76: protected function prepareJournalHistory($journal)
77: {
78: return [
79: 'type' => $journal['@type']
80: ];
81: }
82:
83: public function getAffiliationCurrent()
84: {
85: if (!isset($this->data['affiliation-current']['affiliation'])) {
86: return null;
87: }
88:
89: $affiliation = (array_key_exists(0, $this->data['affiliation-current']['affiliation'])) ? $this->data['affiliation-current']['affiliation'][0] : $this->data['affiliation-current']['affiliation'];
90: return $this->affiliationCurrent ?? $this->affiliationCurrent = new AuthorAffiliation($affiliation);
91: }
92:
93:
94: //getAffiliatonHistory
95: }
96: