diff options
Diffstat (limited to 'src/bdrem/Source')
| -rw-r--r-- | src/bdrem/Source/Bdf.php | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/bdrem/Source/Bdf.php b/src/bdrem/Source/Bdf.php new file mode 100644 index 0000000..e8208eb --- /dev/null +++ b/src/bdrem/Source/Bdf.php @@ -0,0 +1,48 @@ +<?php +namespace bdrem; + +/** + * Reads birthday reminder 2's birthday files (.bdf). + */ +class Source_Bdf +{ + protected $filename; + + public function __construct($filename) + { + $this->filename = $filename; + if (!file_exists($this->filename)) { + throw new \Exception( + 'Birthday file does not exist: ' . $this->filename + ); + } + } + + /** + * @param string $strDate Date the events shall be found for, YYYY-MM-DD + */ + public function getEvents($strDate, $nDaysBefore, $nDaysAfter) + { + $x = simplexml_load_file($this->filename); + + $arEvents = array(); + foreach ($x->content->person as $xPerson) { + $date = implode( + '-', + array_reverse( + explode('.', (string) $xPerson->date) + ) + ); + $event = new Event( + (string) $xPerson->name, + (string) $xPerson->event, + $date + ); + if ($event->isWithin($strDate, $nDaysBefore, $nDaysAfter)) { + $arEvents[] = $event; + } + } + return $arEvents; + } +} +?> |
