Add constant for path to tasks files
authorCameron Ball <cameron@cameron1729.xyz>
Fri, 11 Jan 2019 03:54:58 +0000 (11:54 +0800)
committerCameron Ball <cameron@cameron1729.xyz>
Fri, 11 Jan 2019 04:01:57 +0000 (12:01 +0800)
src/common.php
src/purjolok.php
src/unfinished.php

index ab0dd8d..d884459 100644 (file)
@@ -334,11 +334,12 @@ function getTasksForTheWeek(int $year, int $monthNum, int $weekNum, array $taskM
 }
 
 const getFilePathForWeek = 'getFilePathForWeek';
-function getFilePathForWeek(int $year, int $monthNum, int $weekNum) {
+function getFilePathForWeek(int $year, int $monthNum, int $weekNum, string $base) {
     // December is part of next year's summer
     $seasonYear = $year;
     return sprintf(
-        'tasks/%s/%s/%s/week%s.txt',
+        '%s/tasks/%s/%s/%s/week%s.txt',
+        $base,
         $seasonYear,
         getSeason($monthNum),
         getMonthName($monthNum),
@@ -413,25 +414,25 @@ function getYearWeekBeginsIn(int $year, int $month, int $day) {
     return $year - (int)($month == 1 && getMonthWeekBeginsIn($year, $month, $day) == 12);
 }
 
-function getFilePathsForMonth(int $year, int $monthNum) {
-    return map(function($week) use ($year, $monthNum){
-        return getFilePathForWeek($year, $monthNum, $week);
+function getFilePathsForMonth(int $year, int $monthNum, string $base) {
+    return map(function($week) use ($year, $monthNum, $base){
+        return getFilePathForWeek($year, $monthNum, $week, $base);
     })(range(1, count(getMondaysForMonth($year, $monthNum))));
 }
 
-function getFilePathsForSeason(int $year, string $season) {
-    return array_merge(...map(function($monthNum) use ($year) {
+function getFilePathsForSeason(int $year, string $season, string $base) {
+    return array_merge(...map(function($monthNum) use ($year, $base) {
         // Summer of the current year includes december of the previous year.
         $seasonYear = $year - ($monthNum == 12 ? 1 : 0);
-        return getFilePathsForMonth($seasonYear, $monthNum);
+        return getFilePathsForMonth($seasonYear, $monthNum, $base);
     })(array_filter(range(1,12), function($month) use ($season) {
         return getSeason($month) == $season;
     })));
 }
 
-function getFilePathsForYear(int $year) {
-    return array_merge(...map(function($season) use ($year) {
-        return getFilePathsForSeason($year, $season);
+function getFilePathsForYear(int $year, string $base) {
+    return array_merge(...map(function($season) use ($year, $base) {
+        return getFilePathsForSeason($year, $season, $base);
     })(['summer', 'winter', 'spring', 'autumn']));
 }
 
index 94cc011..e66f830 100644 (file)
@@ -17,7 +17,7 @@ $message = getTelegram()->getWebHookUpdates()->get('message') ? getTelegram()->g
 
 if ($between = between(reveal($message ?? ''), '[taskid]')) {
     $monday = turnBackTime(new DateTimeImmutable);
-    $completedTasksFile = getFilePathForWeek($monday->year, $monday->month, $monday->weekNum);
+    $completedTasksFile = getFilePathForWeek($monday->year, $monday->month, $monday->weekNum, PATH_TO_TASKS_FILES);
     $completedTasks = file_exists($completedTasksFile) ? lines(trim(file_get_contents($completedTasksFile))) : [];
     $tasksForTheWeek = getTasksForTheWeek(
         $monday->year,
@@ -233,7 +233,7 @@ getTelegram()->addCommand(
                 require 'taskMatrix.php'
             );
 
-            $completedTasksFile = getFilePathForWeek($monday->year, $monday->month, $monday->weekNum);
+            $completedTasksFile = getFilePathForWeek($monday->year, $monday->month, $monday->weekNum, PATH_TO_TASKS_FILES);
             $completedTasks = file_exists($completedTasksFile) ? lines(trim(file_get_contents($completedTasksFile))) : [];
 
             if (!array_diff($tasksForTheWeek, $completedTasks)) {
@@ -267,7 +267,7 @@ getTelegram()->addCommand(
                 require 'taskMatrix.php'
             );
 
-            $completedTasksFile = getFilePathForWeek($monday->year, $monday->month, $monday->weekNum);
+            $completedTasksFile = getFilePathForWeek($monday->year, $monday->month, $monday->weekNum, PATH_TO_TASKS_FILES);
             $completedTasks = file_exists($completedTasksFile) ? lines(trim(file_get_contents($completedTasksFile))) : [];
 
             if (!array_diff($tasksForTheWeek, $completedTasks)) {
index 890e0bf..27d6c1a 100644 (file)
@@ -15,20 +15,20 @@ $unfinishedForYear = array_diff(
              return getTasksForTheSeason($season, $taskMatrix);
          }
      )(['summer', 'autumn', 'winter', 'spring'])),
-     array_reduce(getFilePathsForYear($monday->year), $extractTasks, [])
+     array_reduce(getFilePathsForYear($monday->year, PATH_TO_TASKS_FILES), $extractTasks, [])
 );
 
 $unfinishedForSeason = array_diff(
     getTasksForTheSeason($monday->season, $taskMatrix),
-    array_reduce(getFilePathsForSeason($monday->year, $monday->season), $extractTasks, [])
+    array_reduce(getFilePathsForSeason($monday->year, $monday->season, PATH_TO_TASKS_FILES), $extractTasks, [])
 );
 
 $unfinishedForMonth = array_diff(
     getTasksForTheMonth($monday->month, $taskMatrix),
-    array_reduce(getFilePathsForMonth($monday->year, $monday->month), $extractTasks, [])
+    array_reduce(getFilePathsForMonth($monday->year, $monday->month, PATH_TO_TASKS_FILES), $extractTasks, [])
 );
 
-$filePathForWeek = getFilePathForWeek($monday->year, $monday->month, $monday->weekNum);
+$filePathForWeek = getFilePathForWeek($monday->year, $monday->month, $monday->weekNum, PATH_TO_TASKS_FILES);
 $unfinishedForWeek = array_diff(
     getTasksForTheWeek($monday->year, $monday->month, $monday->weekNum, $taskMatrix),
     file_exists($filePathForWeek) ? lines(trim(file_get_contents($filePathForWeek))) : []