1: <?php
2:
3: namespace Scopus\Response;
4:
5: class Entry extends AbstractCoredata implements IAbstract
6: {
7: /** @var array */
8: protected $data;
9:
10: /** @var EntryLinks */
11: protected $links;
12:
13: /** @var Affiliation[] */
14: protected $affiliations;
15:
16: /** @var EntryAuthor[] */
17: protected $authors;
18:
19: //Entry of SEARCH_AUTHOR_URI
20: /** @var AuthorName[] */
21: protected $preferredName;
22:
23: public function __construct(array $data)
24: {
25: parent::__construct($data);
26: }
27:
28: public function getLinks()
29: {
30: if (!isset($this->data['link'])) {
31: return null;
32: }
33:
34: return $this->links ?? $this->links = new EntryLinks($this->data['link']);
35: }
36:
37:
38: public function getCreator()
39: {
40: return isset($this->data['dc:creator']) ? $this->data['dc:creator'] : null;
41: }
42:
43: /**
44: * @return EntryAuthor
45: */
46: public function getCreatorAuthor()
47: {
48: if (!$this->getAuthors()) return null;
49: $matches = array_filter($this->getAuthors(), function (EntryAuthor $author) {
50: return $author->getName() === $this->getCreator();
51: });
52: if ($matches) {
53: return array_values($matches)[0];
54: }
55:
56: return null;
57: }
58:
59: public function getCoverDisplayDate()
60: {
61: return isset($this->data['prism:coverDisplayDate']) ? $this->data['prism:coverDisplayDate'] : null;
62: }
63:
64: public function getAffiliations(): array
65: {
66: if (isset($this->data['affiliation'])) {
67: return $this->affiliations ?? $this->affiliations = array_map(function ($affiliation) {
68: return new Affiliation($affiliation);
69: }, $this->data['affiliation']);
70: }
71:
72: return [];
73: }
74:
75: public function countAffiliations()
76: {
77: return count($this->getAffiliations());
78: }
79:
80: public function getSubtype()
81: {
82: return isset($this->data['subtype']) ? $this->data['subtype'] : null;
83: }
84:
85: public function getSubtypeDescription()
86: {
87: return isset($this->data['subtypeDescription']) ? $this->data['subtypeDescription'] : null;
88: }
89:
90: /**
91: * @return EntryAuthor[]
92: */
93: public function getAuthors(): array
94: {
95: if (isset($this->data['author'])) {
96: return $this->authors ?? $this->authors = array_map(function ($author) {
97: return new EntryAuthor($author);
98: }, $this->data['author']);
99: }
100:
101: return [];
102: }
103:
104: /**
105: * @return EntryAuthor[]
106: */
107: public function getCoAuthor(): array
108: {
109: $matches = array_filter($this->getAuthors(), function (EntryAuthor $author) {
110: return $author->getName() !== $this->getCreator();
111: });
112:
113: return array_values($matches);
114: }
115:
116: public function countAuthors()
117: {
118: return count($this->getAuthors());
119: }
120:
121: public function getAuthkeywords()
122: {
123: return isset($this->data['authkeywords']) ? $this->data['authkeywords'] : null;
124: }
125:
126: public function getYear()
127: {
128: if ($this->getCoverDate() != null) {
129: $date = date_parse($this->getCoverDate());
130: } else if ($this->getCoverDisplayDate() != null) {
131: $date = date_parse($this->getCoverDisplayDate());
132: }
133: return (isset($date)) ? $date['year'] : null;
134: }
135:
136: //Entry di SEARCH_AUTHOR_URI
137: public function getPreferredName()
138: {
139: if (!isset($this->data['preferred-name'])) {
140: return null;
141: }
142:
143: return $this->preferredName ?? $this->preferredName = new AuthorName($this->data['preferred-name']);
144: }
145:
146: public function getAffiliation()
147: {
148: return isset($this->data['affiliation-current']) ? $this->data['affiliation-current']['affiliation-name'] : null;
149: }
150:
151: public function getAuthorID()
152: {
153: $identifier = $this->getIdentifier();
154: if (substr($identifier, 0, 10) === 'AUTHOR_ID:') {
155: return explode(':', $identifier, 2)[1];
156: }
157:
158: return null;
159: }
160:
161: public function isEmpty()
162: {
163: return isset($this->data['error']);
164: }
165:
166: public function isOpenAccess()
167: {
168: if (isset($this->data["openaccessFlag"])) return $this->data["openaccessFlag"];
169: return (isset($this->data["openaccess"]) && $this->data["openaccess"] == "1") ? true : false;
170: }
171: }
172: