diff --git a/habit.php b/habit.php index 75ac47f..560c539 100644 --- a/habit.php +++ b/habit.php @@ -308,6 +308,12 @@ //echo ($wordFound) ? "+ found: $line\n" : $line . "\n"; } + $weekPrevStart = new DateTime($firstOccurrenceDate); + // Add one week to the date + $weekPrevStart->modify('-1 week'); + // Format and print the new date + $weekPrevStart2 = $weekPrevStart->format('Y-m-d'); + foreach ($dateOccurrences as $date => $count) { // Convert each date to the format $year-$weekNo $dateTime = new DateTime($date); @@ -324,7 +330,7 @@ $weeklyOccurrences[$yearWeek] = 0; } } - if($date < $firstOccurrenceDate) + if(strtotime($date) < strtotime($weekPrevStart2)) $weeklyOccurrences[$yearWeek] = "x"; } @@ -333,6 +339,7 @@ // return $value !== 0; //}); + //print_r($dateOccurrences); //print_r($weeklyOccurrences); // Convert keys to timestamps and print in a simple JSON format with surrounding {} @@ -482,6 +489,7 @@ $lines = explode("\n", $fileContent); $dateOccurrences = []; $weeklyOccurrences = []; + $first = ""; foreach ($lines as $line) { // Extract the date from the line @@ -497,6 +505,7 @@ // Check if the word contains "#takeout" (case-insensitive) if (stripos($wordInLine, "#$word") !== false) { $wordFound = true; + $first = $date; // $first will end up containging first instance of word break; } } @@ -531,11 +540,22 @@ } } - + $today = new DateTime(); + $currentDate = date('Y-m-d'); + + while (strtotime($first) <= strtotime($currentDate)) { + $dateTime = new DateTime($currentDate); + $yearWeekKey = $dateTime->format('Y-W'); + $weeklyOccurrences[$yearWeekKey] = 0; + //echo $yearWeekKey; + $currentDate = date('Y-m-d', strtotime($currentDate . ' -1 day')); + } + + $consecutiveCount = 0; $maxConsecutiveCount = 0; - ksort($weeklyOccurrences); + //ksort($weeklyOccurrences); foreach ($weeklyOccurrences as $week => $value) { if ($value >= $multiplier) { @@ -602,6 +622,7 @@ $lines = explode("\n", $fileContent); $dateOccurrences = []; $weeklyOccurrences = []; + $first = ""; foreach ($lines as $line) { // Extract the date from the line @@ -617,6 +638,7 @@ // Check if the word contains "#takeout" (case-insensitive) if (stripos($wordInLine, "#$word") !== false) { $wordFound = true; + $first = $date; break; } } @@ -634,6 +656,15 @@ //echo ($wordFound) ? "+ found: $line\n" : $line . "\n"; } + $currentDate = date('Y-m-d'); + while (strtotime($first) <= strtotime($currentDate)) { + $dateTime = new DateTime($currentDate); + $yearWeekKey = $dateTime->format('Y-W'); + $weeklyOccurrences[$yearWeekKey] = 0; + //echo $yearWeekKey; + $currentDate = date('Y-m-d', strtotime($currentDate . ' -1 day')); + } + foreach ($dateOccurrences as $date => $count) { // Convert each date to the format $year-$weekNo $dateTime = new DateTime($date); @@ -966,6 +997,8 @@ $jsonArray['buttonText'] = ""; } } + if($weekCount == 0) + $jsonArray['buttonClass'] = ''; break; } } @@ -1068,6 +1101,8 @@ $jsonArray['buttonClass'] = 'button-good'; } } + if($weekCount == 0) + $jsonArray['buttonClass'] = ''; $last10 = habit_last_10_weekly($section['Activity'], $moodlog); foreach ($last10 as $key => $value) { diff --git a/habit.php b/habit.php index 75ac47f..560c539 100644 --- a/habit.php +++ b/habit.php @@ -308,6 +308,12 @@ //echo ($wordFound) ? "+ found: $line\n" : $line . "\n"; } + $weekPrevStart = new DateTime($firstOccurrenceDate); + // Add one week to the date + $weekPrevStart->modify('-1 week'); + // Format and print the new date + $weekPrevStart2 = $weekPrevStart->format('Y-m-d'); + foreach ($dateOccurrences as $date => $count) { // Convert each date to the format $year-$weekNo $dateTime = new DateTime($date); @@ -324,7 +330,7 @@ $weeklyOccurrences[$yearWeek] = 0; } } - if($date < $firstOccurrenceDate) + if(strtotime($date) < strtotime($weekPrevStart2)) $weeklyOccurrences[$yearWeek] = "x"; } @@ -333,6 +339,7 @@ // return $value !== 0; //}); + //print_r($dateOccurrences); //print_r($weeklyOccurrences); // Convert keys to timestamps and print in a simple JSON format with surrounding {} @@ -482,6 +489,7 @@ $lines = explode("\n", $fileContent); $dateOccurrences = []; $weeklyOccurrences = []; + $first = ""; foreach ($lines as $line) { // Extract the date from the line @@ -497,6 +505,7 @@ // Check if the word contains "#takeout" (case-insensitive) if (stripos($wordInLine, "#$word") !== false) { $wordFound = true; + $first = $date; // $first will end up containging first instance of word break; } } @@ -531,11 +540,22 @@ } } - + $today = new DateTime(); + $currentDate = date('Y-m-d'); + + while (strtotime($first) <= strtotime($currentDate)) { + $dateTime = new DateTime($currentDate); + $yearWeekKey = $dateTime->format('Y-W'); + $weeklyOccurrences[$yearWeekKey] = 0; + //echo $yearWeekKey; + $currentDate = date('Y-m-d', strtotime($currentDate . ' -1 day')); + } + + $consecutiveCount = 0; $maxConsecutiveCount = 0; - ksort($weeklyOccurrences); + //ksort($weeklyOccurrences); foreach ($weeklyOccurrences as $week => $value) { if ($value >= $multiplier) { @@ -602,6 +622,7 @@ $lines = explode("\n", $fileContent); $dateOccurrences = []; $weeklyOccurrences = []; + $first = ""; foreach ($lines as $line) { // Extract the date from the line @@ -617,6 +638,7 @@ // Check if the word contains "#takeout" (case-insensitive) if (stripos($wordInLine, "#$word") !== false) { $wordFound = true; + $first = $date; break; } } @@ -634,6 +656,15 @@ //echo ($wordFound) ? "+ found: $line\n" : $line . "\n"; } + $currentDate = date('Y-m-d'); + while (strtotime($first) <= strtotime($currentDate)) { + $dateTime = new DateTime($currentDate); + $yearWeekKey = $dateTime->format('Y-W'); + $weeklyOccurrences[$yearWeekKey] = 0; + //echo $yearWeekKey; + $currentDate = date('Y-m-d', strtotime($currentDate . ' -1 day')); + } + foreach ($dateOccurrences as $date => $count) { // Convert each date to the format $year-$weekNo $dateTime = new DateTime($date); @@ -966,6 +997,8 @@ $jsonArray['buttonText'] = ""; } } + if($weekCount == 0) + $jsonArray['buttonClass'] = ''; break; } } @@ -1068,6 +1101,8 @@ $jsonArray['buttonClass'] = 'button-good'; } } + if($weekCount == 0) + $jsonArray['buttonClass'] = ''; $last10 = habit_last_10_weekly($section['Activity'], $moodlog); foreach ($last10 as $key => $value) { diff --git a/habit_ui.php b/habit_ui.php index 9b663ce..66aec6d 100644 --- a/habit_ui.php +++ b/habit_ui.php @@ -162,7 +162,11 @@ if ($weekCount >= $multiplier) { $buttonClass = 'button-good'; } - } + } + if($weekCount == 0){ + $buttonClass = ''; + $buttText = ""; + } }