+ // 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($row_id, $day_header, $dataArray) {
+ foreach($dataArray as $row) {
+ if ($row['row_id'] == $row_id && !empty($row[$day_header]['duration']))
+ return true;
+ }
+ return false;
+ }
+
+ // findRow returns an existing row position in $dataArray, -1 otherwise.
+ static function findRow($row_id, $dataArray) {
+ $pos = 0; // Row position in array.
+ foreach($dataArray as $row) {
+ if ($row['row_id'] == $row_id)
+ return $pos;
+ $pos++; // Increment for search.
+ }
+ return -1; // Row not found.
+ }
+
+ // getDayTotals calculates total durations for each day from the existing data in $dataArray.
+ static function getDayTotals($dataArray, $dayHeaders) {
+ $dayTotals = array();
+
+ // Insert label.
+ global $i18n;
+ $dayTotals['label'] = $i18n->getKey('label.day_total');
+
+ foreach ($dataArray as $row) {
+ foreach($dayHeaders as $dayHeader) {
+ if (array_key_exists($dayHeader, $row)) {
+ $minutes = ttTimeHelper::toMinutes($row[$dayHeader]['duration']);
+ $dayTotals[$dayHeader] += $minutes;
+ }
+ }
+ }
+ // Convert minutes to hh:mm for display.
+ foreach($dayHeaders as $dayHeader) {
+ $dayTotals[$dayHeader] = ttTimeHelper::toAbsDuration($dayTotals[$dayHeader]);
+ }
+ return $dayTotals;
+ }
+
+ // dateFromDayHeader calculates date from start date and day header in week view.
+ static function dateFromDayHeader($start_date, $day_header) {
+ $objDate = new DateAndTime(DB_DATEFORMAT, $start_date);
+ $currentDayHeader = (string) $objDate->getDate(); // It returns an int on first call.
+ if (strlen($currentDayHeader) == 1) // Which is an implementation detail of DateAndTime class.
+ $currentDayHeader = '0'.$currentDayHeader; // Add a 0 for single digit day.
+ $i = 1;
+ while ($currentDayHeader != $day_header && $i < 7) {
+ // Iterate through remaining days to find a match.
+ $objDate->incDay();
+ $currentDayHeader = $objDate->getDate(); // After incDay it returns a string with leading 0, when necessary.
+ $i++;
+ }
+ return $objDate->toString(DB_DATEFORMAT);
+ }
+
+ // insertDurationFromWeekView - inserts a new record in log tables from a week view post.
+ static function insertDurationFromWeekView($fields, $custom_fields, $err) {
+ global $i18n;