* Calendar/Categrory report: Add sort option for the report

This commit is contained in:
Hadi Nategh 2017-01-06 16:15:34 +01:00
parent 4d74df2b87
commit 06bf277940
2 changed files with 21 additions and 2 deletions

View File

@ -347,7 +347,7 @@ class calendar_category_report extends calendar_ui{
// ] // ]
// //
$result = array_replace_recursive($days_output, $min_days_output); $result = array_replace_recursive($days_output, $min_days_output);
$csv_header = array (); $raw_csv = $csv_header = array ();
// create csv header // create csv header
foreach ($categories as $cat_id) foreach ($categories as $cat_id)
@ -384,8 +384,20 @@ class calendar_category_report extends calendar_ui{
// last name // last name
$n_family = array('n_family' => Api\Accounts::id2name($user_id, 'account_lastname')) ? $n_family = array('n_family' => Api\Accounts::id2name($user_id, 'account_lastname')) ?
array('n_family' => Api\Accounts::id2name($user_id, 'account_lastname')) : array(); array('n_family' => Api\Accounts::id2name($user_id, 'account_lastname')) : array();
$raw_csv[] = $n_family + $n_given+ $cats_row;
}
// comparision function for usort
function compareByFamily ($key='n_family') {
return function ($a, $b) use ($key){
return strcasecmp($a[$key], $b[$key]);
};
}
usort($raw_csv, compareByFamily($content['sort_key']));
foreach ($raw_csv as &$row)
{
// printout each row into file // printout each row into file
fputcsv($fp, array_values($n_family + $n_given+ $cats_row)); fputcsv($fp, array_values($row));
} }
// echo out csv file // echo out csv file
fpassthru($fp); fpassthru($fp);

View File

@ -60,6 +60,13 @@ Egroupware
<description value="Date range"/> <description value="Date range"/>
<date id="start" label="Start"/> <date id="start" label="Start"/>
<date id="end" label="End"/> <date id="end" label="End"/>
<hbox>
<description value="sort by" label="%s:"/>
<vbox>
<radio id="sort_key" label="Last name" options="n_family"/>
<radio id="sort_key" label="First name" options="n_given"/>
</vbox>
</hbox>
<button id="button[report]" label="Report" onclick="app.calendar.category_report_submit" background_image="1" image="template"/> <button id="button[report]" label="Report" onclick="app.calendar.category_report_submit" background_image="1" image="template"/>
</hbox> </hbox>
</template> </template>