41 const OPTION_SKIP_FILE =
"option_skipFile";
42 const OPTION_SKIP_FILE_COPYRIGHT =
"option_skipFileCopyRight";
43 const OPTION_SKIP_FILE_IP =
"option_skipFileIp";
44 const OPTION_SKIP_FILE_ECC =
"option_skipFileEcc";
45 const OPTION_SKIP_FILE_KEYWORD =
"option_skipFileKeyword";
58 private $highlightDao;
60 private $highlightProcessor;
62 private $clearingDecisionEventProcessor;
66 private $decisionTypes;
68 function __construct()
70 $this->Name =
"conclude-license";
71 $this->Title = _(
"Change concluded License ");
73 $this->Dependency = array(
"view");
76 $this->OutputType =
'JSON';
77 $this->OutputToStdout =
true;
78 parent::__construct();
81 $this->licenseDao = $container->get(
'dao.license');
82 $this->uploadDao = $container->get(
'dao.upload');
83 $this->clearingDao = $container->get(
'dao.clearing');
84 $this->agentsDao = $container->get(
'dao.agent');
85 $this->logger = $container->get(
"logger");
87 $this->highlightDao = $container->get(
"dao.highlight");
88 $this->highlightProcessor = $container->get(
"view.highlight_processor");
89 $this->urlBuilder = $container->get(
'view.url_builder');
90 $this->decisionTypes = $container->get(
'decision.types');
91 $this->clearingDecisionEventProcessor = $container->get(
'businessrules.clearing_decision_processor');
102 $itemTreeBounds = $this->uploadDao->getItemTreeBoundsFromUploadId($uploadTreeId, $uploadId);
104 $clearingDecWithLicenses = $this->clearingDao->getFileClearings($itemTreeBounds, $groupId,
false,
true);
108 foreach ($clearingDecWithLicenses as $clearingDecision) {
109 $licenseOutputs = array();
110 foreach ($clearingDecision->getClearingLicenses() as $lic) {
111 $shortName = $lic->getShortName();
112 $licenseOutputs[$shortName] = $lic->isRemoved() ?
"<span style=\"color:red\">$shortName</span>" : $shortName;
114 ksort($licenseOutputs, SORT_STRING);
116 '0' => date(
'Y-m-d', $clearingDecision->getTimeStamp()),
117 '1' => $clearingDecision->getUserName(),
118 '2' => $scope->getTypeName($clearingDecision->getScope()),
119 '3' => $this->decisionTypes->getTypeName($clearingDecision->getType()),
120 '4' => implode(
", ", $licenseOutputs)
125 'sEcho' => intval($_GET[
'sEcho']),
127 'iTotalRecords' => count($table),
128 'iTotalDisplayRecords' => count($table)
139 protected function doLicenses($orderAscending, $groupId, $uploadId,
142 $itemTreeBounds = $this->uploadDao->getItemTreeBoundsFromUploadId(
143 $uploadTreeId, $uploadId);
145 list ($licenseDecisions, $removed) = $this->clearingDecisionEventProcessor->getCurrentClearings($itemTreeBounds, $groupId);
147 $licenseRefs = $this->licenseDao->getConclusionLicenseRefs(Auth::getGroupId(), $_GET[
'sSearch'], $orderAscending, array_keys($licenseDecisions));
149 foreach ($licenseRefs as $licenseRef) {
150 $licenseId = $licenseRef->getId();
151 $shortNameWithFullTextLink = $this->urlBuilder->getLicenseTextUrl($licenseRef);
152 $actionLink =
"<a href=\"javascript:;\" onClick=\"addLicense($uploadId, $uploadTreeId, $licenseId);\">" 153 .
"<img src=\"images/space_16.png\" class=\"add\"/></a>";
155 $licenses[] = array($shortNameWithFullTextLink, $actionLink);
158 'sEcho' => intval($_GET[
'sEcho']),
159 'aaData' => $licenses,
160 'iTotalRecords' => count($licenses),
161 'iTotalDisplayRecords' => count($licenses));
172 protected function doClearings($orderAscending, $groupId, $uploadId, $uploadTreeId)
174 $itemTreeBounds = $this->uploadDao->getItemTreeBoundsFromUploadId($uploadTreeId, $uploadId);
176 $groupId, $orderAscending);
179 'sEcho' => intval($_GET[
'sEcho']),
181 'iTotalRecords' => count($aaData),
182 'iTotalDisplayRecords' => count($aaData)
191 $userId = Auth::getUserId();
192 $groupId = Auth::getGroupId();
199 $orderAscending = isset($sort0) ? $sort0 ===
"asc" :
true;
203 return new JsonResponse(
204 $this->
doLicenses($orderAscending, $groupId, $uploadId, $uploadTreeId));
206 case "licenseDecisions":
207 return new JsonResponse(
208 $this->
doClearings($orderAscending, $groupId, $uploadId, $uploadTreeId));
211 $this->clearingDao->insertClearingEvent($uploadTreeId, $userId, $groupId,
212 $licenseId,
false, ClearingEventTypes::USER);
213 return new JsonResponse();
215 case "removeLicense":
216 $this->clearingDao->insertClearingEvent($uploadTreeId, $userId, $groupId,
217 $licenseId,
true, ClearingEventTypes::USER);
218 return new JsonResponse();
220 case "makeMainLicense":
221 $this->clearingDao->makeMainLicense($uploadId, $groupId, $licenseId);
222 return new JsonResponse();
224 case "removeMainLicense":
225 $this->clearingDao->removeMainLicense($uploadId, $groupId, $licenseId);
226 return new JsonResponse();
229 case "setNextPrevCopyRight":
230 case "setNextPrevIp":
231 case "setNextPrevEcc":
232 case "setNextPrevKeyword":
233 return new JsonResponse(
234 $this->
doNextPrev($action, $uploadId, $uploadTreeId, $groupId));
236 case "updateClearings":
239 list ($uploadTreeId, $licenseId) = explode(
',', $id);
242 $what =
'reportinfo';
243 } elseif ($what==3) {
244 $what =
'acknowledgement';
249 $this->clearingDao->updateClearingEvent($uploadTreeId, $userId, $groupId, $licenseId, $what, $changeTo);
253 case "showClearingHistory":
254 return new JsonResponse($this->
doClearingHistory($groupId, $uploadId, $uploadTreeId));
256 case "checkCandidateLicense":
257 if (!empty($this->clearingDao->getCandidateLicenseCountForCurrentDecisions($uploadTreeId))) {
273 $classAttr =
"color:#000000;";
274 $value =
"Click to add";
275 if (empty($forValue) && $detectorType == 2 && $what == 2) {
276 $classAttr =
"color:red;font-weight:bold;";
279 if (!empty($forValue)) {
280 $value = substr(ltrim($forValue,
" \t\n"), 0, 15).
"...";
282 return "<a href=\"javascript:;\" style='$classAttr' id='clearingsForSingleFile$licenseId$what' onclick=\"openTextModel($uploadTreeId, $licenseId, $what);\" title='".htmlspecialchars($forValue, ENT_QUOTES).
"'>$value</a>";
293 $uploadTreeId = $itemTreeBounds->
getItemId();
300 list ($addedClearingResults, $removedLicenses) = $this->clearingDecisionEventProcessor->getCurrentClearings(
301 $itemTreeBounds, $groupId, LicenseMap::CONCLUSION);
304 $mainLicIds = $this->clearingDao->getMainLicenseIds($uploadId, $groupId);
308 foreach ($addedClearingResults as $licenseShortName => $clearingResult) {
309 $licenseId = $clearingResult->getLicenseId();
311 $types = $this->
getAgentInfo($clearingResult, $uberUri, $uploadTreeId);
314 $acknowledgement =
"";
316 if ($clearingResult->hasClearingEvent()) {
317 $licenseDecisionEvent = $clearingResult->getClearingEvent();
318 $types[] = $this->getEventInfo($licenseDecisionEvent, $uberUri,
319 $uploadTreeId, $licenseEventTypes);
320 $reportInfo = $licenseDecisionEvent->getReportinfo();
321 $comment = $licenseDecisionEvent->getComment();
322 $acknowledgement = $licenseDecisionEvent->getAcknowledgement();
325 $licenseShortNameWithLink = $this->urlBuilder->getLicenseTextUrl(
326 $clearingResult->getLicenseRef());
327 $actionLink =
"<a href=\"javascript:;\" onclick=\"removeLicense($uploadId, $uploadTreeId, $licenseId);\"><img class=\"delete\" src=\"images/space_16.png\" alt=\"\"/></a>";
328 if (in_array($clearingResult->getLicenseId(), $mainLicIds)) {
329 $tooltip = _(
'This is a main license for the upload. Click to discard selection.');
330 $actionLink .=
" <a href=\"javascript:;\" onclick=\"removeMainLicense($uploadId, $licenseId);\"><img src=\"images/icons/star_filled_16.png\" alt=\"mainLicense\" title=\"$tooltip\" border=\"0\"/></a>";
332 $tooltip = _(
'Click to select this as a main license for the upload.');
333 $actionLink .=
" <a href=\"javascript:;\" onclick=\"makeMainLicense($uploadId, $licenseId);\"><img src=\"images/icons/star_16.png\" alt=\"noMainLicense\" title=\"$tooltip\" border=\"0\"/></a>";
335 $detectorType = $this->licenseDao->getLicenseById($clearingResult->getLicenseId(), $groupId)->getDetectorType();
336 $id =
"$uploadTreeId,$licenseId";
341 $table[$licenseShortName] = array(
'DT_RowId' => $id,
343 '1' => $licenseShortNameWithLink,
344 '2' => implode(
"<br/>", $types),
345 '3' => $reportInfoField,
346 '4' => $acknowledgementField,
347 '5' => $commentField);
350 foreach ($removedLicenses as $licenseShortName => $clearingResult) {
351 if ($clearingResult->getAgentDecisionEvents()) {
352 $agents = $this->
getAgentInfo($clearingResult, $uberUri, $uploadTreeId);
353 $licenseShortNameWithLink = $this->urlBuilder->getLicenseTextUrl($clearingResult->getLicenseRef());
354 $licenseId = $clearingResult->getLicenseId();
355 $actionLink =
"<a href=\"javascript:;\" onclick=\"addLicense($uploadId, $uploadTreeId, $licenseId);\"><img class=\"add\" src=\"images/space_16.png\" alt=\"\"/></a>";
356 $filled = in_array($clearingResult->getLicenseId(), $mainLicIds) ?
'filled_' :
'';
357 $actionLink .=
' <img src="images/icons/star_'.$filled.
'16.png" alt="mainLicense"/>';
359 $idArray = array($uploadTreeId, $licenseId);
360 $id = implode(
',', $idArray);
361 $table[$licenseShortName] = array(
'DT_RowId' => $id,
362 'DT_RowClass' =>
'removed',
364 '1' => $licenseShortNameWithLink,
365 '2' => implode(
"<br/>", $agents),
372 $valueTable = array_values($this->
sortByKeys($table, $orderAscending));
382 protected function getAgentInfo($licenseDecisionResult, $uberUri, $uploadTreeId)
384 $agentResults = array();
385 foreach ($licenseDecisionResult->getAgentDecisionEvents() as $agentDecisionEvent) {
386 $agentId = $agentDecisionEvent->getAgentId();
387 $matchId = $agentDecisionEvent->getMatchId();
388 $percentage = $agentDecisionEvent->getPercentage();
389 $page = $this->highlightDao->getPageNumberOfHighlightEntry($matchId);
390 $agentResults[$agentDecisionEvent->getAgentName()][] = array(
391 "uri" => $uberUri .
"&item=$uploadTreeId&agentId=$agentId&highlightId=$matchId&page=$page#highlight",
392 "text" => $percentage ?
" (" . $percentage .
" %)" :
"" 397 foreach ($agentResults as $agentName => $agentResult) {
398 $matchTexts = array();
400 foreach ($agentResult as $index => $agentData) {
401 $uri = $agentData[
'uri'];
402 $matchTexts[] =
"<a href=\"$uri\">#" . ($index + 1) .
"</a>" . $agentData[
'text'];
404 $results[] = $agentName .
": " . implode(
', ', $matchTexts);
414 protected function sortByKeys($arrayToBeSortedByKeys, $orderAscending)
416 ksort($arrayToBeSortedByKeys, SORT_STRING);
418 if ($orderAscending) {
419 $arrayToBeSortedByKeys = array_reverse($arrayToBeSortedByKeys);
420 return $arrayToBeSortedByKeys;
422 return $arrayToBeSortedByKeys;
432 protected function doNextPrev($action, $uploadId, $uploadTreeId, $groupId)
436 $modName =
"view-license";
437 $opt = self::OPTION_SKIP_FILE;
440 case "setNextPrevCopyRight":
441 $modName =
"copyright-view";
442 $opt = self::OPTION_SKIP_FILE_COPYRIGHT;
445 case "setNextPrevIp":
446 $modName =
"ip-view";
447 $opt = self::OPTION_SKIP_FILE_IP;
450 case "setNextPrevEcc":
451 $modName =
"ecc-view";
452 $opt = self::OPTION_SKIP_FILE_ECC;
454 case "setNextPrevKeyword":
455 $modName =
"keyword-view";
456 $opt = self::OPTION_SKIP_FILE_KEYWORD;
462 $prevItem = $this->uploadDao->getPreviousItem($uploadId, $uploadTreeId, $options);
463 $prevItemId = $prevItem ? $prevItem->getId() : null;
465 $nextItem = $this->uploadDao->getNextItem($uploadId, $uploadTreeId, $options);
466 $nextItemId = $nextItem ? $nextItem->getId() : null;
468 return array(
'prev' => $prevItemId,
'next' => $nextItemId,
478 return new Response($output, Response::HTTP_OK, array(
'Content-type' =>
'text/plain'));
481 private function getEventInfo($licenseDecisionEvent, $uberUri, $uploadTreeId, $licenseEventTypes)
483 $type = $licenseEventTypes->getTypeName($licenseDecisionEvent->getEventType());
484 if ($licenseDecisionEvent->getEventType() == ClearingEventTypes::BULK) {
485 $eventId = $licenseDecisionEvent->getEventId();
486 $type .=
': <a href="'.$uberUri.
"&item=$uploadTreeId&clearingId=".$eventId.
'#highlight">#'.$eventId.
'</a>';
doClearings($orderAscending, $groupId, $uploadId, $uploadTreeId)
Traceback_uri()
Get the URI without query to this location.
getBuildClearingsForSingleFile($uploadTreeId, $licenseId, $forValue, $what, $detectorType=0)
createPlainResponse($output)
doClearingHistory($groupId, $uploadId, $uploadTreeId)
getCurrentSelectedLicensesTableData(ItemTreeBounds $itemTreeBounds, $groupId, $orderAscending)
doNextPrev($action, $uploadId, $uploadTreeId, $groupId)
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
sortByKeys($arrayToBeSortedByKeys, $orderAscending)
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
getAgentInfo($licenseDecisionResult, $uberUri, $uploadTreeId)
This is the Plugin class. All plugins should:
doLicenses($orderAscending, $groupId, $uploadId, $uploadTreeId)
Traceback_parm_keep($List)
Create a new URI, keeping only these items.