9 namespace Fossology\UI\Page;
24 use Symfony\Component\HttpFoundation\RedirectResponse;
25 use Symfony\Component\HttpFoundation\Request;
26 use Symfony\Component\HttpFoundation\Response;
35 const NAME =
"license";
37 private $uploadtree_tablename =
"";
47 private $clearingFilter;
49 private $licenseProjector;
51 protected $agentNames = AgentRef::AGENT_LIST;
53 public function __construct()
55 parent::__construct(self::NAME, array(
56 self::TITLE => _(
"License Browser"),
57 self::DEPENDENCIES => array(
"browse",
"view"),
59 self::REQUIRES_LOGIN =>
false
63 $this->uploadDao = $container->get(
'dao.upload');
64 $this->licenseDao = $container->get(
'dao.license');
65 $this->clearingDao = $container->get(
'dao.clearing');
66 $this->agentDao = $container->get(
'dao.agent');
67 $this->clearingFilter = $container->get(
'businessrules.clearing_decision_filter');
80 if (empty($Item) || empty($Upload)) {
83 $viewLicenseURI = $this->NAME .
Traceback_parm_keep(array(
"show",
"format",
"page",
"upload",
"item"));
84 $menuName = $this->Title;
86 $uploadTreeTable = $this->uploadDao->getUploadtreeTableName($Upload);
87 $itemBounds = $this->uploadDao->getItemTreeBounds($Item, $uploadTreeTable);
88 if (! $itemBounds->containsFiles()) {
93 $treeDao = $container->get(
'dao.tree');
94 $parent = $treeDao->getParentOfItem($itemBounds);
99 "format",
"page",
"upload")) .
"&item=$parent";
106 $text = _(
"license histogram");
108 menu_insert(
"View::$menuName", 99, $viewLicenseURI, $text);
109 menu_insert(
"View-Meta::$menuName", 99, $viewLicenseURI, $text);
117 protected function handle(Request $request)
119 $upload = intval($request->get(
"upload"));
121 if (!$this->uploadDao->isAccessible($upload, $groupId)) {
122 return $this->flushContent(_(
"Permission Denied"));
125 $item = intval($request->get(
"item"));
128 $left = $itemTreeBounds->getLeft();
130 return $this->flushContent(_(
"Job unpack/adj2nest hasn't completed."));
134 $vars[
'uploadId'] = $upload;
135 if ($request->get(
'show')==
'quick') {
138 $vars[
'itemId'] = $item;
140 $vars[
'micromenu'] =
Dir2Browse($this->Name, $item, NULL, $showBox = 0,
"Browse",
142 $vars[
'licenseArray'] = $this->licenseDao->getLicenseArray();
145 if (is_a($histVars,
'Symfony\\Component\\HttpFoundation\\RedirectResponse')) {
148 $vars = array_merge($vars, $histVars);
150 $vars[
'content'] =
js_url();
153 return $this->
render(
"browse.html.twig",$this->mergeWithDefault($vars));
169 $scannerAgents = array_keys($this->agentNames);
170 $scanJobProxy =
new ScanJobProxy($this->agentDao, $uploadId);
171 $scannerVars = $scanJobProxy->createAgentStatus($scannerAgents);
172 $agentMap = $scanJobProxy->getAgentMap();
176 'agentMap' => $agentMap,
177 'scanners'=>$scannerVars);
179 $selectedAgentIds = empty($selectedAgentId) ? $scanJobProxy->getLatestSuccessfulAgentIds() : $selectedAgentId;
181 if (!empty($agentMap)) {
183 $tag_pk, $itemTreeBounds, $selectedAgentIds, $groupId);
184 $vars = array_merge($vars, $licVars);
187 $this->licenseProjector =
new LicenseMap($this->
getObject(
'db.manager'),$groupId,LicenseMap::CONCLUSION,
true);
189 $childCount = $dirVars[
'iTotalRecords'];
199 if ($childCount == 0) {
200 $itemEntry = $this->uploadDao->getUploadEntry($itemTreeBounds->
getItemId(), $this->uploadtree_tablename);
201 if ($itemEntry && !
Isdir($itemEntry[
'ufile_mode'])) {
202 return new RedirectResponse(
"?mod=view-license" .
Traceback_parm_keep(array(
"upload",
"item")));
206 $vars[
'licenseUri'] =
Traceback_uri() .
"?mod=popup-license&rf=";
209 return array_merge($vars, $dirVars);
218 $isFlat = isset($_GET[
'flatten']);
219 $vars[
'isFlat'] = $isFlat;
220 $vars[
'iTotalRecords'] = $this->uploadDao->countNonArtifactDescendants($itemTreeBounds, $isFlat);
221 $uri =
Traceback_uri().
'?mod='.$this->Name.Traceback_parm_keep(array(
'upload',
'folder',
'show',
'item'));
222 $vars[
'fileSwitch'] = $isFlat ? $uri : $uri.
"&flatten=yes";
237 $fileCount = $this->uploadDao->countPlainFiles($itemTreeBounds);
238 $licenseHistogram = $this->licenseDao->getLicenseHistogram($itemTreeBounds, $agentIds);
239 $editedLicensesHist = $this->clearingDao->getClearedLicenseIdAndMultiplicities($itemTreeBounds, $groupId);
240 $mainLicenseIds = $this->clearingDao->getMainLicenseIds($itemTreeBounds->
getUploadId(), $groupId);
243 $licListUri =
Traceback_uri().
"?mod=license_list_files&item=$uploadTreeId";
245 $licListUri .=
"&tag=$tagId";
248 $licListUri .=
"&agentId=$agentId";
252 list($tableData, $totalScannerLicenseCount, $editedTotalLicenseCount)
255 $uniqueLicenseCount = count($tableData);
256 $scannerUniqueLicenseCount = count( $licenseHistogram );
257 $editedUniqueLicenseCount = count($editedLicensesHist);
258 $noScannerLicenseFoundCount = array_key_exists(LicenseDao::NO_LICENSE_FOUND, $licenseHistogram)
259 ? $licenseHistogram[LicenseDao::NO_LICENSE_FOUND][
'count'] : 0;
260 $editedNoLicenseFoundCount = array_key_exists(LicenseDao::NO_LICENSE_FOUND, $editedLicensesHist)
261 ? $editedLicensesHist[LicenseDao::NO_LICENSE_FOUND][
'count'] : 0;
263 return array(
'tableDataJson'=>json_encode($tableData),
264 'uniqueLicenseCount'=>$uniqueLicenseCount,
265 'fileCount'=>$fileCount,
266 'scannerUniqueLicenseCount'=>$scannerUniqueLicenseCount,
267 'editedUniqueLicenseCount'=>$editedUniqueLicenseCount,
268 'scannerLicenseCount'=> $totalScannerLicenseCount,
269 'editedLicenseCount'=> $editedTotalLicenseCount-$editedNoLicenseFoundCount,
270 'noScannerLicenseFoundCount'=>$noScannerLicenseFoundCount,
271 'editedNoLicenseFoundCount'=>$editedNoLicenseFoundCount,
272 'scannerLicenses'=>$licenseHistogram,
273 'editedLicenses'=>$editedLicensesHist
286 $allScannerLicenseNames = array_keys($scannerLics);
287 $allEditedLicenseNames = array_keys($editedLics);
289 $allLicNames = array_unique(array_merge($allScannerLicenseNames, $allEditedLicenseNames));
290 $realLicNames = array_diff($allLicNames, array(LicenseDao::NO_LICENSE_FOUND));
292 $totalScannerLicenseCount = 0;
293 $editedTotalLicenseCount = 0;
295 $tableData = array();
296 foreach ($realLicNames as $licenseShortName) {
298 if (array_key_exists($licenseShortName, $scannerLics)) {
299 $count = $scannerLics[$licenseShortName][
'unique'];
300 $rfId = $scannerLics[$licenseShortName][
'rf_pk'];
302 $rfId = $editedLics[$licenseShortName][
'rf_pk'];
304 $editedCount = array_key_exists($licenseShortName, $editedLics) ? $editedLics[$licenseShortName][
'count'] : 0;
306 $totalScannerLicenseCount += $count;
307 $editedTotalLicenseCount += $editedCount;
309 $scannerCountLink = ($count > 0) ?
"<a href='$licListUri&lic=" .
310 urlencode($licenseShortName) .
"'>$count</a>":
"0";
311 $editedLink = ($editedCount > 0) ? $editedCount :
"0";
313 $isMain = in_array($rfId, $mainLicenseIds);
314 $tableData[] = array($scannerCountLink, $editedLink, array($licenseShortName,$rfId,$isMain));
317 return array($tableData, $totalScannerLicenseCount, $editedTotalLicenseCount);
327 return $this->renderer->load($templateName)->render($vars);
341 register_plugin(
new BrowseLicense());
char * uploadtree_tablename
upload.uploadtree_tablename
Contains the constants and helpers for authentication of user.
static getGroupId()
Get the current user's group id.
static isAdmin()
Check if user is admin.
Various utility functions to filter ClearingDecision.
Wrapper class for license map.
RegisterMenus()
Customize submenus.
render($templateName, $vars=null, $headers=null)
getUploadHist($itemTreeBounds)
countFileListing(ItemTreeBounds $itemTreeBounds)
createLicenseHistogram($uploadTreeId, $tagId, ItemTreeBounds $itemTreeBounds, $agentIds, $groupId)
createLicenseHistogramJSarray($scannerLics, $editedLics, $licListUri, $mainLicenseIds)
showUploadHist(ItemTreeBounds $itemTreeBounds)
Given an $Uploadtree_pk, display:
renderString($templateName, $vars)
Dir2Browse($Mod, $UploadtreePk, $LinkLast=NULL, $ShowBox=1, $ShowMicro=NULL, $Enumerate=-1, $PreText='', $PostText='', $uploadtree_tablename="uploadtree")
Get an html linked string of a file browse path.
Traceback_uri()
Get the URI without query to this location.
Traceback_parm($ShowMod=1)
Get the URI 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.
list_t type structure used to keep various lists. (e.g. there are multiple lists).