66 public function export($cp_pk=0, $generateJson=
false)
72 $whereClause =
"WHERE cp.cp_pk = $1";
84 STRING_AGG(CASE WHEN cplm.removing = false THEN lr.rf_shortname END, ', ' ORDER BY lr.rf_shortname) as licenses_to_add,
85 STRING_AGG(CASE WHEN cplm.removing = true THEN lr.rf_shortname END, ', ' ORDER BY lr.rf_shortname) as licenses_to_remove
87 LEFT JOIN users u ON cp.user_fk = u.user_pk
88 LEFT JOIN groups g ON cp.group_fk = g.group_pk
89 LEFT JOIN custom_phrase_license_map cplm ON cp.cp_pk = cplm.cp_fk
90 LEFT JOIN license_ref lr ON cplm.rf_fk = lr.rf_pk
92 GROUP BY cp.cp_pk, cp.text, cp.acknowledgement, cp.comments,
93 cp.created_date, cp.is_active, u.user_name, g.group_name
94 ORDER BY cp.created_date DESC";
96 $result = $this->
dbManager->getRows($sql, $params);
129 foreach ($result as $row) {
132 $row[
'acknowledgement'] ?:
'',
133 $row[
'comments'] ?:
'',
134 $row[
'created_date'],
135 $row[
'is_active'] ?
'true' :
'false',
136 $row[
'user_name'] ?:
'',
137 $row[
'group_name'] ?:
'',
138 $row[
'licenses_to_add'] ?:
'',
139 $row[
'licenses_to_remove'] ?:
''
156 foreach ($result as $row) {
158 'text' => $row[
'text'],
159 'acknowledgement' => $row[
'acknowledgement'] ?:
'',
160 'comments' => $row[
'comments'] ?:
'',
161 'created_date' => $row[
'created_date'],
162 'is_active' => $row[
'is_active'] ?
true :
false,
163 'created_by' => $row[
'user_name'] ?:
'',
164 'group' => $row[
'group_name'] ?:
'',
165 'licenses_to_add' => $row[
'licenses_to_add'] ? explode(
', ', $row[
'licenses_to_add']) : array(),
166 'licenses_to_remove' => $row[
'licenses_to_remove'] ? explode(
', ', $row[
'licenses_to_remove']) : array()
170 return json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
181 foreach ($array as $key => $value) {
187 if (strpos($value, $this->delimiter) !==
false ||
188 strpos($value, $this->enclosure) !==
false ||
189 strpos($value,
"\n") !==
false ||
190 strpos($value,
"\r") !==
false) {
191 $value = $this->enclosure . str_replace($this->enclosure, $this->enclosure . $this->enclosure, $value) .
$this->enclosure;
Helper class to export custom text phrases as CSV/JSON from the DB.
createCsvContent($result)
Create CSV content from result array.
__construct(DbManager $dbManager)
setEnclosure($enclosure='"')
Update the enclosure.
createJson($result)
Create JSON content from result array.
setDelimiter($delimiter=',')
Update the delimiter.
arrayToCsvLine($array)
Convert array to CSV line.
export($cp_pk=0, $generateJson=false)
Create the CSV/JSON export from the DB.
fo_dbManager * dbManager
fo_dbManager object
Utility functions for specific applications.