mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-28 01:29:05 +01:00
* Calendar: Some hot fixes for category report
- Fix category report does not take participants into account - Fix events located in mid of the range get miscalculated
This commit is contained in:
parent
10f77aca18
commit
4f922d1eae
@ -85,10 +85,16 @@ class calendar_category_report extends calendar_ui{
|
|||||||
* @param int $unit unit option
|
* @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 ($events as &$event)
|
||||||
{
|
{
|
||||||
|
foreach ($event['participants'] as $user_id => $status)
|
||||||
|
{
|
||||||
|
// if the participant has not accepted the event or not a chair
|
||||||
|
// skip it.
|
||||||
|
if (!($status == 'A' || $status == 'ACHAIR')) continue;
|
||||||
|
|
||||||
$categories = explode(',', $event['category']);
|
$categories = explode(',', $event['category']);
|
||||||
if (!in_array($cat_id, $categories)) continue;
|
if (!in_array($cat_id, $categories)) continue;
|
||||||
|
|
||||||
@ -101,6 +107,8 @@ class calendar_category_report extends calendar_ui{
|
|||||||
$previous_week_number = $week_number == 1? 53: $week_number -1;
|
$previous_week_number = $week_number == 1? 53: $week_number -1;
|
||||||
// check if multidays event starts before start range
|
// check if multidays event starts before start range
|
||||||
$is_over_range_event = $day_timestamp< $event['end'] && $start_range > $event['start'];
|
$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'];
|
$is_multiple_days_event = $event['start']< $day_timestamp && $day_timestamp< $event['end'];
|
||||||
|
|
||||||
@ -113,7 +121,7 @@ class calendar_category_report extends calendar_ui{
|
|||||||
{
|
{
|
||||||
$day_diff_to_end = $event['end'] - $day_timestamp;
|
$day_diff_to_end = $event['end'] - $day_timestamp;
|
||||||
$reduction_amount = $day_diff_to_end > 86400? 86400: $day_diff_to_end;
|
$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;
|
continue;
|
||||||
}
|
}
|
||||||
@ -122,25 +130,25 @@ class calendar_category_report extends calendar_ui{
|
|||||||
// we can procced calculating the amount of the event via the first day
|
// 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.
|
// and mark as counted for the rest of the days to avoid miscalculation.
|
||||||
if ($event['start']< $day_timestamp && $day_timestamp< $event['end'] &&
|
if ($event['start']< $day_timestamp && $day_timestamp< $event['end'] &&
|
||||||
($events_log[$week_number][$event['id']]['counted'] ||
|
($events_log[$user_id][$week_number][$event['id']]['counted'] ||
|
||||||
$events_log[$previous_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
|
// 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
|
// amount base on the part of event on the range and keep track of counting to avoid
|
||||||
// miscalculation too.
|
// miscalculation too.
|
||||||
if ($is_over_range_event &&
|
if ($is_over_range_event &&
|
||||||
!$events_log[$week_number][$event['id']]['over_range'] &&
|
!$events_log[$user_id][$week_number][$event['id']]['over_range'] &&
|
||||||
!$events_log[$previous_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[$user_id][$week_number][$event['id']]['counted'] = false;
|
||||||
$events_log[$week_number][$event['id']]['over_range'] = true;
|
$events_log[$user_id][$week_number][$event['id']]['over_range'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we already counted the multidays event, set the amount to 0
|
// if we already counted the multidays event, set the amount to 0
|
||||||
// for the rest of days, to end up with a right calculation.
|
// 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;
|
$amount = 0;
|
||||||
}
|
}
|
||||||
@ -151,14 +159,18 @@ class calendar_category_report extends calendar_ui{
|
|||||||
{
|
{
|
||||||
$amount = $event['end'] - $start_range;
|
$amount = $event['end'] - $start_range;
|
||||||
}
|
}
|
||||||
|
else if ($is_over_end_range) // over end range multidays event
|
||||||
|
{
|
||||||
|
$amount = $end_range - $event['start'];
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$amount = $event['end'] - $event['start'];
|
$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
|
// store day
|
||||||
$day[$event['owner']][$cat_id][$event['id']] = array (
|
$day[$user_id][$cat_id][$event['id']] = array (
|
||||||
'weekN' => date('W', $event['start']),
|
'weekN' => date('W', $event['start']),
|
||||||
'cat_id' => $cat_id,
|
'cat_id' => $cat_id,
|
||||||
'event_id' => $event['id'],
|
'event_id' => $event['id'],
|
||||||
@ -170,8 +182,9 @@ class calendar_category_report extends calendar_ui{
|
|||||||
// specified with min_days in their row.
|
// specified with min_days in their row.
|
||||||
if ($min_days)
|
if ($min_days)
|
||||||
{
|
{
|
||||||
$week_sum[$event['owner']][date('W', $event['start'])][$cat_id][$event['id']][] = $amount;
|
$week_sum[$user_id][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]['min_days'] = $min_days;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -269,7 +282,8 @@ class calendar_category_report extends calendar_ui{
|
|||||||
$content['grid'][$row_id]['weekend'],
|
$content['grid'][$row_id]['weekend'],
|
||||||
$content['grid'][$row_id]['min_days'],
|
$content['grid'][$row_id]['min_days'],
|
||||||
$content['grid'][$row_id]['unit'],
|
$content['grid'][$row_id]['unit'],
|
||||||
$content['start']
|
$content['start'],
|
||||||
|
$content['end']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -331,7 +345,8 @@ class calendar_category_report extends calendar_ui{
|
|||||||
{
|
{
|
||||||
$csv_header [] = $api_cats->id2name($cat_id);
|
$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
|
// file pointer
|
||||||
$fp = fopen('php://output', 'w');
|
$fp = fopen('php://output', 'w');
|
||||||
@ -354,8 +369,14 @@ class calendar_category_report extends calendar_ui{
|
|||||||
($cats_data[$cat_id]['amount'] - $events_log['reductions'][$user_id][$cat_id]) /
|
($cats_data[$cat_id]['amount'] - $events_log['reductions'][$user_id][$cat_id]) /
|
||||||
$cats_data[$cat_id]['unit']: 0);
|
$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
|
// 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
|
// echo out csv file
|
||||||
fpassthru($fp);
|
fpassthru($fp);
|
||||||
|
Loading…
Reference in New Issue
Block a user