Exemplo n.º 1
0
 public function testGetClearedLicenses()
 {
     $user = 1;
     $groupId = 601;
     $rf = 401;
     $isRm = false;
     $t = -10815;
     $item = 303;
     $this->buildProposals(array(array($item, $user, $groupId, $rf, $isRm, $t), array($item, $user, $groupId, $rf + 1, !$isRm, $t + 1)), $eventId = 0);
     $type = DecisionTypes::IDENTIFIED;
     $scope = DecisionScopes::ITEM;
     $this->buildDecisions(array(array($item, $user, $groupId, $type, $t, $scope, array($eventId, $eventId + 1))));
     $treeBounds = M::mock(ItemTreeBounds::classname());
     $treeBounds->shouldReceive('getLeft')->andReturn(1);
     $treeBounds->shouldReceive('getRight')->andReturn(8);
     $treeBounds->shouldReceive('getUploadTreeTableName')->andReturn("uploadtree");
     $treeBounds->shouldReceive('getUploadId')->andReturn(102);
     $map = $this->clearingDao->getClearedLicenses($treeBounds, $groupId);
     assertThat($map, equalTo(array(new LicenseRef($rf, 'FOO', 'foo full'))));
 }
Exemplo n.º 2
0
 /**
  * @param array $child
  * @param int $uploadId
  * @param int $selectedAgentId
  * @param array $pfileLicenses
  * @param int $groupId
  * @param ClearingDecision[][] $editedMappedLicenses
  * @param string $uri
  * @param null|ClearingView $ModLicView
  * @param array $UniqueTagArray
  * @param boolean $isFlat
  * @param int[] $latestSuccessfulAgentIds
  * @return array
  */
 private function createFileDataRow($child, $uploadId, $selectedAgentId, $pfileLicenses, $groupId, $editedMappedLicenses, $uri, $ModLicView, &$UniqueTagArray, $isFlat, $latestSuccessfulAgentIds)
 {
     $fileId = $child['pfile_fk'];
     $childUploadTreeId = $child['uploadtree_pk'];
     $linkUri = '';
     if (!empty($fileId) && !empty($ModLicView)) {
         $linkUri = Traceback_uri();
         $linkUri .= "?mod=view-license&upload={$uploadId}&item={$childUploadTreeId}";
         if ($selectedAgentId) {
             $linkUri .= "&agentId={$selectedAgentId}";
         }
     }
     /* Determine link for containers */
     $isContainer = Iscontainer($child['ufile_mode']);
     if ($isContainer && !$isFlat) {
         $fatChild = $this->uploadDao->getFatItemArray($child['uploadtree_pk'], $uploadId, $this->uploadtree_tablename);
         $uploadtree_pk = $fatChild['item_id'];
         $linkUri = "{$uri}&item=" . $uploadtree_pk;
         if ($selectedAgentId) {
             $linkUri .= "&agentId={$selectedAgentId}";
         }
         $child['ufile_name'] = $fatChild['ufile_name'];
         if (!Iscontainer($fatChild['ufile_mode'])) {
             $isContainer = false;
         }
     } else {
         if ($isContainer) {
             $uploadtree_pk = Isartifact($child['ufile_mode']) ? DirGetNonArtifact($childUploadTreeId, $this->uploadtree_tablename) : $childUploadTreeId;
             $linkUri = "{$uri}&item=" . $uploadtree_pk;
             if ($selectedAgentId) {
                 $linkUri .= "&agentId={$selectedAgentId}";
             }
         }
     }
     /* Populate the output ($VF) - file list */
     /* id of each element is its uploadtree_pk */
     $fileName = $child['ufile_name'];
     if ($isContainer) {
         $fileName = "<a href='{$linkUri}'><span style='color: darkblue'> <b>{$fileName}</b> </span></a>";
     } else {
         if (!empty($linkUri)) {
             $fileName = "<a href='{$linkUri}'>{$fileName}</a>";
         }
     }
     /* show licenses under file name */
     $childItemTreeBounds = new ItemTreeBounds($childUploadTreeId, $this->uploadtree_tablename, $child['upload_fk'], $child['lft'], $child['rgt']);
     if ($isContainer) {
         $agentFilter = $selectedAgentId ? array($selectedAgentId) : $latestSuccessfulAgentIds;
         $licenseEntries = $this->licenseDao->getLicenseShortnamesContained($childItemTreeBounds, $agentFilter, array());
         $editedLicenses = $this->clearingDao->getClearedLicenses($childItemTreeBounds, $groupId);
     } else {
         $licenseEntries = array();
         if (array_key_exists($fileId, $pfileLicenses)) {
             foreach ($pfileLicenses[$fileId] as $shortName => $rfInfo) {
                 $agentEntries = array();
                 foreach ($rfInfo as $agent => $match) {
                     $agentName = $this->agentNames[$agent];
                     $agentEntry = "<a href='?mod=view-license&upload={$child['upload_fk']}&item={$childUploadTreeId}&format=text&agentId={$match['agent_id']}&licenseId={$match['license_id']}#highlight'>" . $agentName . "</a>";
                     if ($match['match_percentage'] > 0) {
                         $agentEntry .= ": {$match['match_percentage']}%";
                     }
                     $agentEntries[] = $agentEntry;
                 }
                 $licenseEntries[] = $shortName . " [" . implode("][", $agentEntries) . "]";
             }
         }
         /* @var $decision ClearingDecision */
         if (false !== ($decision = $this->clearingFilter->getDecisionOf($editedMappedLicenses, $childUploadTreeId, $fileId))) {
             $editedLicenses = $decision->getPositiveLicenses();
         } else {
             $editedLicenses = array();
         }
     }
     $concludedLicenses = array();
     /** @var LicenseRef $licenseRef */
     foreach ($editedLicenses as $licenseRef) {
         $projectedId = $this->licenseProjector->getProjectedId($licenseRef->getId());
         $projectedName = $this->licenseProjector->getProjectedShortname($licenseRef->getId(), $licenseRef->getShortName());
         $concludedLicenses[$projectedId] = $projectedName;
     }
     $editedLicenseList = implode(', ', $concludedLicenses);
     $licenseList = implode(', ', $licenseEntries);
     $fileListLinks = FileListLinks($uploadId, $childUploadTreeId, 0, $fileId, true, $UniqueTagArray, $this->uploadtree_tablename, !$isFlat);
     $getTextEditUser = _("Edit");
     $fileListLinks .= "[<a href='#' onclick='openUserModal({$childUploadTreeId})' >{$getTextEditUser}</a>]";
     if ($isContainer) {
         $getTextEditBulk = _("Bulk");
         $fileListLinks .= "[<a href='#' onclick='openBulkModal({$childUploadTreeId})' >{$getTextEditBulk}</a>]";
     }
     $filesThatShouldStillBeCleared = array_key_exists($childItemTreeBounds->getItemId(), $this->filesThatShouldStillBeCleared) ? $this->filesThatShouldStillBeCleared[$childItemTreeBounds->getItemId()] : 0;
     $filesToBeCleared = array_key_exists($childItemTreeBounds->getItemId(), $this->filesToBeCleared) ? $this->filesToBeCleared[$childItemTreeBounds->getItemId()] : 0;
     $filesCleared = $filesToBeCleared - $filesThatShouldStillBeCleared;
     $img = $filesCleared == $filesToBeCleared ? 'green' : 'red';
     return array($fileName, $licenseList, $editedLicenseList, $img, "{$filesCleared}/{$filesToBeCleared}", $fileListLinks);
 }