aboutsummaryrefslogtreecommitdiff
path: root/src/bdrem/Source
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2014-01-14 17:46:51 +0100
committerChristian Weiske <cweiske@cweiske.de>2014-01-14 17:46:51 +0100
commit441c72bbf3d29be5c7f5eb0fd43ac267fe059c2f (patch)
treeadaf976068ed80a424f5acf64a754a52ce21c4e7 /src/bdrem/Source
downloadbdrem-441c72bbf3d29be5c7f5eb0fd43ac267fe059c2f.tar.gz
bdrem-441c72bbf3d29be5c7f5eb0fd43ac267fe059c2f.zip
first version that reads birthday reminder files
Diffstat (limited to 'src/bdrem/Source')
-rw-r--r--src/bdrem/Source/Bdf.php48
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;
+ }
+}
+?>