FOSSology  4.4.0
Open Source License Compliance by Open Source Software
LicenseNonFunctionalGetter.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 $nonFunctionalFilesOnly;
20 
21  public function __construct($nonFunctionalFilesOnly=true)
22  {
23  $this->clearingDao = $GLOBALS['container']->get('dao.clearing');
24  $this->nonFunctionalFilesOnly = $nonFunctionalFilesOnly;
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, 'nonFunctional');
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->nonFunctionalFilesOnly) {
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  "licenses" => array($licenseName)
66  );
67  }
68  } else {
69  if ($comment) {
70  $statements[] = array(
71  "content" => $licenseName,
72  "text" => $comment,
73  "files" => array($fileName)
74  );
75  }
76  }
77  $objectAgent->heartbeat(1);
78  }
79  return array("statements" => array_values($statements));
80  }
81 }
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)