48 public function export($cp_pk=0, $generateJson=
false)
54 $whereClause =
"WHERE cp.cp_pk = $1";
71 LEFT JOIN users u ON cp.user_fk = u.user_pk
72 LEFT JOIN groups g ON cp.group_fk = g.group_pk
73 LEFT JOIN custom_phrase_license_map cplm ON cp.cp_pk = cplm.cp_fk
74 LEFT JOIN license_ref lr ON cplm.rf_fk = lr.rf_pk
76 ORDER BY cp.created_date DESC, cp.cp_pk, lr.rf_shortname";
78 $rows = $this->
dbManager->getRows($sql, $params);
81 foreach ($rows as $row) {
82 $cpPk = $row[
'cp_pk'];
83 if (!isset($phrases[$cpPk])) {
84 $phrases[$cpPk] = array(
85 'text' => $row[
'text'],
86 'created_date' => $row[
'created_date'],
89 'is_active' => $this->
dbManager->booleanFromDb($row[
'is_active']),
90 'user_name' => $row[
'user_name'] ?:
'',
91 'group_name' => $row[
'group_name'] ?:
'',
95 if (!empty($row[
'rf_shortname'])) {
96 $phrases[$cpPk][
'licenses'][] = array(
97 'shortname' => $row[
'rf_shortname'],
98 'removing' => $this->
dbManager->booleanFromDb($row[
'removing']),
99 'comment' => $row[
'comment'] ?:
'',
100 'reportinfo' => $row[
'reportinfo'] ?:
'',
101 'acknowledgement' => $row[
'acknowledgement'] ?:
''
107 return $this->
createJson(array_values($phrases));
136 foreach ($phrases as $phrase) {
141 if (empty($phrase[
'licenses'])) {
144 $phrase[
'created_date'],
145 $phrase[
'is_active'] ?
'true' :
'false',
146 $phrase[
'user_name'],
147 $phrase[
'group_name'],
151 foreach ($phrase[
'licenses'] as $lic) {
154 $phrase[
'created_date'],
155 $phrase[
'is_active'] ?
'true' :
'false',
156 $phrase[
'user_name'],
157 $phrase[
'group_name'],
159 $lic[
'removing'] ?
'true' :
'false',
180 foreach ($phrases as $phrase) {
182 'text' => $phrase[
'text'],
183 'created_date' => $phrase[
'created_date'],
184 'is_active' => (
bool) $phrase[
'is_active'],
185 'created_by' => $phrase[
'user_name'],
186 'group' => $phrase[
'group_name'],
187 'licenses' => array_map(
function ($lic) {
189 'shortname' => $lic[
'shortname'],
190 'removing' => (
bool) $lic[
'removing'],
191 'comment' => $lic[
'comment'],
192 'reportinfo' => $lic[
'reportinfo'],
193 'acknowledgement' => $lic[
'acknowledgement']
195 }, $phrase[
'licenses'])
199 return json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
210 foreach ($array as $key => $value) {
216 if (strpos($value, $this->delimiter) !==
false ||
217 strpos($value, $this->enclosure) !==
false ||
218 strpos($value,
"\n") !==
false ||
219 strpos($value,
"\r") !==
false) {
220 $value = $this->enclosure . str_replace($this->enclosure, $this->enclosure . $this->enclosure, $value) .
$this->enclosure;
static escapeNewlines($value)
Flatten real newlines to a literal so a field stays on one physical CSV line. Backslashes are escap...
Helper class to export custom text phrases as CSV/JSON from the DB.
__construct(DbManager $dbManager)
createJson($phrases)
Create JSON content from result array.
arrayToCsvLine($array)
Convert array to CSV line.
export($cp_pk=0, $generateJson=false)
Create the CSV/JSON export from the DB.
createCsvContent($phrases)
Create CSV content from result array.
fo_dbManager * dbManager
fo_dbManager object
Utility functions for specific applications.