20 use Symfony\Component\HttpFoundation\JsonResponse;
21 use Symfony\Component\HttpFoundation\Request;
22 use Symfony\Component\HttpFoundation\Response;
32 const NAME =
"ajax_file_browser";
34 private $uploadtree_tablename =
"";
42 private $licenseProjector;
44 protected $agentNames = AgentRef::AGENT_LIST;
46 public function __construct()
48 parent::__construct(self::NAME, array(
49 self::TITLE => _(
"Ajax: File Browser"),
50 self::DEPENDENCIES => array(
"fileBrowse"),
52 self::REQUIRES_LOGIN =>
false
55 $this->uploadDao = $this->
getObject(
'dao.upload');
56 $this->licenseDao = $this->
getObject(
'dao.license');
57 $this->agentDao = $this->
getObject(
'dao.agent');
64 protected function handle(Request $request)
66 $upload = intval($request->get(
"upload"));
68 if (!$this->uploadDao->isAccessible($upload, $groupId)) {
69 throw new \Exception(
"Permission Denied");
72 $item = intval($request->get(
"item"));
75 $left = $itemTreeBounds->getLeft();
77 throw new \Exception(
"Job unpack/adj2nest hasn't completed.");
80 $scannerAgents = array_keys($this->agentNames);
81 $scanJobProxy =
new ScanJobProxy($this->agentDao, $upload);
82 $scanJobProxy->createAgentStatus($scannerAgents);
83 $selectedAgentId = intval($request->get(
'agentId'));
84 $tag_pk = intval($request->get(
'tag'));
86 $UniqueTagArray = array();
87 $this->licenseProjector =
new LicenseMap($this->
getObject(
'db.manager'),$groupId,LicenseMap::CONCLUSION,
true);
88 $vars = $this->
createFileListing($tag_pk, $itemTreeBounds, $UniqueTagArray, $selectedAgentId, $groupId, $scanJobProxy, $request);
90 return new JsonResponse(array(
91 'sEcho' => intval($request->get(
'sEcho')),
92 'aaData' => $vars[
'fileData'],
93 'iTotalRecords' => intval($request->get(
'totalRecords')),
94 'iTotalDisplayRecords' => $vars[
'iTotalDisplayRecords']
110 if (!empty($selectedAgentId)) {
111 $agentName = $this->agentDao->getAgentName($selectedAgentId);
112 $selectedScanners = array($agentName=>$selectedAgentId);
114 $selectedScanners = $scanJobProxy->getLatestSuccessfulAgentIds();
119 $isFlat = isset($_GET[
'flatten']);
122 $options = array(UploadTreeProxy::OPT_RANGE => $itemTreeBounds);
124 $options = array(UploadTreeProxy::OPT_REALPARENT => $itemTreeBounds->
getItemId());
127 $searchMap = array();
128 foreach (explode(
' ',$request->get(
'sSearch')) as $pair) {
129 $a = explode(
':',$pair);
130 if (count($a) == 1) {
131 $searchMap[
'head'] = $pair;
133 $searchMap[$a[0]] = $a[1];
137 if (array_key_exists(
'ext', $searchMap) && strlen($searchMap[
'ext'])>=1) {
138 $options[UploadTreeProxy::OPT_EXT] = $searchMap[
'ext'];
140 if (array_key_exists(
'head', $searchMap) && strlen($searchMap[
'head'])>=1) {
141 $options[UploadTreeProxy::OPT_HEAD] = $searchMap[
'head'];
143 if (($rfId=$request->get(
'scanFilter'))>0) {
144 $options[UploadTreeProxy::OPT_AGENT_SET] = $selectedScanners;
145 $options[UploadTreeProxy::OPT_SCAN_REF] = $rfId;
150 $vars[
'iTotalDisplayRecords'] = $descendantView->count();
152 $columnNamesInDatabase = array($isFlat?
'ufile_name':
'lft');
153 $defaultOrder = array(array(0,
"asc"));
154 $orderString = $this->
getObject(
'utils.data_tables_utility')->getSortingString($_GET, $columnNamesInDatabase, $defaultOrder);
159 $orderString .=
" OFFSET $offset";
162 $orderString .=
" LIMIT $limit";
166 $sql = $descendantView->getDbViewQuery().
" $orderString";
167 $dbManager = $this->
getObject(
'db.manager');
169 $dbManager->prepare($stmt=__METHOD__.$orderString,$sql);
170 $res = $dbManager->execute($stmt,$descendantView->getParams());
171 $descendants = $dbManager->fetchAll($res);
172 $dbManager->freeResult($res);
175 if (!empty($tagId)) {
178 if (empty($descendants)) {
179 $vars[
'fileData'] = array();
184 $firstChild = reset($descendants);
185 $lastChild = end($descendants);
186 $nameRange = array($firstChild[
'ufile_name'],$lastChild[
'ufile_name']);
188 $nameRange = array();
192 $pfileLicenses = array();
193 foreach ($selectedScanners as $agentName=>$agentId) {
194 $licensePerPfile = $this->licenseDao->getLicenseIdPerPfileForAgentId($itemTreeBounds, $agentId, $isFlat, $nameRange);
195 foreach ($licensePerPfile as $pfile => $licenseRow) {
196 foreach ($licenseRow as $licId => $row) {
197 $lic = $this->licenseProjector->getProjectedShortname($licId);
198 $pfileLicenses[$pfile][$lic][$agentName] = $row;
205 $tableData = array();
206 $latestSuccessfulAgentIds = $scanJobProxy->getLatestSuccessfulAgentIds();
207 foreach ($descendants as $child) {
212 $pfileLicenses, $groupId, $baseUri, $UniqueTagArray, $isFlat, $latestSuccessfulAgentIds);
215 $vars[
'fileData'] = $tableData;
232 private function createFileDataRow($child, $uploadId, $selectedAgentId, $pfileLicenses, $groupId, $uri, &$UniqueTagArray, $isFlat, $latestSuccessfulAgentIds)
234 $fileId = $child[
'pfile_fk'];
235 $childUploadTreeId = $child[
'uploadtree_pk'];
237 if (!empty($fileId)) {
239 $linkUri .=
"?mod=view-license&upload=$uploadId&item=$childUploadTreeId";
240 if ($selectedAgentId) {
241 $linkUri .=
"&agentId=$selectedAgentId";
247 if ($isContainer && !$isFlat) {
248 $uploadtree_pk = $child[
'uploadtree_pk'];
249 $linkUri =
"$uri&item=" . $uploadtree_pk;
250 if ($selectedAgentId) {
251 $linkUri .=
"&agentId=$selectedAgentId";
253 }
else if ($isContainer) {
255 $linkUri =
"$uri&item=" . $uploadtree_pk;
256 if ($selectedAgentId) {
257 $linkUri .=
"&agentId=$selectedAgentId";
263 $fileName = htmlspecialchars($child[
'ufile_name']);
265 $fileName =
"<a href='$linkUri'><span style='color: darkblue'> <b>$fileName</b> </span></a>";
266 }
else if (!empty($linkUri)) {
267 $fileName =
"<a href='$linkUri'>$fileName</a>";
270 $childItemTreeBounds =
272 $licenseEntries = array();
274 $agentFilter = $selectedAgentId ? array($selectedAgentId) : $latestSuccessfulAgentIds;
275 $licenseEntries = $this->licenseDao->getLicenseShortnamesContained($childItemTreeBounds, $agentFilter, array());
277 if (array_key_exists($fileId, $pfileLicenses)) {
278 foreach ($pfileLicenses[$fileId] as $shortName => $rfInfo) {
279 $agentEntries = array();
280 foreach ($rfInfo as $agent => $match) {
281 $agentName = $this->agentNames[$agent];
282 $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>";
284 if ($match[
'match_percentage'] > 0) {
285 $agentEntry .=
": $match[match_percentage]%";
287 $agentEntries[] = $agentEntry;
289 $licenseEntries[] = $shortName .
" [" . implode(
"][", $agentEntries) .
"]";
294 $licenseList = implode(
', ', $licenseEntries);
298 if (! $isContainer) {
299 $text = _(
"Copyright/Email/Url");
300 $fileListLinks .=
"[<a href='" .
Traceback_uri() .
"?mod=copyright-view&upload=$uploadId&item=$childUploadTreeId' >$text</a>]";
301 $text = _(
"ReadMe_OSS");
302 $fileListLinks .=
"[<a href='" .
Traceback_uri() .
"?mod=ui_readmeoss&upload=$uploadId&item=$childUploadTreeId' >$text</a>]";
304 $fileListLinks .=
"[<a href='" .
Traceback_uri() .
"?mod=ui_spdx2&upload=$uploadId&item=$childUploadTreeId' >$text</a>]";
307 return array($fileName, $licenseList, $fileListLinks);
311 register_plugin(
new AjaxFileBrowser());
char * uploadtree_tablename
upload.uploadtree_tablename
Contains the constants and helpers for authentication of user.
static getGroupId()
Get the current user's group id.
Wrapper class for license map.
createFileListing($tagId, ItemTreeBounds $itemTreeBounds, &$UniqueTagArray, $selectedAgentId, $groupId, $scanJobProxy, $request)
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).
FileListLinks($upload_fk, $uploadtree_pk, $napk, $pfile_pk, $Recurse=True, &$UniqueTagArray=array(), $uploadtree_tablename="uploadtree", $wantTags=true)
Get list of links: [View][Info][Download]
Traceback_uri()
Get the URI without query to this location.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Traceback_parm_keep($List)
Create a new URI, keeping only these items.