44 const NAME =
"ajax_file_browser";
46 private $uploadtree_tablename =
"";
54 private $licenseProjector;
56 protected $agentNames = AgentRef::AGENT_LIST;
58 public function __construct()
60 parent::__construct(self::NAME, array(
61 self::TITLE => _(
"Ajax: File Browser"),
62 self::DEPENDENCIES => array(
"fileBrowse"),
64 self::REQUIRES_LOGIN =>
false 67 $this->uploadDao = $this->
getObject(
'dao.upload');
68 $this->licenseDao = $this->
getObject(
'dao.license');
69 $this->agentDao = $this->
getObject(
'dao.agent');
76 protected function handle(Request $request)
78 $upload = intval($request->get(
"upload"));
80 if (!$this->uploadDao->isAccessible($upload, $groupId)) {
81 throw new \Exception(
"Permission Denied");
84 $item = intval($request->get(
"item"));
86 $itemTreeBounds = $this->uploadDao->getItemTreeBounds($item, $this->uploadtree_tablename);
87 $left = $itemTreeBounds->getLeft();
89 throw new \Exception(
"Job unpack/adj2nest hasn't completed.");
92 $scannerAgents = array_keys($this->agentNames);
93 $scanJobProxy =
new ScanJobProxy($this->agentDao, $upload);
94 $scanJobProxy->createAgentStatus($scannerAgents);
95 $selectedAgentId = intval($request->get(
'agentId'));
96 $tag_pk = intval($request->get(
'tag'));
98 $UniqueTagArray = array();
99 $this->licenseProjector =
new LicenseMap($this->
getObject(
'db.manager'),$groupId,LicenseMap::CONCLUSION,
true);
100 $vars = $this->
createFileListing($tag_pk, $itemTreeBounds, $UniqueTagArray, $selectedAgentId, $groupId, $scanJobProxy);
102 return new JsonResponse(array(
103 'sEcho' => intval($request->get(
'sEcho')),
104 'aaData' => $vars[
'fileData'],
105 'iTotalRecords' => intval($request->get(
'totalRecords')),
106 'iTotalDisplayRecords' => $vars[
'iTotalDisplayRecords']
122 if (!empty($selectedAgentId)) {
123 $agentName = $this->agentDao->getAgentName($selectedAgentId);
124 $selectedScanners = array($agentName=>$selectedAgentId);
126 $selectedScanners = $scanJobProxy->getLatestSuccessfulAgentIds();
131 $isFlat = isset($_GET[
'flatten']);
134 $options = array(UploadTreeProxy::OPT_RANGE => $itemTreeBounds);
136 $options = array(UploadTreeProxy::OPT_REALPARENT => $itemTreeBounds->
getItemId());
141 $vars[
'iTotalDisplayRecords'] = $descendantView->
count();
143 $columnNamesInDatabase = array($isFlat?
'ufile_name':
'lft');
144 $defaultOrder = array(array(0,
"asc"));
145 $orderString = $this->
getObject(
'utils.data_tables_utility')->getSortingString($_GET, $columnNamesInDatabase, $defaultOrder);
150 $orderString .=
" OFFSET $offset";
153 $orderString .=
" LIMIT $limit";
157 $sql = $descendantView->getDbViewQuery().
" $orderString";
158 $dbManager = $this->
getObject(
'db.manager');
160 $dbManager->prepare($stmt=__METHOD__.$orderString,$sql);
161 $res = $dbManager->execute($stmt,$descendantView->getParams());
162 $descendants = $dbManager->fetchAll($res);
163 $dbManager->freeResult($res);
166 if (!empty($tagId)) {
169 if (empty($descendants)) {
170 $vars[
'fileData'] = array();
175 $firstChild = reset($descendants);
176 $lastChild = end($descendants);
177 $nameRange = array($firstChild[
'ufile_name'],$lastChild[
'ufile_name']);
179 $nameRange = array();
183 $pfileLicenses = array();
184 foreach ($selectedScanners as $agentName=>$agentId) {
185 $licensePerPfile = $this->licenseDao->getLicenseIdPerPfileForAgentId($itemTreeBounds, $agentId, $isFlat, $nameRange);
186 foreach ($licensePerPfile as $pfile => $licenseRow) {
187 foreach ($licenseRow as $licId => $row) {
188 $lic = $this->licenseProjector->getProjectedShortname($licId);
189 $pfileLicenses[$pfile][$lic][$agentName] = $row;
196 $tableData = array();
197 $latestSuccessfulAgentIds = $scanJobProxy->getLatestSuccessfulAgentIds();
198 foreach ($descendants as $child) {
203 $pfileLicenses, $groupId, $baseUri, $UniqueTagArray, $isFlat, $latestSuccessfulAgentIds);
206 $vars[
'fileData'] = $tableData;
223 private function createFileDataRow($child, $uploadId, $selectedAgentId, $pfileLicenses, $groupId, $uri, &$UniqueTagArray, $isFlat, $latestSuccessfulAgentIds)
225 $fileId = $child[
'pfile_fk'];
226 $childUploadTreeId = $child[
'uploadtree_pk'];
228 if (!empty($fileId)) {
230 $linkUri .=
"?mod=view-license&upload=$uploadId&item=$childUploadTreeId";
231 if ($selectedAgentId) {
232 $linkUri .=
"&agentId=$selectedAgentId";
238 if ($isContainer && !$isFlat) {
239 $uploadtree_pk = $child[
'uploadtree_pk'];
240 $linkUri =
"$uri&item=" . $uploadtree_pk;
241 if ($selectedAgentId) {
242 $linkUri .=
"&agentId=$selectedAgentId";
244 }
else if ($isContainer) {
246 $linkUri =
"$uri&item=" . $uploadtree_pk;
247 if ($selectedAgentId) {
248 $linkUri .=
"&agentId=$selectedAgentId";
254 $fileName = htmlspecialchars($child[
'ufile_name']);
256 $fileName =
"<a href='$linkUri'><span style='color: darkblue'> <b>$fileName</b> </span></a>";
257 }
else if (!empty($linkUri)) {
258 $fileName =
"<a href='$linkUri'>$fileName</a>";
261 $childItemTreeBounds =
263 $licenseEntries = array();
265 $agentFilter = $selectedAgentId ? array($selectedAgentId) : $latestSuccessfulAgentIds;
266 $licenseEntries = $this->licenseDao->getLicenseShortnamesContained($childItemTreeBounds, $agentFilter, array());
268 if (array_key_exists($fileId, $pfileLicenses)) {
269 foreach ($pfileLicenses[$fileId] as $shortName => $rfInfo) {
270 $agentEntries = array();
271 foreach ($rfInfo as $agent => $match) {
272 $agentName = $this->agentNames[$agent];
273 $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>";
275 if ($match[
'match_percentage'] > 0) {
276 $agentEntry .=
": $match[match_percentage]%";
278 $agentEntries[] = $agentEntry;
280 $licenseEntries[] = $shortName .
" [" . implode(
"][", $agentEntries) .
"]";
285 $licenseList = implode(
', ', $licenseEntries);
289 if (! $isContainer) {
290 $text = _(
"Copyright/Email/Url");
291 $fileListLinks .=
"[<a href='" .
Traceback_uri() .
"?mod=copyright-view&upload=$uploadId&item=$childUploadTreeId' >$text</a>]";
292 $text = _(
"ReadMe_OSS");
293 $fileListLinks .=
"[<a href='" .
Traceback_uri() .
"?mod=ui_readmeoss&upload=$uploadId&item=$childUploadTreeId' >$text</a>]";
295 $fileListLinks .=
"[<a href='" .
Traceback_uri() .
"?mod=ui_spdx2&upload=$uploadId&item=$childUploadTreeId' >$text</a>]";
298 return array($fileName, $licenseList, $fileListLinks);
Traceback_uri()
Get the URI without query to this location.
createFileListing($tagId, ItemTreeBounds $itemTreeBounds, &$UniqueTagArray, $selectedAgentId, $groupId, $scanJobProxy)
FileListLinks($upload_fk, $uploadtree_pk, $napk, $pfile_pk, $Recurse=True, &$UniqueTagArray=array(), $uploadtree_tablename="uploadtree", $wantTags=true)
Get list of links: [View][Info][Download]
Wrapper class for license map.
createFileDataRow($child, $uploadId, $selectedAgentId, $pfileLicenses, $groupId, $uri, &$UniqueTagArray, $isFlat, $latestSuccessfulAgentIds)
DirGetNonArtifact($UploadtreePk, $uploadtree_tablename='uploadtree')
Given an artifact directory (uploadtree_pk), return the first non-artifact directory (uploadtree_pk)...
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
char * uploadtree_tablename
upload.uploadtree_tablename
static getGroupId()
Get the current user's group id.
Traceback_parm_keep($List)
Create a new URI, keeping only these items.