9 namespace Fossology\Lib\View;
18 const LEVEL =
'level';
19 const ACTION =
'action';
20 const ENTRY =
'entry';
21 const REF_TEXT_MAX_LENGTH = 100;
26 public function __construct(
LicenseDao $licenseDao)
28 $this->licenseDao = $licenseDao;
35 public function addReferenceTexts(&$highlights, $groupId=
null)
38 foreach ($highlights as &$highlight) {
39 if ($highlight->hasLicenseId()) {
40 $licenseId = $highlight->getLicenseId();
42 if (!array_key_exists($licenseId, $licenses)) {
43 $licenses[$licenseId] = $this->licenseDao->getLicenseById($licenseId, $groupId);
48 $license = $licenses[$licenseId];
49 $licenseReferenceText =
": '" . $this->
getReferenceText($license, $highlight) .
"'";
50 $includeReferenceText = $highlight->getType() != Highlight::MATCH && $highlight->getRefLength() > 0;
51 $infoText = $license->getShortName() . ($includeReferenceText ? $licenseReferenceText :
"");
52 $highlight->setInfoText($infoText);
65 return $referenceText . ($highlight->
getRefLength() > self::REF_TEXT_MAX_LENGTH ?
" ... " :
"");
75 if (empty($highlights)) {
82 $this->filterMultipleAtomEntries($splitPositions);
86 return $splitPositions;
95 $excludedTypesSet = array();
96 foreach ($excludedTypes as $type) {
97 $excludedTypesSet[$type] = $type;
100 $highlights = array_unique($highlights, SORT_REGULAR);
103 $currentPosition = 0;
105 foreach ($highlights as $key => $highlight) {
106 $isExcludedType = array_key_exists($highlight->getType(), $excludedTypesSet);
107 if ($isExcludedType) {
110 if ($highlight->getEnd() > $currentPosition) {
111 $startPosition =
max($highlight->getStart(), $currentPosition);
112 $highlights[$key] =
new Highlight($startPosition, $highlight->getEnd(),
"any", $highlight->getRefStart(), $highlight->getRefEnd(), $highlight->getInfoText());
113 $currentPosition = $highlight->getEnd();
115 unset($highlights[$key]);
125 if (isset($highlights)) {
126 usort($highlights, array(get_class($this),
'startAndLengthFirstSorter'));
136 $splitPositions = array();
140 }
while (!empty($highlightInfos));
142 return $splitPositions;
153 $currentPosition = 0;
154 foreach ($highlightEntries as $key => &$highlightEntry) {
155 $start = $highlightEntry->getStart();
156 $end = $highlightEntry->getEnd();
158 if ($start >= $currentPosition) {
161 ksort($splitPositions);
162 $currentPosition = $end;
164 unset($highlightEntries[$key]);
178 $start = $highlightEntry->getStart();
179 $end = $highlightEntry->getEnd();
181 $splitStart = $start;
182 foreach ($splitPositions as $splitPosition => $dummy) {
183 if ($start < $splitPosition && $splitPosition < $end) {
185 $splitStart = $splitPosition;
199 $level, $highlightEntry)
201 if ($start == $end) {
202 $splitPositions[$start][] =
new SplitPosition($level, SplitPosition::ATOM, $highlightEntry);
204 $splitPositions[$start][] =
new SplitPosition($level, SplitPosition::START, $highlightEntry);
205 $splitPositions[$end][] =
new SplitPosition($level, SplitPosition::END, $highlightEntry);
228 $leftAction = $leftAction == SplitPosition::ATOM ? SplitPosition::START : $leftAction;
229 $rightAction = $rightAction == SplitPosition::ATOM ? SplitPosition::START : $rightAction;
231 if ($leftAction != $rightAction) {
232 return strcasecmp($leftAction, $rightAction);
234 return ($leftAction == SplitPosition::START ? 1 : -1) * $this->compare($a->
getLevel(), $b->
getLevel());
238 private function compare($a, $b)
243 return ($a < $b) ? -1 : 1;
249 private function filterMultipleAtomEntries(&$splitPositions)
251 foreach ($splitPositions as &$splitPositionEntries) {
254 foreach ($splitPositionEntries as $key => $entry) {
258 if ($entry->getAction() == SplitPosition::ATOM) {
260 unset($splitPositionEntries[$key]);
267 unset($splitPositionEntries);
276 foreach ($splitPositions as &$splitPositionEntries) {
277 usort($splitPositionEntries, array(get_class($this),
'splitPositionEntrySorter'));
279 unset($splitPositionEntries);
addAllSplitPositions(&$splitPositions, $level, $highlightEntry)
startAndLengthFirstSorter(Highlight $a, Highlight $b)
getReferenceText(License $license, Highlight $highlight)
sortHighlights(&$highlights)
flattenHighlights(&$highlights, $excludedTypes=array())
addSingleSectionSplitPositions(&$splitPositions, $start, $end, $level, $highlightEntry)
addHighlightingLayer(&$highlightEntries, &$splitPositions, $level)
calculateSplitPositions($highlights)
getSplitPositions($highlightInfos)
sortSplitPositionEntries(&$splitPositions)
FUNCTION int max(int permGroup, int permPublic)
Get the maximum group privilege.
FUNCTION int min(int user_perm, int permExternal)
Get the minimum permission level required.