- $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'];
+ // Find row.
+ $pos = ttTimeHelper::findRow($record_id, $dataArray);
+ if ($pos < 0) {
+ $dataArray[] = array('id' => $record_id,'label' => ttTimeHelper::makeRecordLabel($record)); // Insert row.
+ $pos = ttTimeHelper::findRow($record_id, $dataArray);
+ }
+ // Insert cell data from $record.
+ $dataArray[$pos][$day_header] = array('id' => $record['id'],'duration' => $record['duration']);
+ }
+ return $dataArray;
+ }
+
+ // cellExists is a helper function for getDataForWeekView() to see if a cell with a given label
+ // and a day header already exists.
+ static function cellExists($record_id, $day_header, $dataArray) {
+ foreach($dataArray as $row) {
+ if ($row['id'] == $record_id && !empty($row[$day_header]['duration']))
+ return true;
+ }
+ return false;
+ }
+
+ // findRow returns an existing row position in $dataArray, -1 otherwise.
+ static function findRow($record_id, $dataArray) {
+ $pos = 0; // Row position in array.
+ foreach($dataArray as $row) {
+ if ($row['id'] == $record_id)
+ return $pos;
+ $pos++; // Increment for search.