23 const CANDIDATE_PREFIX =
'candidatePrefix';
24 const OPT_COLUMNS =
'columns';
28 private $allColumns = array(
'rf_pk',
'rf_shortname',
'rf_text',
'rf_url',
'rf_add_date',
'rf_copyleft',
'rf_fullname',
29 'rf_notes',
'marydone',
'rf_active',
'rf_text_updatable',
'rf_md5',
'rf_detector_type',
'rf_source',
37 public function __construct($groupId, $options=array(), $dbViewName=
'license_all')
39 $this->groupId = $groupId;
41 $dbViewQuery = $this->queryOnlyLicenseRef($options);
42 parent::__construct($dbViewQuery, $dbViewName);
45 $dbViewQuery = $this->queryLicenseCandidate($options);
46 if (! array_key_exists(
'diff', $options)) {
47 $dbViewQuery .=
" UNION ".$this->queryOnlyLicenseRef($options);
49 parent::__construct($dbViewQuery, $dbViewName);
53 private function queryLicenseCandidate($options)
55 $columns = array_key_exists(self::OPT_COLUMNS, $options) ? $options[self::OPT_COLUMNS] : $this->allColumns;
56 if (array_key_exists(self::CANDIDATE_PREFIX, $options)) {
57 $shortnameId = array_search(
'rf_shortname',$columns);
58 if ($shortnameId !==
false) {
59 $columns[$shortnameId] =
"'". pg_escape_string($options[self::CANDIDATE_PREFIX]).
'\'||rf_shortname AS rf_shortname
'; 62 $gluedColumns = implode(',
', $columns); 63 $dbViewQuery = "SELECT $gluedColumns FROM license_candidate WHERE group_fk=$this->groupId"; 64 if (array_key_exists('extraCondition
', $options)) { 65 $dbViewQuery .= " AND $options[extraCondition]"; 70 private function queryOnlyLicenseRef($options) 72 $columns = array_key_exists(self::OPT_COLUMNS, $options) ? $options[self::OPT_COLUMNS] : $this->allColumns; 73 $groupFkPos = array_search('group_fk
',$columns); 75 $columns[$groupFkPos] = '0 AS group_fk
'; 77 $gluedColumns = implode(',
', $columns); 78 $dbViewQuery = "SELECT $gluedColumns FROM ONLY license_ref"; 79 if (array_key_exists('extraCondition
', $options)) { 80 $dbViewQuery .= " WHERE $options[extraCondition]"; __construct($groupId, $options=array(), $dbViewName='license_all')