forked from extern/egroupware
* Calendar: Some hotfixes for category report
- Fix category report does not take participants into account - Fix events located in mid of the range get miscalculated - Consider over ranged event in calculation
This commit is contained in:
parent
4ca32f82a5
commit
a719f8b01f
@ -85,10 +85,15 @@ class calendar_category_report extends calendar_ui{
|
||||
* @param int $unit unit option
|
||||
*
|
||||
*/
|
||||
public function process_days(&$events_log, &$week_sum, &$day,$day_index, $events, $cat_id, $holidays, $weekend, $min_days, $unit, $start_range)
|
||||
public function process_days(&$events_log, &$week_sum, &$day,$day_index, $events, $cat_id, $holidays, $weekend, $min_days, $unit, $start_range, $end_range)
|
||||
{
|
||||
foreach ($events as &$event)
|
||||
{
|
||||
foreach ($event['participants'] as $user_id => $status)
|
||||
{
|
||||
// if the participant has not accepted the event, not a chair or not an user then skip.
|
||||
if (!($status == 'A' || $status == 'ACHAIR') || preg_match('/^(.*<)?([a-z0-9_.-]+@[a-z0-9_.-]{5,})>?$/i',$user_id)) continue;
|
||||
|
||||
$categories = explode(',', $event['category']);
|
||||
if (!in_array($cat_id, $categories)) continue;
|
||||
|
||||
@ -101,6 +106,8 @@ class calendar_category_report extends calendar_ui{
|
||||
$previous_week_number = $week_number == 1? 53: $week_number -1;
|
||||
// check if multidays event starts before start range
|
||||
$is_over_range_event = $day_timestamp< $event['end'] && $start_range > $event['start'];
|
||||
// check if multidays event ends after end range
|
||||
$is_over_end_range = $day_timestamp< $event['end'] && $end_range < $event['end'];
|
||||
|
||||
$is_multiple_days_event = $event['start']< $day_timestamp && $day_timestamp< $event['end'];
|
||||
|
||||
@ -113,7 +120,7 @@ class calendar_category_report extends calendar_ui{
|
||||
{
|
||||
$day_diff_to_end = $event['end'] - $day_timestamp;
|
||||
$reduction_amount = $day_diff_to_end > 86400? 86400: $day_diff_to_end;
|
||||
$events_log['reductions'][$event['owner']][$cat_id] = $events_log['reductions'][$event['owner']][$cat_id] + $reduction_amount;
|
||||
$events_log['reductions'][$user_id][$cat_id] = $events_log['reductions'][$user_id][$cat_id] + $reduction_amount;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@ -122,25 +129,25 @@ class calendar_category_report extends calendar_ui{
|
||||
// we can procced calculating the amount of the event via the first day
|
||||
// and mark as counted for the rest of the days to avoid miscalculation.
|
||||
if ($event['start']< $day_timestamp && $day_timestamp< $event['end'] &&
|
||||
($events_log[$week_number][$event['id']]['counted'] ||
|
||||
$events_log[$previous_week_number][$event['id']]['counted']))
|
||||
($events_log[$user_id][$week_number][$event['id']]['counted'] ||
|
||||
$events_log[$user_id][$previous_week_number][$event['id']]['counted']))
|
||||
{
|
||||
$events_log[$week_number][$event['id']]['counted'] = true;
|
||||
$events_log[$user_id][$week_number][$event['id']]['counted'] = true;
|
||||
}
|
||||
// In case of start range is in middle of multidays event, we need to calculate the
|
||||
// amount base on the part of event on the range and keep track of counting to avoid
|
||||
// miscalculation too.
|
||||
if ($is_over_range_event &&
|
||||
!$events_log[$week_number][$event['id']]['over_range'] &&
|
||||
!$events_log[$previous_week_number][$event['id']]['over_range'])
|
||||
!$events_log[$user_id][$week_number][$event['id']]['over_range'] &&
|
||||
!$events_log[$user_id][$previous_week_number][$event['id']]['over_range'])
|
||||
{
|
||||
$events_log[$week_number][$event['id']]['counted'] = false;
|
||||
$events_log[$week_number][$event['id']]['over_range'] = true;
|
||||
$events_log[$user_id][$week_number][$event['id']]['counted'] = false;
|
||||
$events_log[$user_id][$week_number][$event['id']]['over_range'] = true;
|
||||
}
|
||||
|
||||
// if we already counted the multidays event, set the amount to 0
|
||||
// for the rest of days, to end up with a right calculation.
|
||||
if ($events_log[$week_number][$event['id']]['counted'])
|
||||
if ($events_log[$user_id][$week_number][$event['id']]['counted'] && $is_multiple_days_event)
|
||||
{
|
||||
$amount = 0;
|
||||
}
|
||||
@ -151,14 +158,18 @@ class calendar_category_report extends calendar_ui{
|
||||
{
|
||||
$amount = $event['end'] - $start_range;
|
||||
}
|
||||
else if ($is_over_end_range) // over end range multidays event
|
||||
{
|
||||
$amount = $end_range - $event['start'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$amount = $event['end'] - $event['start'];
|
||||
}
|
||||
$events_log[$week_number][$event['id']]['counted'] = true;
|
||||
$events_log[$user_id][$week_number][$event['id']]['counted'] = true;
|
||||
}
|
||||
// store day
|
||||
$day[$event['owner']][$cat_id][$event['id']] = array (
|
||||
$day[$user_id][$cat_id][$event['id']] = array (
|
||||
'weekN' => date('W', $event['start']),
|
||||
'cat_id' => $cat_id,
|
||||
'event_id' => $event['id'],
|
||||
@ -170,8 +181,9 @@ class calendar_category_report extends calendar_ui{
|
||||
// specified with min_days in their row.
|
||||
if ($min_days)
|
||||
{
|
||||
$week_sum[$event['owner']][date('W', $event['start'])][$cat_id][$event['id']][] = $amount;
|
||||
$week_sum[$event['owner']][date('W', $event['start'])][$cat_id]['min_days'] = $min_days;
|
||||
$week_sum[$user_id][date('W', $event['start'])][$cat_id][$event['id']][] = $amount;
|
||||
$week_sum[$user_id][date('W', $event['start'])][$cat_id]['min_days'] = $min_days;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -269,7 +281,8 @@ class calendar_category_report extends calendar_ui{
|
||||
$content['grid'][$row_id]['weekend'],
|
||||
$content['grid'][$row_id]['min_days'],
|
||||
$content['grid'][$row_id]['unit'],
|
||||
$content['start']
|
||||
$content['start'],
|
||||
$content['end']
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -331,7 +344,8 @@ class calendar_category_report extends calendar_ui{
|
||||
{
|
||||
$csv_header [] = $api_cats->id2name($cat_id);
|
||||
}
|
||||
array_unshift($csv_header, 'user_fullname');
|
||||
array_unshift($csv_header, 'n_given');
|
||||
array_unshift($csv_header, 'n_family');
|
||||
|
||||
// file pointer
|
||||
$fp = fopen('php://output', 'w');
|
||||
@ -354,8 +368,14 @@ class calendar_category_report extends calendar_ui{
|
||||
($cats_data[$cat_id]['amount'] - $events_log['reductions'][$user_id][$cat_id]) /
|
||||
$cats_data[$cat_id]['unit']: 0);
|
||||
}
|
||||
// first name
|
||||
$n_given = array('n_given' => Api\Accounts::id2name($user_id, 'account_firstname')) ?
|
||||
array('n_given' => Api\Accounts::id2name($user_id, 'account_firstname')) : array();
|
||||
// last name
|
||||
$n_family = array('n_family' => Api\Accounts::id2name($user_id, 'account_lastname')) ?
|
||||
array('n_family' => Api\Accounts::id2name($user_id, 'account_lastname')) : array();
|
||||
// printout each row into file
|
||||
fputcsv($fp, array_values(array(Api\Accounts::id2name($user_id, 'account_fullname')) + $cats_row));
|
||||
fputcsv($fp, array_values($n_family + $n_given+ $cats_row));
|
||||
}
|
||||
// echo out csv file
|
||||
fpassthru($fp);
|
||||
|
Loading…
Reference in New Issue
Block a user