8 namespace Fossology\Lib\Proxy;
12 const CANDIDATE_PREFIX =
'candidatePrefix';
13 const OPT_COLUMNS =
'columns';
17 private $allColumns = array(
'rf_pk',
'rf_spdx_id',
'rf_shortname',
'rf_text',
18 'rf_url',
'rf_add_date',
'rf_copyleft',
'rf_fullname',
'rf_notes',
19 'marydone',
'rf_active',
'rf_text_updatable',
'rf_md5',
'rf_detector_type',
20 'rf_source',
'group_fk');
27 public function __construct($groupId, $options=array(), $dbViewName=
'license_all')
29 $this->groupId = $groupId;
31 $dbViewQuery = $this->queryOnlyLicenseRef($options);
32 parent::__construct($dbViewQuery, $dbViewName);
35 $dbViewQuery = $this->queryLicenseCandidate($options);
36 if (! array_key_exists(
'diff', $options)) {
37 $dbViewQuery .=
" UNION ".$this->queryOnlyLicenseRef($options);
39 parent::__construct($dbViewQuery, $dbViewName);
43 private function queryLicenseCandidate($options)
45 $columns = array_key_exists(self::OPT_COLUMNS, $options) ? $options[self::OPT_COLUMNS] : $this->allColumns;
46 if (array_key_exists(self::CANDIDATE_PREFIX, $options)) {
47 $shortnameId = array_search(
'rf_shortname',$columns);
48 if ($shortnameId !==
false) {
49 $columns[$shortnameId] =
"'". pg_escape_string($options[self::CANDIDATE_PREFIX]).
'\'||rf_shortname AS rf_shortname
';
52 $gluedColumns = implode(',
', $columns);
53 $dbViewQuery = "SELECT $gluedColumns FROM license_candidate WHERE group_fk=$this->groupId";
54 if (array_key_exists('extraCondition
', $options)) {
55 $dbViewQuery .= " AND $options[extraCondition]";
60 private function queryOnlyLicenseRef($options)
62 $columns = array_key_exists(self::OPT_COLUMNS, $options) ? $options[self::OPT_COLUMNS] : $this->allColumns;
63 $groupFkPos = array_search('group_fk
',$columns);
65 $columns[$groupFkPos] = '0 AS group_fk
';
67 $gluedColumns = implode(',
', $columns);
68 $dbViewQuery = "SELECT $gluedColumns FROM ONLY license_ref";
69 if (array_key_exists('extraCondition
', $options)) {
70 $dbViewQuery .= " WHERE $options[extraCondition]";
__construct($groupId, $options=array(), $dbViewName='license_all')