- return $result;
- }
-
- // getGroupedRecordsForInterval - returns time records for a user for a given interval of dates grouped in an array of dates.
- // Example: for a week view we want one row representing the same attributes to have 7 values for each day of week.
- // We identify simlar records by a combination of client, billable, project, task, and custom field values.
- // This will allow us to extend the feature when more custom fields are added.
- //
- // "cl:546,bl:1,pr:23456,ts:27464,cf_1:example text"
- // The above means client 546, billable, project 23456, task 27464, custom field text "example text".
- //
- // "cl:546,bl:0,pr:23456,ts:27464,cf_1:7623"
- // The above means client 546, not billable, project 23456, task 27464, custom field option id 7623.
- static function getGroupedRecordsForInterval($user_id, $start_date, $end_date) {
- // Start by obtaining all records in interval.
- // Then, iterate through them to build an array.
- $records = ttTimeHelper::getRecordsForInterval($user_id, $start_date, $end_date);
- $groupedRecords = array();
- foreach ($records as $record) {
- $record_identifier_no_suffix = ttTimeHelper::makeRecordIdentifier($record);
- // Handle potential multiple records with the same attributes by using a numerical suffix.
- $suffix = 0;
- $record_identifier = $record_identifier_no_suffix.'_'.$suffix;
- while (!empty($groupedRecords[$record_identifier][$record['date']])) {
- $suffix++;
- $record_identifier = $record_identifier_no_suffix.'_'.$suffix;
- }
- $groupedRecords[$record_identifier][$record['date']] = array('id'=>$record['id'], 'duration'=>$record['duration']);
- $groupedRecords[$record_identifier]['client'] = $record['client'];
- $groupedRecords[$record_identifier]['cf_1_value'] = $record['cf_1_value'];
- $groupedRecords[$record_identifier]['project'] = $record['project'];
- $groupedRecords[$record_identifier]['task'] = $record['task'];
- $groupedRecords[$record_identifier]['billable'] = $record['billable'];
- }