FOSSology  4.4.0
Open Source License Compliance by Open Source Software
LicenseIrrelevantGetter.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2017 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 $irreleavntFilesOnly;
20 
21  public function __construct($irreleavntFilesOnly=true)
22  {
23  $this->clearingDao = $GLOBALS['container']->get('dao.clearing');
24  $this->irreleavntFilesOnly = $irreleavntFilesOnly;
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, 'irrelevant');
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->irreleavntFilesOnly) {
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  if (!empty($objectAgent)) {
79  $objectAgent->heartbeat(1);
80  }
81  }
82  return array("statements" => array_values($statements));
83  }
84 }
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)