29 const LEVEL =
'level';
30 const ACTION =
'action';
31 const ENTRY =
'entry';
32 const REF_TEXT_MAX_LENGTH = 100;
37 public function __construct(
LicenseDao $licenseDao)
39 $this->licenseDao = $licenseDao;
46 public function addReferenceTexts(&$highlights, $groupId=null)
49 foreach ($highlights as &$highlight) {
50 if ($highlight->hasLicenseId()) {
51 $licenseId = $highlight->getLicenseId();
53 if (!array_key_exists($licenseId, $licenses)) {
54 $licenses[$licenseId] = $this->licenseDao->getLicenseById($licenseId, $groupId);
59 $license = $licenses[$licenseId];
60 $licenseReferenceText =
": '" . $this->
getReferenceText($license, $highlight) .
"'";
61 $includeReferenceText = $highlight->getType() != Highlight::MATCH && $highlight->getRefLength() > 0;
62 $infoText = $license->getShortName() . ($includeReferenceText ? $licenseReferenceText :
"");
63 $highlight->setInfoText($infoText);
76 return $referenceText . ($highlight->
getRefLength() > self::REF_TEXT_MAX_LENGTH ?
" ... " :
"");
86 if (empty($highlights)) {
93 $this->filterMultipleAtomEntries($splitPositions);
97 return $splitPositions;
106 $excludedTypesSet = array();
107 foreach ($excludedTypes as $type) {
108 $excludedTypesSet[$type] = $type;
111 $highlights = array_unique($highlights, SORT_REGULAR);
114 $currentPosition = 0;
116 foreach ($highlights as $key => $highlight) {
117 $isExcludedType = array_key_exists($highlight->getType(), $excludedTypesSet);
118 if ($isExcludedType) {
121 if ($highlight->getEnd() > $currentPosition) {
122 $startPosition =
max($highlight->getStart(), $currentPosition);
123 $highlights[$key] =
new Highlight($startPosition, $highlight->getEnd(),
"any", $highlight->getRefStart(), $highlight->getRefEnd(), $highlight->getInfoText());
124 $currentPosition = $highlight->
getEnd();
126 unset($highlights[$key]);
136 if (isset($highlights)) {
137 usort($highlights, array(get_class($this),
'startAndLengthFirstSorter'));
147 $splitPositions = array();
151 }
while (!empty($highlightInfos));
153 return $splitPositions;
164 $currentPosition = 0;
165 foreach ($highlightEntries as $key => &$highlightEntry) {
166 $start = $highlightEntry->getStart();
167 $end = $highlightEntry->getEnd();
169 if ($start >= $currentPosition) {
172 ksort($splitPositions);
173 $currentPosition = $end;
175 unset($highlightEntries[$key]);
189 $start = $highlightEntry->getStart();
190 $end = $highlightEntry->getEnd();
192 $splitStart = $start;
193 foreach ($splitPositions as $splitPosition => $dummy) {
194 if ($start < $splitPosition && $splitPosition < $end) {
196 $splitStart = $splitPosition;
210 $level, $highlightEntry)
212 if ($start == $end) {
213 $splitPositions[$start][] =
new SplitPosition($level, SplitPosition::ATOM, $highlightEntry);
215 $splitPositions[$start][] =
new SplitPosition($level, SplitPosition::START, $highlightEntry);
216 $splitPositions[$end][] =
new SplitPosition($level, SplitPosition::END, $highlightEntry);
239 $leftAction = $leftAction == SplitPosition::ATOM ? SplitPosition::START : $leftAction;
240 $rightAction = $rightAction == SplitPosition::ATOM ? SplitPosition::START : $rightAction;
242 if ($leftAction != $rightAction) {
243 return strcasecmp($leftAction, $rightAction);
245 return ($leftAction == SplitPosition::START ? 1 : -1) * $this->compare($a->
getLevel(), $b->
getLevel());
249 private function compare($a, $b)
254 return ($a < $b) ? -1 : 1;
260 private function filterMultipleAtomEntries(&$splitPositions)
262 foreach ($splitPositions as &$splitPositionEntries) {
265 foreach ($splitPositionEntries as $key => $entry) {
269 if ($entry->getAction() == SplitPosition::ATOM) {
271 unset($splitPositionEntries[$key]);
278 unset($splitPositionEntries);
287 foreach ($splitPositions as &$splitPositionEntries) {
288 usort($splitPositionEntries, array(get_class($this),
'splitPositionEntrySorter'));
290 unset($splitPositionEntries);
sortHighlights(&$highlights)
flattenHighlights(&$highlights, $excludedTypes=array())
addAllSplitPositions(&$splitPositions, $level, $highlightEntry)
FUNCTION int min(int user_perm, int permExternal)
Get the minimum permission level required.
calculateSplitPositions($highlights)
getReferenceText(License $license, Highlight $highlight)
addHighlightingLayer(&$highlightEntries, &$splitPositions, $level)
startAndLengthFirstSorter(Highlight $a, Highlight $b)
addSingleSectionSplitPositions(&$splitPositions, $start, $end, $level, $highlightEntry)
FUNCTION int max(int permGroup, int permPublic)
Get the maximum group privilege.
sortSplitPositionEntries(&$splitPositions)
getSplitPositions($highlightInfos)