FOSSology  4.4.0
Open Source License Compliance by Open Source Software
reportSummary.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2017 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
9 use PhpOffice\PhpWord\Element\Section;
10 use PhpOffice\PhpWord\Style;
11 use PhpOffice\PhpWord\SimpleType\JcTable;
12 use PhpOffice\PhpWord\Style\Table;
13 
19 {
23  private $uploadDao;
24 
28  private $tablestyle = array("borderSize" => 2,
29  "name" => "Arial",
30  "borderColor" => "000000",
31  "cellSpacing" => 5,
32  "alignment" => JcTable::START,
33  "layout" => Table::LAYOUT_FIXED
34  );
35 
39  private $subHeadingStyle = array("size" => 9,
40  "align" => "center",
41  "bold" => true
42  );
43 
44  public function __construct()
45  {
46  global $container;
47  $this->uploadDao = $container->get('dao.upload');
48  }
49 
55  private function accumulateLicenses($licenses)
56  {
57  $allOtherLicenses = "";
58  if (!empty($licenses)) {
59  $licenses = array_unique(array_column($licenses, 'content'));
60  foreach ($licenses as $otherLicenses) {
61  $allOtherLicenses .= $otherLicenses.", ";
62  }
63  $allOtherLicenses = rtrim($allOtherLicenses, ", ");
64  }
65  return $allOtherLicenses;
66  }
67 
82  function summaryTable(Section $section, $uploadId, $userName, $mainLicenses, $licenses, $histLicenses, $otherStatement, $timestamp, $groupName, $packageUri, $assignedToUserName)
83  {
84  $cellRowContinue = array("vMerge" => "continue");
85  $firstRowStyle = array("size" => 14, "bold" => true);
86  $firstRowStyle1 = array("size" => 12, "bold" => true);
87 
88  $cellRowSpan = array("vMerge" => "restart", "valign" => "top");
89  $cellColSpan = array("gridSpan" => 3, "valign" => "center");
90 
91  $rowWidth = 200;
92  $rowWidth2 = 400;
93  $cellFirstLen = 2500;
94  $cellSecondLen = 3800;
95  $cellThirdLen = 5500;
96 
97  $allMainLicenses = $this->accumulateLicenses($mainLicenses);
98  $allOtherLicenses = $this->accumulateLicenses($licenses);
99 
100  $allHistLicenses = "";
101  if (!empty($histLicenses)) {
102  foreach ($histLicenses as $histLicense) {
103  $allHistLicenses .= $histLicense["licenseShortname"].", ";
104  }
105  $allHistLicenses = rtrim($allHistLicenses, ", ");
106  }
107 
108  $newSw360Component = array();
109  $table = $section->addTable($this->tablestyle);
110 
111  $table->addRow($rowWidth);
112  $table->addCell($cellFirstLen, $cellColSpan)->addText(htmlspecialchars(" OSS Component Clearing report"),
113  $firstRowStyle, "pStyle");
114 
115  $table->addRow($rowWidth);
116  $table->addCell($cellFirstLen, $cellRowSpan)->addText(htmlspecialchars(" Clearing Information"), $firstRowStyle, "pStyle");
117  $table->addCell($cellSecondLen)->addText(htmlspecialchars(" Department"), $firstRowStyle1, "pStyle");
118  $table->addCell($cellThirdLen)->addText(htmlspecialchars($otherStatement['ri_department']), null, "pStyle");
119 
120  $table->addRow($rowWidth);
121  $table->addCell($cellFirstLen, $cellRowContinue);
122  $table->addCell($cellSecondLen)->addText(htmlspecialchars(" Report Created by"), $firstRowStyle1, "pStyle");
123  $table->addCell($cellThirdLen)->addText(htmlspecialchars(
124  date("Y/m/d", $timestamp)." ".$userName." (".$groupName.") "), null, "pStyle");
125 
126  $table->addRow($rowWidth);
127  $table->addCell($cellFirstLen, $cellRowContinue);
128  $table->addCell($cellSecondLen)->addText(htmlspecialchars(" Analyzed by"),$firstRowStyle1, "pStyle");
129  $table->addCell($cellThirdLen)->addText(htmlspecialchars($assignedToUserName), null, "pStyle");
130 
131  $table->addRow($rowWidth);
132  $table->addCell($cellFirstLen, $cellRowContinue);
133  $table->addCell($cellSecondLen)->addText(htmlspecialchars(" Reviewed by (opt.)"),$firstRowStyle1, "pStyle");
134  $table->addCell($cellThirdLen)->addText(htmlspecialchars($otherStatement['ri_reviewed']), null, "pStyle");
135 
136  $table->addRow($rowWidth);
137  $table->addCell($cellFirstLen, $cellRowContinue);
138  $table->addCell($cellSecondLen)->addText(htmlspecialchars(" Report release date"), $firstRowStyle1, "pStyle");
139  $table->addCell($cellThirdLen)->addText(htmlspecialchars($otherStatement['ri_report_rel']), null, "pStyle");
140 
141  $table->addRow($rowWidth);
142  $table->addCell($cellFirstLen, $cellRowSpan)->addText(htmlspecialchars(" Component Information"), $firstRowStyle, "pStyle");
143  $table->addCell($cellSecondLen)->addText(htmlspecialchars(" Community"), $firstRowStyle1, "pStyle");
144  if (!empty($newSw360Component["Community"])) {
145  $table->addCell($cellThirdLen)->addText(htmlspecialchars($newSw360Component["Community"]), null, "pStyle");
146  } else {
147  $table->addCell($cellThirdLen)->addText(htmlspecialchars($otherStatement['ri_community']), null, "pStyle");
148  }
149  $table->addRow($rowWidth);
150  $table->addCell($cellFirstLen, $cellRowContinue);
151  $table->addCell($cellSecondLen)->addText(htmlspecialchars(" Component"), $firstRowStyle1, "pStyle");
152 
153  if (!empty($newSw360Component["Component"])) {
154  $table->addCell($cellThirdLen)->addText(htmlspecialchars($newSw360Component["Component"]), null, "pStyle");
155  } else {
156  $table->addCell($cellThirdLen)->addText(htmlspecialchars($otherStatement['ri_component']), null, "pStyle");
157  }
158  $table->addRow($rowWidth);
159  $table->addCell($cellFirstLen, $cellRowContinue);
160  $table->addCell($cellSecondLen)->addText(htmlspecialchars(" Version"), $firstRowStyle1, "pStyle");
161 
162  if (!empty($newSw360Component["Version"])) {
163  $table->addCell($cellThirdLen)->addText(htmlspecialchars($newSw360Component["Version"]), null, "pStyle");
164  } else {
165  $table->addCell($cellThirdLen)->addText(htmlspecialchars($otherStatement['ri_version']), null, "pStyle");
166  }
167  $table->addRow($rowWidth);
168  $table->addCell($cellFirstLen, $cellRowContinue);
169  $table->addCell($cellSecondLen)->addText(htmlspecialchars(" Component hash (SHA-1)"), $firstRowStyle1, "pStyle");
170 
171  $componentHash = $this->uploadDao->getUploadHashes($uploadId);
172 
173  $table->addCell($cellThirdLen)->addText(htmlspecialchars($componentHash["sha1"]), null, "pStyle");
174 
175  $table->addRow($rowWidth);
176  $table->addCell($cellFirstLen, $cellRowContinue);
177  $table->addCell($cellSecondLen)->addText(htmlspecialchars(" Release date"), $firstRowStyle1, "pStyle");
178 
179  if (!empty($newSw360Component["Release date"])) {
180  $table->addCell($cellThirdLen)->addText(htmlspecialchars($newSw360Component["Release date"]), null, "pStyle");
181  } else {
182  $table->addCell($cellThirdLen)->addText(htmlspecialchars($otherStatement['ri_release_date']), null, "pStyle");
183  }
184 
185  $table->addRow($rowWidth);
186  $table->addCell($cellFirstLen, $cellRowContinue);
187  $table->addCell($cellSecondLen)->addText(htmlspecialchars(" Component Id"), $firstRowStyle1, "pStyle");
188 
189  if (!empty($newSw360Component["Component Id"])) {
190  $table->addCell($cellThirdLen)->addText(htmlspecialchars($newSw360Component["Component Id"]), null, "pStyle");
191  } else {
192  if (
193  empty($otherStatement['ri_component_id']) ||
194  $otherStatement['ri_component_id'] == "NA"
195  ) {
196  $componentType = "";
197  } else {
198  $componentType = ComponentType::TYPE_MAP[
199  $otherStatement['ri_component_type']
200  ] . ": ";
201  }
202  $table->addCell($cellThirdLen)->addText(
203  $componentType . htmlspecialchars($otherStatement['ri_component_id']),
204  null, "pStyle");
205  }
206 
207  $table->addRow($rowWidth);
208  $table->addCell($cellFirstLen, $cellRowContinue);
209  $table->addCell($cellSecondLen)->addText(htmlspecialchars(" Main license(s)"), $firstRowStyle1, "pStyle");
210  if (!empty($allMainLicenses)) {
211  $table->addCell($cellThirdLen)->addText(htmlspecialchars("$allMainLicenses."), null, "pStyle");
212  } else {
213  $table->addCell($cellThirdLen)->addText(htmlspecialchars("Main License(s) Not selected."), null, "pStyle");
214  }
215 
216  $table->addRow($rowWidth2);
217  $table->addCell($cellFirstLen, $cellRowSpan)->addText(htmlspecialchars(" "), $firstRowStyle, "pStyle");
218  $table->addCell($cellSecondLen)->addText(htmlspecialchars("Other license(s)"), $firstRowStyle1, "pStyle");
219  if (!empty($allOtherLicenses)) {
220  $table->addCell($cellThirdLen)->addText(htmlspecialchars("$allOtherLicenses."), null, "pStyle");
221  } else {
222  $table->addCell($cellThirdLen)->addText(htmlspecialchars("License(s) Not Identified."), null, "pStyle");
223  }
224 
225  $table->addRow($rowWidth2);
226  $table->addCell($cellFirstLen, $cellRowSpan)->addText(htmlspecialchars(" "), $firstRowStyle, "pStyle");
227  $table->addCell($cellSecondLen)->addText(htmlspecialchars("Fossology Upload/Package Link"), $firstRowStyle1, "pStyle");
228  $table->addCell($cellThirdLen)->addText(htmlspecialchars(" ".$packageUri.""), null, "pStyle");
229 
230  $table->addRow($rowWidth2);
231  $table->addCell($cellFirstLen, $cellRowSpan)->addText(htmlspecialchars(" "), $firstRowStyle, "pStyle");
232  $table->addCell($cellSecondLen)->addText(htmlspecialchars("SW360 Portal Link"), $firstRowStyle1, "pStyle");
233  $table->addCell($cellThirdLen)->addText(htmlspecialchars($otherStatement['ri_sw360_link']), null, "pStyle");
234 
235  $table->addRow($rowWidth2);
236  $table->addCell($cellFirstLen, $cellRowSpan)->addText(htmlspecialchars(" "), $firstRowStyle, "pStyle");
237  $table->addCell($cellSecondLen)->addText(htmlspecialchars("Result of License Scan"), $firstRowStyle1, "pStyle");
238  if (!empty($allHistLicenses)) {
239  $table->addCell($cellThirdLen)->addText(htmlspecialchars("$allHistLicenses."), null, "pStyle");
240  } else {
241  $table->addCell($cellThirdLen)->addText(htmlspecialchars("No License found by the Scanner"), null, "pStyle");
242  }
243 
244  $section->addTextBreak();
245  $section->addTextBreak();
246  }
247 }
Handles report summary.
summaryTable(Section $section, $uploadId, $userName, $mainLicenses, $licenses, $histLicenses, $otherStatement, $timestamp, $groupName, $packageUri, $assignedToUserName)
Design the summaryTable of the report.
accumulateLicenses($licenses)
Remove the duplicate licenses.