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