/** * \brief test for Isdir Isartifact Iscontainer */ function test_Is() { print "Starting unit test for common-dir.php\n"; print "test function Isdir()\n"; $mode = 536888320; $result = Isdir($mode); $this->assertEquals(true, $result); $mode = 33188; $result = Isdir($mode); $this->assertEquals(false, $result); print "test function Isartifact()\n"; $mode = 536888320; $result = Isartifact($mode); $this->assertEquals(false, $result); $mode = 805323776; $result = Isartifact($mode); $this->assertEquals(true, $result); print "test function Iscontainer()\n"; $mode = 536888320; $result = Iscontainer($mode); $this->assertEquals(true, $result); $mode = 805323776; $result = Iscontainer($mode); $this->assertEquals(true, $result); print "test function DirMode2String()\n"; $result = DirMode2String($mode); $this->assertEquals("a-d-----S---", $result); //print "Ending unit test for common-dir.php\n"; }
/** * * @param int $uploadTreeId * @param Request $request * @return int $jobQueueId */ private function getJobQueueId($uploadTreeId, Request $request) { $uploadEntry = $this->uploadDao->getUploadEntry($uploadTreeId); $uploadId = intval($uploadEntry['upload_fk']); $userId = Auth::getUserId(); $groupId = Auth::getGroupId(); if ($uploadId <= 0 || !$this->uploadDao->isAccessible($uploadId, $groupId)) { throw new Exception('permission denied'); } $bulkScope = $request->get('bulkScope'); switch ($bulkScope) { case 'u': $uploadTreeTable = $this->uploadDao->getUploadtreeTableName($uploadId); $topBounds = $this->uploadDao->getParentItemBounds($uploadId, $uploadTreeTable); $uploadTreeId = $topBounds->getItemId(); break; case 'f': if (!Isdir($uploadEntry['ufile_mode']) && !Iscontainer($uploadEntry['ufile_mode']) && !Isartifact($uploadEntry['ufile_mode'])) { $uploadTreeId = $uploadEntry['parent'] ?: $uploadTreeId; } break; default: throw new InvalidArgumentException('bad scope request'); } $refText = $request->get('refText'); $actions = $request->get('bulkAction'); $licenseRemovals = array(); foreach ($actions as $licenseAction) { $licenseRemovals[$licenseAction['licenseId']] = $licenseAction['action'] == 'remove'; } $bulkId = $this->licenseDao->insertBulkLicense($userId, $groupId, $uploadTreeId, $licenseRemovals, $refText); if ($bulkId <= 0) { throw new Exception('cannot insert bulk reference'); } $upload = $this->uploadDao->getUpload($uploadId); $uploadName = $upload->getFilename(); $job_pk = JobAddJob($userId, $groupId, $uploadName, $uploadId); /** @var DeciderJobAgentPlugin $deciderPlugin */ $deciderPlugin = plugin_find("agent_deciderjob"); $dependecies = array(array('name' => 'agent_monk_bulk', 'args' => $bulkId)); $conflictStrategyId = intval($request->get('forceDecision')); $errorMsg = ''; $jqId = $deciderPlugin->AgentAdd($job_pk, $uploadId, $errorMsg, $dependecies, $conflictStrategyId); if (!empty($errorMsg)) { throw new Exception(str_replace('<br>', "\n", $errorMsg)); } return $jqId; }
private function getJobQueueId($uploadTreeId) { $uploadEntry = $this->uploadDao->getUploadEntry($uploadTreeId); $uploadId = intval($uploadEntry['upload_fk']); if ($uploadId <= 0) { throw new Exception('permission denied'); } $bulkScope = filter_input(INPUT_POST, 'bulkScope'); switch ($bulkScope) { case 'u': $uploadTreeTable = $this->uploadDao->getUploadtreeTableName($uploadId); $row = $this->dbManager->getSingleRow("SELECT uploadtree_pk FROM {$uploadTreeTable} WHERE upload_fk = \$1 ORDER BY uploadtree_pk LIMIT 1", array($uploadId), __METHOD__ . "adam" . $uploadTreeTable); $uploadTreeId = $row['uploadtree_pk']; break; case 'f': if (!Isdir($uploadEntry['ufile_mode']) && !Iscontainer($uploadEntry['ufile_mode']) && !Isartifact($uploadEntry['ufile_mode'])) { $uploadTreeId = $uploadEntry['parent'] ?: $uploadTreeId; } break; default: throw new InvalidArgumentException('bad scope request'); } $userId = Auth::getUserId(); $groupId = Auth::getGroupId(); $refText = filter_input(INPUT_POST, 'refText'); $action = filter_input(INPUT_POST, 'bulkAction'); $licenseId = GetParm('licenseId', PARM_INTEGER); $removing = $action === 'remove'; $bulkId = $this->licenseDao->insertBulkLicense($userId, $groupId, $uploadTreeId, $licenseId, $removing, $refText); if ($bulkId <= 0) { throw new Exception('cannot insert bulk reference'); } $upload = $this->uploadDao->getUpload($uploadId); $uploadName = $upload->getFilename(); $job_pk = JobAddJob($userId, $groupId, $uploadName, $uploadId); /** @var DeciderJobAgentPlugin $deciderPlugin */ $deciderPlugin = plugin_find("agent_deciderjob"); $dependecies = array(array('name' => 'agent_monk_bulk', 'args' => $bulkId)); $conflictStrategyId = intval(filter_input(INPUT_POST, 'forceDecision')); $errorMsg = ''; $jqId = $deciderPlugin->AgentAdd($job_pk, $uploadId, $errorMsg, $dependecies, $conflictStrategyId); if (!empty($errorMsg)) { throw new Exception(str_replace('<br>', "\n", $errorMsg)); } return $jqId; }
/** * \brief Find the non artifact children of an uploadtree pk. * If any children are artifacts, resolve them until you get * to a non-artifact. * * \param $uploadtree_pk * \param $uploadtree_tablename * * \return list of child uploadtree recs + pfile_size + pfile_mimetypefk on success. * list may be empty if there are no children. * Child list is sorted by ufile_name. */ function GetNonArtifactChildren($uploadtree_pk, $uploadtree_tablename = 'uploadtree') { global $container; /** @var DbManager */ $dbManager = $container->get('db.manager'); /* Find all the children */ $sql = "select {$uploadtree_tablename}.*, pfile_size, pfile_mimetypefk from {$uploadtree_tablename}\n left outer join pfile on (pfile_pk=pfile_fk)\n where parent=\$1 ORDER BY lft"; $dbManager->prepare($stmt = __METHOD__ . "{$uploadtree_tablename}", $sql); $result = $dbManager->execute($stmt, array($uploadtree_pk)); $children = $dbManager->fetchAll($result); $dbManager->freeResult($result); if (count($children) == 0) { return $children; } /* Loop through each child and replace any artifacts with their non artifact child. Or skip them if they are not containers. */ $foundChildren = array(); foreach ($children as $key => $child) { if (Isartifact($child['ufile_mode'])) { if (Iscontainer($child['ufile_mode'])) { unset($children[$key]); $NonAChildren = GetNonArtifactChildren($child['uploadtree_pk'], $uploadtree_tablename); if ($NonAChildren) { $foundChildren = array_merge($foundChildren, $NonAChildren); } } else { unset($children[$key]); } } else { $foundChildren[$key] = $child; } } // uasort($foundChildren, '_DirCmp'); return $foundChildren; }
/** * \brief Find the non artifact children of an uploadtree pk. * If any children are artifacts, resolve them until you get * to a non-artifact. * * This function replaces DirGetList() * * \param $uploadtree_pk * \param $uploadtree_tablename * * \return list of child uploadtree recs + pfile_size + pfile_mimetypefk on success. * list may be empty if there are no children. * Child list is sorted by ufile_name. */ function GetNonArtifactChildren($uploadtree_pk, $uploadtree_tablename = 'uploadtree') { global $PG_CONN; $foundChildren = array(); /* Find all the children */ $sql = "select {$uploadtree_tablename}.*, pfile_size, pfile_mimetypefk from {$uploadtree_tablename}\n left outer join pfile on (pfile_pk=pfile_fk)\n where parent={$uploadtree_pk}"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result) == 0) { pg_free_result($result); return $foundChildren; } $children = pg_fetch_all($result); pg_free_result($result); /* Loop through each child and replace any artifacts with their non artifact child. Or skip them if they are not containers. */ foreach ($children as $key => $child) { if (Isartifact($child['ufile_mode'])) { if (Iscontainer($child['ufile_mode'])) { unset($children[$key]); $NonAChildren = GetNonArtifactChildren($child['uploadtree_pk'], $uploadtree_tablename); if ($NonAChildren) { $foundChildren = array_merge($foundChildren, $NonAChildren); } } else { unset($children[$key]); } } else { $foundChildren[$key] = $child; } } uasort($foundChildren, '_DirCmp'); return $foundChildren; }
/** * \brief Given an Upload and UploadtreePk item, display: * - The file listing for the directory, with license navigation. * - Recursively traverse the tree. * \note This is recursive! * Output goes to stdout! */ function ShowLicenseTree($Upload, $Item, $Uri, $Path = NULL) { /***** Get all the licenses PER item (file or directory) under this UploadtreePk. Save the data 3 ways: - Number of licenses PER item. - Number of items PER license. - Number of items PER license family. *****/ global $Plugins; $Time = time(); $ModLicView =& $Plugins[plugin_find_id("view-license")]; if ($Path == NULL) { $Path = array(); } /****************************************/ /* Get the items under this UploadtreePk */ $Children = DirGetList($Upload, $Item); $Name = ""; foreach ($Children as $C) { if (empty($C)) { continue; } /* Store the item information */ $IsDir = Isdir($C['ufile_mode']); $IsContainer = Iscontainer($C['ufile_mode']); $IsArtifact = Isartifact($C['ufile_mode']); /* Load licenses for the item */ $Lics = array(); LicenseGetAll($C['uploadtree_pk'], $Lics); /* Determine the hyperlinks */ if (!empty($C['pfile_fk'])) { $LinkUri = "{$Uri}&item=" . $C['uploadtree_pk']; $LinkUri = str_replace("mod=license-tree", "mod=view-license", $LinkUri); } else { $LinkUri = NULL; } if (Iscontainer($C['ufile_mode'])) { $uploadtree_pk = DirGetNonArtifact($C['uploadtree_pk']); $LicUri = "{$Uri}&item=" . $uploadtree_pk; $LicUri = str_replace("mod=license-tree", "mod=license", $LicUri); } else { $LicUri = NULL; } /* Populate the output */ ksort($Lics); $LicCount = $Lics[' Total ']; $LicSum = ""; foreach ($Lics as $Key => $Val) { if ($Key == " Total ") { continue; } if (!empty($LicSum)) { $LicSum .= ","; } $LicSum .= $Key; } /* Display the results */ if ($LicCount > 0) { $LicSum = ""; foreach ($Lics as $Key => $Val) { if ($Key == " Total ") { continue; } if (!empty($LicSum)) { $LicSum .= ","; } $LicSum .= $Key; } $Name = $C['ufile_name']; if ($IsArtifact) { $Name = str_replace("artifact.", "", $Name); } if ($this->OutputType == 'HTML') { $this->ShowOutputHTML($LicCount, $LicSum, $IsContainer, $IsArtifact, $IsDir, $Path, $Name, $LicUri, $LinkUri); } else { if ($this->OutputType == 'CSV') { $this->ShowOutputCSV($LicCount, $LicSum, $IsContainer, $IsArtifact, $IsDir, $Path, $Name, $LicUri, $LinkUri); } } } /* Recurse! */ if (($IsDir || $IsContainer) && $LicCount > 0) { $NewPath = $Path; $NewPath[] = $Name; $this->ShowLicenseTree($Upload, $C['uploadtree_pk'], $Uri, $NewPath); } } /* for each item in the directory */ flush(); }
/** * \brief Given a Folder_pk, list every upload in the folder. */ function ShowFolder($Folder, $Show) { global $Plugins; global $PG_CONN; $V = ""; /* Get list of uploads in this folder */ $sql = "SELECT * FROM upload\n INNER JOIN uploadtree ON upload_fk = upload_pk\n AND upload.pfile_fk = uploadtree.pfile_fk\n AND parent IS NULL\n AND lft IS NOT NULL \n WHERE upload_pk IN\n (SELECT child_id FROM foldercontents WHERE foldercontents_mode & 2 != 0 AND parent_fk = {$Folder})\n ORDER BY upload_filename,upload_desc,upload_pk,upload_origin;"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $Uri = Traceback_uri() . "?mod=" . $this->Name; $V .= "<table border=1 width='100%'>"; $V .= "<tr><td valign='top' width='20%'>\n"; $V .= FolderListScript(); $text = _("Folder Navigation"); $V .= "<center><H3>{$text}</H3></center>\n"; $V .= "<center><small>"; if ($Folder != GetUserRootFolder()) { $text = _("Top"); $V .= "<a href='" . Traceback_uri() . "?mod=" . $this->Name . "'>{$text}</a> |"; } $text = _("Expand"); $V .= "<a href='javascript:Expand();'>{$text}</a> |"; $text = _("Collapse"); $V .= "<a href='javascript:Collapse();'>{$text}</a> |"; $text = _("Refresh"); $V .= "<a href='" . Traceback() . "'>{$text}</a>"; $V .= "</small></center>"; $V .= "<P>\n"; $V .= "<form>\n"; $V .= FolderListDiv($Folder, 0, $Folder, 1); $V .= "</form>\n"; $V .= "</td><td valign='top'>\n"; $text = _("Uploads"); $V .= "<center><H3>{$text}</H3></center>\n"; $V .= "<table class='text' id='browsetbl' border=0 width='100%' cellpadding=0>\n"; $text = _("Upload Name and Description"); $text1 = _("Upload Date"); $V .= "<th>{$text}</th><th>{$text1}</th></tr>\n"; /* Browse-Pfile menu */ $MenuPfile = menu_find("Browse-Pfile", $MenuDepth); /* Browse-Pfile menu without the compare menu item */ $MenuPfileNoCompare = menu_remove($MenuPfile, "Compare"); while ($Row = pg_fetch_assoc($result)) { if (empty($Row['upload_pk'])) { continue; } $Desc = htmlentities($Row['upload_desc']); $UploadPk = $Row['upload_pk']; /* check permission on upload */ $UploadPerm = GetUploadPerm($UploadPk); if ($UploadPerm < PERM_READ) { continue; } $Name = $Row['ufile_name']; if (empty($Name)) { $Name = $Row['upload_filename']; } /* If UploadtreePk is not an artifact, then use it as the root. Else get the first non artifact under it. */ if (Isartifact($Row['ufile_mode'])) { $UploadtreePk = DirGetNonArtifact($Row['uploadtree_pk'], $uploadtree_tablename); } else { $UploadtreePk = $Row['uploadtree_pk']; } $V .= "<tr><td>"; if (IsContainer($Row['ufile_mode'])) { $V .= "<a href='{$Uri}&upload={$UploadPk}&folder={$Folder}&item={$UploadtreePk}&show={$Show}'>"; $V .= "<b>" . $Name . "</b>"; $V .= "</a>"; } else { $V .= "<b>" . $Name . "</b>"; } $V .= "<br>"; if (!empty($Desc)) { $V .= "<i>" . $Desc . "</i><br>"; } $Upload = $Row['upload_pk']; $Parm = "upload={$Upload}&show={$Show}&item=" . $Row['uploadtree_pk']; if (Iscontainer($Row['ufile_mode'])) { $V .= menu_to_1list($MenuPfile, $Parm, " ", " ", 1, $UploadPk); } else { $V .= menu_to_1list($MenuPfileNoCompare, $Parm, " ", " ", 1, $UploadPk); } /* Job queue link */ $text = _("History"); if (plugin_find_id('showjobs') >= 0) { $V .= "<a href='" . Traceback_uri() . "?mod=showjobs&upload={$UploadPk}'>[{$text}]</a>"; $V .= "</td>\n"; $V .= "<td align='right'>" . substr($Row['upload_ts'], 0, 19) . "</td>"; } $V .= "<tr><td colspan=2> </td></tr>\n"; } pg_free_result($result); $V .= "</table>\n"; $V .= "</td></tr>\n"; $V .= "</table>\n"; return $V; }
/** * @param array $child * @param int $uploadId * @param int $selectedAgentId * @param array $pfileLicenses * @param int $groupId * @param string $uri * @param array $UniqueTagArray * @param boolean $isFlat * @param int[] $latestSuccessfulAgentIds * @return array */ private function createFileDataRow($child, $uploadId, $selectedAgentId, $pfileLicenses, $groupId, $uri, &$UniqueTagArray, $isFlat, $latestSuccessfulAgentIds) { $fileId = $child['pfile_fk']; $childUploadTreeId = $child['uploadtree_pk']; $linkUri = ''; if (!empty($fileId)) { $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) { $uploadtree_pk = $child['uploadtree_pk']; $linkUri = "{$uri}&item=" . $uploadtree_pk; if ($selectedAgentId) { $linkUri .= "&agentId={$selectedAgentId}"; } } 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']); $licenseEntries = array(); if ($isContainer) { $agentFilter = $selectedAgentId ? array($selectedAgentId) : $latestSuccessfulAgentIds; $licenseEntries = $this->licenseDao->getLicenseShortnamesContained($childItemTreeBounds, $agentFilter, array()); } else { 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) . "]"; } } } $licenseList = implode(', ', $licenseEntries); $fileListLinks = FileListLinks($uploadId, $childUploadTreeId, 0, $fileId, true, $UniqueTagArray, $this->uploadtree_tablename, !$isFlat); if (!$isContainer) { $text = _("Copyright/Email/Url"); $fileListLinks .= "[<a href='" . Traceback_uri() . "?mod=copyright-view&upload={$uploadId}&item={$childUploadTreeId}' >{$text}</a>]"; $text = _("ReadMe_OSS"); $fileListLinks .= "[<a href='" . Traceback_uri() . "?mod=ui_readmeoss&upload={$uploadId}&item={$childUploadTreeId}' >{$text}</a>]"; $text = _("SPDX"); $fileListLinks .= "[<a href='" . Traceback_uri() . "?mod=ui_spdx2&upload={$uploadId}&item={$childUploadTreeId}' >{$text}</a>]"; } return array($fileName, $licenseList, $fileListLinks); }
/** * @return bool */ public function isFile() { return !Isartifact($this->fileMode) && !Isdir($this->fileMode) && !Iscontainer($this->fileMode); }
/** * @param array $row fetched row * @param Request $request * @param $uri * @param $menuPfile * @param $menuPfileNoCompare * @param array $statusTypesAvailable * @param array $users * @param string (unique) * @return array */ private function showRow($row, Request $request, $uri, $menuPfile, $menuPfileNoCompare, $statusTypesAvailable, $users, $rowCounter) { $show = $request->get('show'); $folder = $request->get('folder'); $uploadId = intval($row['upload_pk']); $description = htmlentities($row['upload_desc']); $fileName = $row['ufile_name']; if (empty($fileName)) { $fileName = $row['upload_filename']; } $itemId = Isartifact($row['ufile_mode']) ? DirGetNonArtifact($row['uploadtree_pk']) : $row['uploadtree_pk']; $nameColumn = "<b>{$fileName}</b>"; if (IsContainer($row['ufile_mode'])) { $nameColumn = "<a href='{$uri}&upload={$uploadId}&folder={$folder}&item={$itemId}&show={$show}'>{$nameColumn}</a>"; } $nameColumn .= "<br>"; if (!empty($description)) { $nameColumn .= "<i>{$description}</i><br>"; } $Parm = "upload={$uploadId}&show={$show}&item=" . $row['uploadtree_pk']; if (Iscontainer($row['ufile_mode'])) { $nameColumn .= MenuRenderer::menuToActiveSelect($menuPfile, $Parm, $uploadId); } else { $nameColumn .= MenuRenderer::menuToActiveSelect($menuPfileNoCompare, $Parm, $uploadId); } $modsUploadMulti = MenuHook::getAgentPluginNames('UploadMulti'); if (!empty($modsUploadMulti)) { $nameColumn = '<input type="checkbox" name="uploads[]" class="browse-upload-checkbox" value="' . $uploadId . '"/>' . $nameColumn; } $dateCol = substr($row['upload_ts'], 0, 19); $pairIdPrio = array($uploadId, floatval($row[UploadBrowseProxy::PRIO_COLUMN])); if (!$this->userPerm && 4 == $row['status_fk']) { $currentStatus = $this->statusTypes[4]; } else { $statusAction = " onchange =\"changeTableEntry(this, {$uploadId},'status_fk' )\" "; $currentStatus = $this->createSelect("Status" . $this->userPerm . "Of_{$rowCounter}", $statusTypesAvailable, $row['status_fk'], $statusAction); } if ($this->userPerm) { $action = " onchange =\"changeTableEntry(this, {$uploadId}, 'assignee')\""; $currentAssignee = $this->createSelectUsers("AssignedTo_{$rowCounter}", $users, $row['assignee'], $action); } else { $currentAssignee = array_key_exists($row['assignee'], $users) ? $users[$row['assignee']] : _('Unassigned'); } $rejectableUploadId = $this->userPerm || $row['status_fk'] < 4 ? $uploadId : 0; $tripleComment = array($rejectableUploadId, $row['status_fk'], htmlspecialchars($row['status_comment'])); $sql = "SELECT rf_pk, rf_shortname FROM upload_clearing_license ucl, license_ref" . " WHERE ucl.group_fk=\$1 AND upload_fk=\$2 AND ucl.rf_fk=rf_pk"; $stmt = __METHOD__ . '.collectMainLicenses'; $this->dbManager->prepare($stmt, $sql); $res = $this->dbManager->execute($stmt, array(Auth::getGroupId(), $uploadId)); $mainLicenses = array(); while ($lic = $this->dbManager->fetchArray($res)) { $mainLicenses[] = '<a onclick="javascript:window.open(\'' . Traceback_uri() . "?mod=popup-license&rf={$lic['rf_pk']}','License text','width=600,height=400,toolbar=no,scrollbars=yes,resizable=yes');" . '" href="javascript:;">' . $lic['rf_shortname'] . '</a>' . "<img onclick=\"removeMainLicense({$uploadId},{$lic['rf_pk']});\" class=\"delete\" src=\"images/space_16.png\" alt=\"\"/></img>"; } $this->dbManager->freeResult($res); $output = array($nameColumn, $currentStatus, $tripleComment, implode(', ', $mainLicenses), $currentAssignee, $dateCol, $pairIdPrio); return $output; }
/** * @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); }