FOSSology  4.5.1
Open Source License Compliance by Open Source Software
LicenseMainGetter.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2016-2017 Siemens AG
4  Author: Daniele Fognini, Shaheem Azmal M MD
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 
9 namespace Fossology\Lib\Report;
10 
14 
16 {
18  private $clearingDao;
19 
21  private $licenseDao;
22 
23  public function __construct()
24  {
25  global $container;
26 
27  $this->clearingDao = $container->get('dao.clearing');
28  $this->licenseDao = $container->get('dao.license');
29 
30  parent::__construct($groupBy = 'text');
31  }
32 
33  protected function getStatements($uploadId, $uploadTreeTableName, $groupId = null)
34  {
35  $dbManager = $GLOBALS['container']->get('db.manager');
36  $licenseMap = new LicenseMap($dbManager, $groupId, LicenseMap::REPORT, true);
37  $mainLicIds = $this->clearingDao->getMainLicenseIds($uploadId, $groupId);
38 
39  $allStatements = array();
40  foreach ($mainLicIds as $originLicenseId) {
41  $allLicenseCols = $this->licenseDao->getLicenseById($originLicenseId, $groupId);
42  // Null-check: if the license is missing, log and skip this ID.
43  if ($allLicenseCols === null) {
44  error_log("Error: License ID " . $originLicenseId . " not found in the database.");
45  exit;
46  }
47  $allStatements[] = array(
48  'licenseId' => $originLicenseId,
49  'risk' => $allLicenseCols->getRisk(),
50  'content' => $licenseMap->getProjectedSpdxId($originLicenseId),
51  'text' => $allLicenseCols->getText(),
52  'name' => $licenseMap->getProjectedShortname($originLicenseId, $allLicenseCols->getShortName())
53  );
54  }
55  return $allStatements;
56  }
57 
58  public function getCleared($uploadId, $objectAgent, $groupId=null, $extended=true, $agentcall=null, $isUnifiedReport=false)
59  {
60  $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
61  $statements = $this->getStatements($uploadId, $uploadTreeTableName, $groupId);
62  if (!$extended) {
63  for ($i=0; $i<=count($statements); $i++) {
64  unset($statements[$i]['risk']);
65  unset($statements[$i]['licenseId']);
66  }
67  }
68  return array("statements" => array_values($statements));
69  }
70 }
Wrapper class for license map.
Definition: LicenseMap.php:19
getStatements($uploadId, $uploadTreeTableName, $groupId=null)