/** * @param ItemTreeBounds $itemTreeBounds * @param int $groupId * @param boolean $orderAscending * @return array */ protected function getCurrentSelectedLicensesTableData(ItemTreeBounds $itemTreeBounds, $groupId, $orderAscending) { $uploadTreeId = $itemTreeBounds->getItemId(); $uploadId = $itemTreeBounds->getUploadId(); $uberUri = Traceback_uri() . "?mod=view-license" . Traceback_parm_keep(array('upload', 'folder')); list($addedClearingResults, $removedLicenses) = $this->clearingDecisionEventProcessor->getCurrentClearings($itemTreeBounds, $groupId, LicenseMap::CONCLUSION); $licenseEventTypes = new ClearingEventTypes(); $mainLicIds = $this->clearingDao->getMainLicenseIds($uploadId, $groupId); $table = array(); /* @var $clearingResult ClearingResult */ foreach ($addedClearingResults as $licenseShortName => $clearingResult) { $licenseId = $clearingResult->getLicenseId(); $types = $this->getAgentInfo($clearingResult, $uberUri, $uploadTreeId); $reportInfo = ""; $comment = ""; if ($clearingResult->hasClearingEvent()) { $licenseDecisionEvent = $clearingResult->getClearingEvent(); $types[] = $this->getEventInfo($licenseDecisionEvent, $uberUri, $uploadTreeId, $licenseEventTypes); $reportInfo = $licenseDecisionEvent->getReportinfo(); $comment = $licenseDecisionEvent->getComment(); } $licenseShortNameWithLink = $this->urlBuilder->getLicenseTextUrl($clearingResult->getLicenseRef()); $actionLink = "<a href=\"javascript:;\" onclick=\"removeLicense({$uploadId}, {$uploadTreeId}, {$licenseId});\"><img class=\"delete\" src=\"images/space_16.png\" alt=\"\"/></a>"; if (in_array($clearingResult->getLicenseId(), $mainLicIds)) { $tooltip = _('This is a main license for the upload. Click to discard selection.'); $actionLink .= " <a href=\"javascript:;\" onclick=\"removeMainLicense({$uploadId}, {$licenseId});\"><img src=\"images/icons/star_filled_16.png\" alt=\"mainLicense\" title=\"{$tooltip}\" border=\"0\"/></a>"; } else { $tooltip = _('Click to select this as a main license for the upload.'); $actionLink .= " <a href=\"javascript:;\" onclick=\"makeMainLicense({$uploadId}, {$licenseId});\"><img src=\"images/icons/star_16.png\" alt=\"noMainLicense\" title=\"{$tooltip}\" border=\"0\"/></a>"; } $reportInfoField = nl2br(htmlspecialchars($reportInfo)); $commentField = nl2br(htmlspecialchars($comment)); $id = "{$uploadTreeId},{$licenseId}"; $table[$licenseShortName] = array('DT_RowId' => $id, '0' => $licenseShortNameWithLink, '1' => implode("<br/>", $types), '2' => $reportInfoField, '3' => $commentField, '4' => $actionLink); } foreach ($removedLicenses as $licenseShortName => $clearingResult) { if ($clearingResult->getAgentDecisionEvents()) { $agents = $this->getAgentInfo($clearingResult, $uberUri, $uploadTreeId); $licenseShortNameWithLink = $this->urlBuilder->getLicenseTextUrl($clearingResult->getLicenseRef()); $licenseId = $clearingResult->getLicenseId(); $actionLink = "<a href=\"javascript:;\" onclick=\"addLicense({$uploadId}, {$uploadTreeId}, {$licenseId});\"><img class=\"add\" src=\"images/space_16.png\" alt=\"\"/></a>"; $filled = in_array($clearingResult->getLicenseId(), $mainLicIds) ? 'filled_' : ''; $actionLink .= ' <img src="images/icons/star_' . $filled . '16.png" alt="mainLicense"/>'; $idArray = array($uploadTreeId, $licenseId); $id = implode(',', $idArray); $table[$licenseShortName] = array('DT_RowId' => $id, 'DT_RowClass' => 'removed', '0' => $licenseShortNameWithLink, '1' => implode("<br/>", $agents), '2' => "-", '3' => "-", '4' => $actionLink); } } $valueTable = array_values($this->sortByKeys($table, $orderAscending)); return $valueTable; }
public function testGetCurrentClearingsWithUserRemovedDecisionsOnly() { /** @var LicenseRef $licenseRef */ list($scannerResults, $licenseRef, $agentRef) = $this->createScannerDetectedLicenses(); $removedEvent = $this->createClearingEvent(123, $this->timestamp, $licenseRef->getId(), $licenseRef->getShortName(), $licenseRef->getFullName(), ClearingEventTypes::USER, true); $this->agentLicenseEventProcessor->shouldReceive("getScannerEvents")->with($this->itemTreeBounds, LicenseMap::TRIVIAL)->andReturn($scannerResults); $this->clearingDao->shouldReceive("getRelevantClearingEvents")->with($this->itemTreeBounds, $this->groupId)->andReturn(array($licenseRef->getId() => $removedEvent)); list($licenseDecisions, $removedClearings) = $this->clearingDecisionProcessor->getCurrentClearings($this->itemTreeBounds, $this->groupId); assertThat($licenseDecisions, is(emptyArray())); assertThat($removedClearings, is(arrayWithSize(1))); /** @var ClearingResult $result */ $result = $removedClearings[$removedEvent->getLicenseId()]; assertThat($result->getLicenseRef(), is($removedEvent->getLicenseRef())); assertThat($result->getClearingEvent(), is($removedEvent)); $agentClearingEvents = $result->getAgentDecisionEvents(); assertThat($agentClearingEvents, is(arrayWithSize(1))); $agentEvent = $agentClearingEvents[0]; assertThat($agentEvent->getAgentRef(), is($agentRef)); assertThat($agentEvent->getLicenseRef(), is($licenseRef)); assertThat($agentEvent->getMatchId(), is(self::MATCH_ID)); assertThat($agentEvent->getPercentage(), is(self::PERCENTAGE)); }
/** * @brief extends standard Output to handle empty uploads */ function Output() { if ($this->invalidParm) { $this->vars['content'] = 'This upload contains no files!<br><a href="' . Traceback_uri() . '?mod=browse">Go back to browse view</a>'; return $this->render("include/base.html.twig"); } $uploadId = GetParm("upload", PARM_INTEGER); if (empty($uploadId)) { return new Response("", Response::HTTP_BAD_REQUEST); } $uploadTreeId = GetParm("item", PARM_INTEGER); if (empty($uploadTreeId)) { return new Response("", Response::HTTP_BAD_REQUEST); } $userId = Auth::getUserId(); $groupId = Auth::getGroupId(); $lastItem = GetParm("lastItem", PARM_INTEGER); if (!empty($lastItem)) { $this->updateLastItem($userId, $groupId, $lastItem); } $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId); $itemTreeBounds = $this->uploadDao->getItemTreeBounds($uploadTreeId, $uploadTreeTableName); $this->vars['micromenu'] = Dir2Browse('license', $uploadTreeId, NULL, $showBox = 0, "View", -1, '', '', $uploadTreeTableName); global $Plugins; /** @var ui_view $view */ $view =& $Plugins[plugin_find_id("view")]; $licenseId = GetParm("licenseId", PARM_INTEGER); $selectedAgentId = GetParm("agentId", PARM_INTEGER); $highlightId = GetParm("highlightId", PARM_INTEGER); $clearingId = GetParm("clearingId", PARM_INTEGER); if ($clearingId !== null) { $highlightId = -1; } else { if ($highlightId !== null) { $clearingId = -1; } } $baseUri = Traceback_uri(); $this->vars['baseuri'] = $baseUri; $this->vars['uri'] = $baseUri . "?mod=" . $this->Name . Traceback_parm_keep(array('upload', 'folder')); $this->vars['bulkHistoryHighlightUri'] = $this->vars['uri']; $this->vars['optionName'] = "skipFile"; $this->vars['formName'] = "uiClearingForm"; $this->vars['ajaxAction'] = "setNextPrev"; $highlights = $this->getSelectedHighlighting($itemTreeBounds, $licenseId, $selectedAgentId, $highlightId, $clearingId, $uploadId); $isSingleFile = !$itemTreeBounds->containsFiles(); $hasWritePermission = $this->uploadDao->isEditable($uploadId, $groupId); $clearingDecisions = null; if ($isSingleFile || $hasWritePermission) { $clearingDecisions = $this->clearingDao->getFileClearings($itemTreeBounds, $groupId, false); } if ($isSingleFile && $hasWritePermission) { $this->vars['bulkUri'] = Traceback_uri() . "?mod=popup-license"; $licenseArray = $this->licenseDao->getLicenseArray($groupId); // $clearingDecision = $this->clearingDao->getRelevantClearingDecision($itemTreeBounds, $groupId); list($addedResults, $removedResults) = $this->clearingDecisionEventProcessor->getCurrentClearings($itemTreeBounds, $groupId, LicenseMap::CONCLUSION); if (count($addedResults) + count($removedResults) > 0) { array_unshift($licenseArray, array('id' => 0, 'fullname' => '', 'shortname' => '------')); } /** @var ClearingResult $result */ foreach ($removedResults as $result) { array_unshift($licenseArray, array('id' => $result->getLicenseId(), 'fullname' => $result->getLicenseFullName(), 'shortname' => $result->getLicenseShortName())); } /** @var ClearingResult $result */ foreach ($addedResults as $result) { array_unshift($licenseArray, array('id' => $result->getLicenseId(), 'fullname' => $result->getLicenseFullName(), 'shortname' => $result->getLicenseShortName())); } $this->vars['licenseArray'] = $licenseArray; } elseif ($isSingleFile) { $this->vars['auditDenied'] = true; } $clearingHistory = array(); $selectedClearingType = false; if ($hasWritePermission) { $clearingHistory = $this->getClearingHistory($clearingDecisions); } if (count($clearingHistory) > 0) { $selectedClearingType = $this->decisionTypes->getTypeByName($clearingHistory[0]['type']); } $bulkHistory = $this->clearingDao->getBulkHistory($itemTreeBounds, $groupId); $ModBack = GetParm("modback", PARM_STRING) ?: "license"; list($pageMenu, $textView) = $view->getView(NULL, $ModBack, 0, "", $highlights, false, true); $this->vars['uploadId'] = $uploadId; $this->vars['itemId'] = $uploadTreeId; $this->vars['pageMenu'] = $pageMenu; $this->vars['textView'] = $textView; $this->vars['legendData'] = $this->highlightRenderer->getLegendData($selectedAgentId || $clearingId); $this->vars['clearingTypes'] = $this->decisionTypes->getMap(); $this->vars['selectedClearingType'] = $selectedClearingType; $this->vars['tmpClearingType'] = $this->clearingDao->isDecisionWip($uploadTreeId, $groupId); $this->vars['clearingHistory'] = $clearingHistory; $this->vars['bulkHistory'] = $bulkHistory; $noLicenseUploadTreeView = new UploadTreeProxy($uploadId, $options = array(UploadTreeProxy::OPT_SKIP_THESE => "noLicense", UploadTreeProxy::OPT_GROUP_ID => $groupId), $uploadTreeTableName, $viewName = 'no_license_uploadtree' . $uploadId); $filesOfInterest = $noLicenseUploadTreeView->count(); $nonClearedUploadTreeView = new UploadTreeProxy($uploadId, $options = array(UploadTreeProxy::OPT_SKIP_THESE => "alreadyCleared", UploadTreeProxy::OPT_GROUP_ID => $groupId), $uploadTreeTableName, $viewName = 'already_cleared_uploadtree' . $uploadId); $filesToBeCleared = $nonClearedUploadTreeView->count(); $filesAlreadyCleared = $filesOfInterest - $filesToBeCleared; $this->vars['message'] = _("Cleared") . ": {$filesAlreadyCleared}/{$filesOfInterest}"; return $this->render("ui-clearing-view.html.twig"); }