FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
reportSummary.php
1 <?php
2 /*
3  Copyright (C) 2017, Siemens AG
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  version 2 as published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
20 use \PhpOffice\PhpWord\Style;
21 
27 {
31  private $uploadDao;
32 
36  private $tablestyle = array("borderSize" => 2,
37  "name" => "Arial",
38  "borderColor" => "000000",
39  "cellSpacing" => 5
40  );
41 
45  private $subHeadingStyle = array("size" => 9,
46  "align" => "center",
47  "bold" => true
48  );
49 
50  public function __construct()
51  {
52  global $container;
53  $this->uploadDao = $container->get('dao.upload');
54  }
55 
61  private function accumulateLicenses($licenses)
62  {
63  if (!empty($licenses)) {
64  $licenses = array_unique(array_column($licenses, 'content'));
65  foreach ($licenses as $otherLicenses) {
66  $allOtherLicenses .= $otherLicenses.", ";
67  }
68  $allOtherLicenses = rtrim($allOtherLicenses, ", ");
69  }
70  return $allOtherLicenses;
71  }
72 
86  function summaryTable(Section $section, $uploadId, $userName, $mainLicenses, $licenses, $histLicenses, $otherStatement, $timestamp, $groupName, $packageUri)
87  {
88  $cellRowContinue = array("vMerge" => "continue");
89  $firstRowStyle = array("size" => 14, "bold" => true);
90  $firstRowStyle1 = array("size" => 12, "bold" => true);
91 
92  $cellRowSpan = array("vMerge" => "restart", "valign" => "top");
93  $cellColSpan = array("gridSpan" => 3, "valign" => "center");
94 
95  $rowWidth = 200;
96  $rowWidth2 = 400;
97  $cellFirstLen = 2500;
98  $cellSecondLen = 3800;
99  $cellThirdLen = 5500;
100 
101  $allMainLicenses = $this->accumulateLicenses($mainLicenses);
102  $allOtherLicenses = $this->accumulateLicenses($licenses);
103 
104  if (!empty($histLicenses)) {
105  foreach ($histLicenses as $histLicense) {
106  $allHistLicenses .= $histLicense["licenseShortname"].", ";
107  }
108  $allHistLicenses = rtrim($allHistLicenses, ", ");
109  }
110 
111  $newSw360Component = array();
112  $table = $section->addTable($this->tablestyle);
113 
114  $table->addRow($rowWidth);
115  $table->addCell($cellFirstLen, $cellColSpan)->addText(htmlspecialchars(" OSS Component Clearing report"),
116  $firstRowStyle, "pStyle");
117 
118  $table->addRow($rowWidth);
119  $table->addCell($cellFirstLen, $cellRowSpan)->addText(htmlspecialchars(" Clearing Information"), $firstRowStyle, "pStyle");
120  $table->addCell($cellSecondLen)->addText(htmlspecialchars(" Department"), $firstRowStyle1, "pStyle");
121  $table->addCell($cellThirdLen)->addText(htmlspecialchars($otherStatement['ri_department']), null, "pStyle");
122 
123  $table->addRow($rowWidth);
124  $table->addCell($cellFirstLen, $cellRowContinue);
125  $table->addCell($cellSecondLen)->addText(htmlspecialchars(" Prepared by"), $firstRowStyle1, "pStyle");
126  $table->addCell($cellThirdLen)->addText(htmlspecialchars(" "
127  .date("Y/m/d", $timestamp)." ".$userName." (".$groupName.") "), null, "pStyle");
128  $table->addRow($rowWidth);
129  $table->addCell($cellFirstLen, $cellRowContinue);
130  $table->addCell($cellSecondLen)->addText(htmlspecialchars(" Reviewed by (opt.)"),$firstRowStyle1, "pStyle");
131  $table->addCell($cellThirdLen)->addText(htmlspecialchars($otherStatement['ri_reviewed']), null, "pStyle");
132 
133  $table->addRow($rowWidth);
134  $table->addCell($cellFirstLen, $cellRowContinue);
135  $table->addCell($cellSecondLen)->addText(htmlspecialchars(" Report release date"), $firstRowStyle1, "pStyle");
136  $table->addCell($cellThirdLen)->addText(htmlspecialchars($otherStatement['ri_report_rel']), null, "pStyle");
137 
138  $table->addRow($rowWidth);
139  $table->addCell($cellFirstLen, $cellRowSpan)->addText(htmlspecialchars(" Component Information"), $firstRowStyle, "pStyle");
140  $table->addCell($cellSecondLen)->addText(htmlspecialchars(" Community"), $firstRowStyle1, "pStyle");
141  if (!empty($newSw360Component["Community"])) {
142  $table->addCell($cellThirdLen)->addText(htmlspecialchars($newSw360Component["Community"]), null, "pStyle");
143  } else {
144  $table->addCell($cellThirdLen)->addText(htmlspecialchars($otherStatement['ri_community']), null, "pStyle");
145  }
146  $table->addRow($rowWidth);
147  $table->addCell($cellFirstLen, $cellRowContinue);
148  $table->addCell($cellSecondLen)->addText(htmlspecialchars(" Component"), $firstRowStyle1, "pStyle");
149 
150  if (!empty($newSw360Component["Component"])) {
151  $table->addCell($cellThirdLen)->addText(htmlspecialchars($newSw360Component["Component"]), null, "pStyle");
152  } else {
153  $table->addCell($cellThirdLen)->addText(htmlspecialchars($otherStatement['ri_component']), null, "pStyle");
154  }
155  $table->addRow($rowWidth);
156  $table->addCell($cellFirstLen, $cellRowContinue);
157  $table->addCell($cellSecondLen)->addText(htmlspecialchars(" Version"), $firstRowStyle1, "pStyle");
158 
159  if (!empty($newSw360Component["Version"])) {
160  $table->addCell($cellThirdLen)->addText(htmlspecialchars($newSw360Component["Version"]), null, "pStyle");
161  } else {
162  $table->addCell($cellThirdLen)->addText(htmlspecialchars($otherStatement['ri_version']), null, "pStyle");
163  }
164  $table->addRow($rowWidth);
165  $table->addCell($cellFirstLen, $cellRowContinue);
166  $table->addCell($cellSecondLen)->addText(htmlspecialchars(" Component hash (SHA-1)"), $firstRowStyle1, "pStyle");
167 
168  $componentHash = $this->uploadDao->getUploadHashes($uploadId);
169 
170  $table->addCell($cellThirdLen)->addText(htmlspecialchars($componentHash["sha1"]), null, "pStyle");
171 
172  $table->addRow($rowWidth);
173  $table->addCell($cellFirstLen, $cellRowContinue);
174  $table->addCell($cellSecondLen)->addText(htmlspecialchars(" Release date"), $firstRowStyle1, "pStyle");
175 
176  if (!empty($newSw360Component["Release date"])) {
177  $table->addCell($cellThirdLen)->addText(htmlspecialchars($newSw360Component["Release date"]), null, "pStyle");
178  } else {
179  $table->addCell($cellThirdLen)->addText(htmlspecialchars($otherStatement['ri_release_date']), null, "pStyle");
180  }
181 
182  $table->addRow($rowWidth);
183  $table->addCell($cellFirstLen, $cellRowContinue);
184  $table->addCell($cellSecondLen)->addText(htmlspecialchars(" Main license(s)"), $firstRowStyle1, "pStyle");
185  if (!empty($allMainLicenses)) {
186  $table->addCell($cellThirdLen)->addText(htmlspecialchars("$allMainLicenses."), null, "pStyle");
187  } else {
188  $table->addCell($cellThirdLen)->addText(htmlspecialchars("Main License(s) Not selected."), null, "pStyle");
189  }
190 
191  $table->addRow($rowWidth2);
192  $table->addCell($cellFirstLen, $cellRowSpan)->addText(htmlspecialchars(" "), $firstRowStyle, "pStyle");
193  $table->addCell($cellSecondLen)->addText(htmlspecialchars("Other license(s)"), $firstRowStyle1, "pStyle");
194  if (!empty($allOtherLicenses)) {
195  $table->addCell($cellThirdLen)->addText(htmlspecialchars("$allOtherLicenses."), null, "pStyle");
196  } else {
197  $table->addCell($cellThirdLen)->addText(htmlspecialchars("License(s) Not Identified."), null, "pStyle");
198  }
199 
200  $table->addRow($rowWidth2);
201  $table->addCell($cellFirstLen, $cellRowSpan)->addText(htmlspecialchars(" "), $firstRowStyle, "pStyle");
202  $table->addCell($cellSecondLen)->addText(htmlspecialchars("Fossology Upload/Package Link"), $firstRowStyle1, "pStyle");
203  $table->addCell($cellThirdLen)->addText(htmlspecialchars(" ".$packageUri.""), null, "pStyle");
204 
205  $table->addRow($rowWidth2);
206  $table->addCell($cellFirstLen, $cellRowSpan)->addText(htmlspecialchars(" "), $firstRowStyle, "pStyle");
207  $table->addCell($cellSecondLen)->addText(htmlspecialchars("SW360 Portal Link"), $firstRowStyle1, "pStyle");
208  $table->addCell($cellThirdLen)->addText(htmlspecialchars($otherStatement['ri_sw360_link']), null, "pStyle");
209 
210  $table->addRow($rowWidth2);
211  $table->addCell($cellFirstLen, $cellRowSpan)->addText(htmlspecialchars(" "), $firstRowStyle, "pStyle");
212  $table->addCell($cellSecondLen)->addText(htmlspecialchars("Result of License Scan"), $firstRowStyle1, "pStyle");
213  if (!empty($allHistLicenses)) {
214  $table->addCell($cellThirdLen)->addText(htmlspecialchars("$allHistLicenses."), null, "pStyle");
215  } else {
216  $table->addCell($cellThirdLen)->addText(htmlspecialchars("No License found by the Scanner"), null, "pStyle");
217  }
218 
219  $section->addTextBreak();
220  $section->addTextBreak();
221  }
222 }
accumulateLicenses($licenses)
Remove the duplicate licenses.
Handles report summary.
summaryTable(Section $section, $uploadId, $userName, $mainLicenses, $licenses, $histLicenses, $otherStatement, $timestamp, $groupName, $packageUri)
Design the summaryTable of the report.