1: <?php
2:
3: namespace Scopus\Response;
4:
5: class AbstractCitations
6: {
7: /** @var array */
8: protected $data;
9:
10: /** @var AbstractCoredata[] */
11: protected $identifiers;
12:
13: /** @var CiteInfo[] */
14: protected $citeInfos;
15:
16: /** @var CiteCountHeader */
17: protected $citeCountHeader;
18:
19: public function __construct(array $data)
20: {
21: $this->data = $data;
22: }
23:
24: public function getHindex()
25: {
26: return $this->data['h-index'];
27: }
28:
29: public function getIdentifiers()
30: {
31: if (isset($this->data['identifier-legend']['identifier'])) {
32: return $this->identifiers ?: $this->identifiers = array_map(function ($identifier) {
33: return new AbstractCoredata($identifier);
34: }, $this->data['identifier-legend']['identifier']);
35: }
36: return null;
37: }
38:
39: public function getCiteInfos()
40: {
41: if (isset($this->data['citeInfoMatrix']['citeInfoMatrixXML']['citationMatrix']['citeInfo'])) {
42: return $this->citeInfos ?: $this->citeInfos = array_map(function ($citeInfo) {
43: return new CiteInfo($citeInfo);
44: }, $this->data['citeInfoMatrix']['citeInfoMatrixXML']['citationMatrix']['citeInfo']);
45: }
46: return null;
47: }
48:
49: public function getCiteCountHeader()
50: {
51: if (isset($this->data['citeColumnTotalXML']['citeCountHeader']))
52: return $this->citeCountHeader ?? $this->citeCountHeader = new CiteCountHeader($this->data['citeColumnTotalXML']['citeCountHeader']);
53:
54: return null;
55: }
56:
57: /**
58: * Extracts the citations per year of each document
59: * @return array [document_scopus_id => [year => value ]]
60: */
61: public function getCompactInfo()
62: {
63: $header = $this->getCiteCountHeader();
64: if (!$header) return null;
65:
66: $clmHeader = $header->getColumnHeading();
67: $citeInfos = $this->getCiteInfos();
68:
69: if (!$clmHeader || !$citeInfos) return null;
70: if (!is_array($clmHeader)) return [$citeInfos[0]->getScopusId() => [$clmHeader => $citeInfos[0]->getColumnCount()]];
71:
72: $compactData = [];
73: foreach ($citeInfos as $citeInfo) {
74: foreach ($clmHeader as $index => $value) {
75: $compactData[$citeInfo->getScopusId()][$value["$"]] = $citeInfo->getColumnCount()[$index]["$"];
76: }
77: }
78: return $compactData;
79: }
80:
81: /**
82: * Extracts total citations per year
83: * @return array [year => value ]
84: */
85: public function getTotalCompactInfo()
86: {
87: $header = $this->getCiteCountHeader();
88: if (!$header) return null;
89:
90: $clmHeader = $header->getColumnHeading();
91: $clmCount = $header->getColumnTotal();
92:
93: if (!$clmHeader || !$clmCount) return null;
94: if (!is_array($clmHeader)) $clmHeader = [$clmHeader];
95:
96: $compactData = [];
97: $compactData["citation_previous_dates"] = $header->getPrevColumnTotal();
98: $compactData["citation_subsequent_dates"] = $header->getLaterColumnTotal();
99:
100: foreach ($clmHeader as $index => $value)
101: $compactData[$value["$"]] = $clmCount[$index]["$"];
102:
103: return $compactData;
104: }
105: }
106: