68 public function createCsv($rf=0, $allCandidates=
false, $generateJson=
false)
70 $forAllCandidates =
"WHERE marydone = true";
72 $forAllCandidates =
"";
74 $forGroupBy =
" GROUP BY rf.rf_shortname, rf.rf_fullname, rf.rf_licensetype, rf.rf_spdx_id, rf.rf_text, rc.rf_shortname, rr.rf_shortname, rf.rf_url, rf.rf_notes, rf.rf_source, rf.rf_risk, gp.group_name";
75 $sql =
"WITH marydoneCand AS (
76 SELECT * FROM license_candidate
79 SELECT DISTINCT ON(rf_pk) * FROM
81 NATURAL FULL JOIN marydoneCand)
83 rf.rf_shortname AS shortname, rf.rf_fullname AS fullname, rf.rf_spdx_id AS spdx_id, rf.rf_licensetype as license_type, rf.rf_text AS text,
84 rc.rf_shortname parent_shortname, rr.rf_shortname report_shortname, rf.rf_url AS url,
85 rf.rf_notes AS notes, rf.rf_source AS source, rf.rf_risk AS risk, gp.group_name AS group,
86 string_agg(ob_topic, ', ') obligations
87 FROM allLicenses AS rf
88 LEFT OUTER JOIN obligation_map om ON om.rf_fk = rf.rf_pk
89 LEFT OUTER JOIN obligation_ref ON ob_fk = ob_pk
90 FULL JOIN groups AS gp ON gp.group_pk = rf.group_fk
91 LEFT JOIN license_map mc ON mc.rf_fk=rf.rf_pk AND mc.usage=$2
92 LEFT JOIN license_ref rc ON mc.rf_parent=rc.rf_pk
93 LEFT JOIN license_map mr ON mr.rf_fk=rf.rf_pk AND mr.usage=$3
94 LEFT JOIN license_ref rr ON mr.rf_parent=rr.rf_pk
95 WHERE rf.rf_detector_type=$1";
97 $param = array(1, LicenseMap::CONCLUSION, LicenseMap::REPORT);
99 $stmt = __METHOD__ .
'.rf';
101 $sql .=
' AND rf.rf_pk = $'.count($param).$forGroupBy;
102 $row = $this->
dbManager->getSingleRow($sql,$param,$stmt);
103 $vars = $row ? array( $row ) : array();
106 $sql .= $forGroupBy .
', rf.rf_pk ORDER BY rf.rf_pk';
108 $res = $this->
dbManager->execute($stmt,$param);
109 $vars = $this->
dbManager->fetchAll( $res );
113 return json_encode($vars, JSON_PRETTY_PRINT);
115 $out = fopen(
'php://output',
'w');
118 'shortname',
'fullname',
'spdx_id',
'licensetype',
'text',
'parent_shortname',
119 'report_shortname',
'url',
'notes',
'source',
'risk',
'group',
121 fputs($out, $bom =( chr(0xEF) . chr(0xBB) . chr(0xBF) ));
122 fputcsv($out, $head, $this->delimiter, $this->enclosure);
123 foreach ($vars as $row) {
126 if (strlen($row[
'text']) > LicenseMap::MAX_CHAR_LIMIT) {
127 $row[
'text'] = LicenseMap::TEXT_MAX_CHAR_LIMIT;
129 fputcsv($out, $row, $this->delimiter, $this->enclosure);
131 $content = ob_get_contents();
Helper class to export license list as a CSV from the DB.
setDelimiter($delimiter=',')
Update the delimiter.
__construct(DbManager $dbManager)
createCsv($rf=0, $allCandidates=false, $generateJson=false)
Create the CSV from the DB.
setEnclosure($enclosure='"')
Update the enclosure.
Wrapper class for license map.
static convertToSpdxId($shortname, $spdxId)
Given a license's shortname and spdx id, give out spdx id to use in reports.
fo_dbManager * dbManager
fo_dbManager object
Utility functions for specific applications.