FOSSology  4.4.0
Open Source License Compliance by Open Source Software
LicenseDNUGetter.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2020 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 namespace Fossology\Lib\Report;
9 
12 
14 {
16  private $clearingDao;
17 
19  private $DNUFilesOnly;
20 
21  public function __construct($DNUFilesOnly=true)
22  {
23  $this->clearingDao = $GLOBALS['container']->get('dao.clearing');
24  $this->DNUFilesOnly = $DNUFilesOnly;
25  parent::__construct($groupBy = 'text');
26  }
27 
34  protected function getStatements($uploadId, $uploadTreeTableName, $groupId=null)
35  {
36  $itemTreeBounds = $this->uploadDao->getParentItemBounds($uploadId,$uploadTreeTableName);
37  return $this->clearingDao->getFilesForDecisionTypeFolderLevel($itemTreeBounds, $groupId, true, 'doNotUse');
38  }
39 
45  protected function groupStatements($ungrupedStatements, $extended, $agentcall, $isUnifiedReport, $objectAgent)
46  {
47  $statements = array();
48  foreach ($ungrupedStatements as $statement) {
49  $fileName = $statement['fileName'];
50  $dirName = dirname($statement['fileName']);
51  $baseName = basename($statement['fileName']);
52  $comment = $statement['comment'];
53  $licenseName = LicenseRef::convertToSpdxId($statement['shortname'],
54  $statement['spdx_id']);
55  if ($this->DNUFilesOnly) {
56  if (array_key_exists($fileName, $statements)) {
57  $currentLics = &$statements[$fileName]["licenses"];
58  if (! in_array($licenseName, $currentLics)) {
59  $currentLics[] = $licenseName;
60  }
61  } else {
62  $statements[$fileName] = array(
63  "content" => convertToUTF8($dirName, false),
64  "fileName" => $baseName,
65  "fullPath" => convertToUTF8($fileName, false),
66  "licenses" => array($licenseName)
67  );
68  }
69  } else {
70  if ($comment) {
71  $statements[] = array(
72  "content" => $licenseName,
73  "text" => $comment,
74  "files" => array($fileName)
75  );
76  }
77  }
78  $objectAgent->heartbeat(1);
79  }
80  return array("statements" => array_values($statements));
81  }
82 }
static convertToSpdxId($shortname, $spdxId)
Given a license's shortname and spdx id, give out spdx id to use in reports.
Definition: LicenseRef.php:106
groupStatements($ungrupedStatements, $extended, $agentcall, $isUnifiedReport, $objectAgent)
getStatements($uploadId, $uploadTreeTableName, $groupId=null)
if(! defined('ENT_SUBSTITUTE')) convertToUTF8($content, $toHTML=true)