1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SCI; |
4
|
|
|
|
5
|
|
|
use SMW\Subobject; |
6
|
|
|
use SMW\DIWikiPage; |
7
|
|
|
use SMW\DIProperty; |
8
|
|
|
use SMWDIContainer as DIContainer; |
9
|
|
|
use SMWContainerSemanticData as ContainerSemanticData; |
10
|
|
|
use SMW\DataValueFactory; |
11
|
|
|
use SMW\SemanticData; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @license GNU GPL v2+ |
15
|
|
|
* @since 1.0 |
16
|
|
|
* |
17
|
|
|
* @author mwjames |
18
|
|
|
*/ |
19
|
|
|
class CitationMeta { |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var CitationReferencePositionJournal |
23
|
|
|
*/ |
24
|
|
|
private $citationReferencePositionJournal = null; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var boolean |
28
|
|
|
*/ |
29
|
|
|
private $isEnabled = false; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @since 1.1 |
33
|
|
|
* |
34
|
|
|
* @param CitationReferencePositionJournal $citationReferencePositionJournal |
35
|
|
|
*/ |
36
|
14 |
|
public function __construct( CitationReferencePositionJournal $citationReferencePositionJournal ) { |
37
|
14 |
|
$this->citationReferencePositionJournal = $citationReferencePositionJournal; |
38
|
14 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @since 1.1 |
42
|
|
|
* |
43
|
|
|
* @param $isEnabled boolean |
44
|
|
|
*/ |
45
|
14 |
|
public function setEnabledState( $isEnabled ) { |
46
|
14 |
|
$this->isEnabled = (bool)$isEnabled; |
47
|
14 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @since 1.1 |
51
|
|
|
* |
52
|
|
|
* @param SemanticData $semanticData |
53
|
|
|
* |
54
|
|
|
* @return boolean |
55
|
|
|
*/ |
56
|
14 |
|
public function addMetaRecordToSemanticData( SemanticData $semanticData ) { |
57
|
|
|
|
58
|
14 |
|
if ( !$this->isEnabled ) { |
59
|
14 |
|
return false; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$containerSemanticData = $this->tryToCollectCitationFrequency( |
63
|
|
|
$semanticData->getSubject() |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
if ( $containerSemanticData === null || $containerSemanticData->isEmpty() ) { |
67
|
|
|
return false; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$semanticData->addPropertyObjectValue( |
71
|
|
|
new DIProperty( PropertyRegistry::SCI_CITE_META ), |
72
|
|
|
new DIContainer( $containerSemanticData ) |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
return true; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
private function tryToCollectCitationFrequency( DIWikiPage $subject ) { |
79
|
|
|
|
80
|
|
|
$journal = $this->citationReferencePositionJournal->getJournalBySubject( $subject ); |
81
|
|
|
|
82
|
|
|
if ( $journal === array() || !isset( $journal['reference-list'] ) ) { |
83
|
|
|
return null; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$subWikiPage = new DIWikiPage( |
87
|
|
|
$subject->getDBkey(), |
88
|
|
|
$subject->getNamespace(), |
89
|
|
|
$subject->getInterwiki(), |
90
|
|
|
'sci.meta' |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
$containerSemanticData = new ContainerSemanticData( $subWikiPage ); |
94
|
|
|
|
95
|
|
|
foreach ( $journal['reference-list'] as $hash => $citationKey ) { |
96
|
|
|
|
97
|
|
|
if ( !isset( $journal['reference-pos'][$hash] ) ) { |
98
|
|
|
continue; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
$this->addFrequencyRecord( |
102
|
|
|
$containerSemanticData, |
103
|
|
|
$subject, |
104
|
|
|
$citationKey, |
105
|
|
|
count( $journal['reference-pos'][$hash] ) |
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return $containerSemanticData; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
private function addFrequencyRecord( $containerSemanticData, $subject, $citationKey, $count ) { |
113
|
|
|
|
114
|
|
|
$dataValue = DataValueFactory::getInstance()->newPropertyObjectValue( |
115
|
|
|
new DIProperty( PropertyRegistry::SCI_CITE_FREQUENCY ), |
116
|
|
|
$citationKey . ';' . $count, |
|
|
|
|
117
|
|
|
false, |
118
|
|
|
$subject |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
$containerSemanticData->addDataValue( $dataValue ); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: