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);
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());
129 $vars[
'iTotalDisplayRecords'] = $descendantView->count();
131 $columnNamesInDatabase = array($isFlat?
'ufile_name':
'lft');
132 $defaultOrder = array(array(0,
"asc"));
133 $orderString = $this->
getObject(
'utils.data_tables_utility')->getSortingString($_GET, $columnNamesInDatabase, $defaultOrder);
138 $orderString .=
" OFFSET $offset";
141 $orderString .=
" LIMIT $limit";
145 $sql = $descendantView->getDbViewQuery().
" $orderString";
146 $dbManager = $this->
getObject(
'db.manager');
148 $dbManager->prepare($stmt=__METHOD__.$orderString,$sql);
149 $res = $dbManager->execute($stmt,$descendantView->getParams());
150 $descendants = $dbManager->fetchAll($res);
151 $dbManager->freeResult($res);
154 if (!empty($tagId)) {
157 if (empty($descendants)) {
158 $vars[
'fileData'] = array();
163 $firstChild = reset($descendants);
164 $lastChild = end($descendants);
165 $nameRange = array($firstChild[
'ufile_name'],$lastChild[
'ufile_name']);
167 $nameRange = array();
171 $pfileLicenses = array();
172 foreach ($selectedScanners as $agentName=>$agentId) {
173 $licensePerPfile = $this->licenseDao->getLicenseIdPerPfileForAgentId($itemTreeBounds, $agentId, $isFlat, $nameRange);
174 foreach ($licensePerPfile as $pfile => $licenseRow) {
175 foreach ($licenseRow as $licId => $row) {
176 $lic = $this->licenseProjector->getProjectedShortname($licId);
177 $pfileLicenses[$pfile][$lic][$agentName] = $row;
184 $tableData = array();
185 $latestSuccessfulAgentIds = $scanJobProxy->getLatestSuccessfulAgentIds();
186 foreach ($descendants as $child) {
191 $pfileLicenses, $groupId, $baseUri, $UniqueTagArray, $isFlat, $latestSuccessfulAgentIds);
194 $vars[
'fileData'] = $tableData;
211 private function createFileDataRow($child, $uploadId, $selectedAgentId, $pfileLicenses, $groupId, $uri, &$UniqueTagArray, $isFlat, $latestSuccessfulAgentIds)
213 $fileId = $child[
'pfile_fk'];
214 $childUploadTreeId = $child[
'uploadtree_pk'];
216 if (!empty($fileId)) {
218 $linkUri .=
"?mod=view-license&upload=$uploadId&item=$childUploadTreeId";
219 if ($selectedAgentId) {
220 $linkUri .=
"&agentId=$selectedAgentId";
226 if ($isContainer && !$isFlat) {
227 $uploadtree_pk = $child[
'uploadtree_pk'];
228 $linkUri =
"$uri&item=" . $uploadtree_pk;
229 if ($selectedAgentId) {
230 $linkUri .=
"&agentId=$selectedAgentId";
232 }
else if ($isContainer) {
234 $linkUri =
"$uri&item=" . $uploadtree_pk;
235 if ($selectedAgentId) {
236 $linkUri .=
"&agentId=$selectedAgentId";
242 $fileName = htmlspecialchars($child[
'ufile_name']);
244 $fileName =
"<a href='$linkUri'><span style='color: darkblue'> <b>$fileName</b> </span></a>";
245 }
else if (!empty($linkUri)) {
246 $fileName =
"<a href='$linkUri'>$fileName</a>";
249 $childItemTreeBounds =
251 $licenseEntries = array();
253 $agentFilter = $selectedAgentId ? array($selectedAgentId) : $latestSuccessfulAgentIds;
254 $licenseEntries = $this->licenseDao->getLicenseShortnamesContained($childItemTreeBounds, $agentFilter, array());
256 if (array_key_exists($fileId, $pfileLicenses)) {
257 foreach ($pfileLicenses[$fileId] as $shortName => $rfInfo) {
258 $agentEntries = array();
259 foreach ($rfInfo as $agent => $match) {
260 $agentName = $this->agentNames[$agent];
261 $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>";
263 if ($match[
'match_percentage'] > 0) {
264 $agentEntry .=
": $match[match_percentage]%";
266 $agentEntries[] = $agentEntry;
268 $licenseEntries[] = $shortName .
" [" . implode(
"][", $agentEntries) .
"]";
273 $licenseList = implode(
', ', $licenseEntries);
277 if (! $isContainer) {
278 $text = _(
"Copyright/Email/Url");
279 $fileListLinks .=
"[<a href='" .
Traceback_uri() .
"?mod=copyright-view&upload=$uploadId&item=$childUploadTreeId' >$text</a>]";
280 $text = _(
"ReadMe_OSS");
281 $fileListLinks .=
"[<a href='" .
Traceback_uri() .
"?mod=ui_readmeoss&upload=$uploadId&item=$childUploadTreeId' >$text</a>]";
283 $fileListLinks .=
"[<a href='" .
Traceback_uri() .
"?mod=ui_spdx2&upload=$uploadId&item=$childUploadTreeId' >$text</a>]";
286 return array($fileName, $licenseList, $fileListLinks);
290 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)
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.