9 * @author Christian Weiske <cweiske@cweiske.de>
10 * @copyright 2023 Christian Weiske
11 * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
12 * @link http://cweiske.de/bdrem.htm
17 use Sabre\VObject\Component\VCard;
20 * Read a folder of vcard files
21 * 2 subfolder levels are supported.
25 * @author Christian Weiske <cweiske@cweiske.de>
26 * @copyright 2023 Christian Weiske
27 * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
28 * @link http://cweiske.de/bdrem.htm
33 * Full path to a folder with .vcf files
35 protected string $folder;
38 * Set the VCard folder path
40 public function __construct($config)
42 if (is_string($config)) {
47 $this->folder = $config['folder'];
48 if (!is_dir($this->folder)) {
50 'VCard folder does not exist: ' . $this->folder
56 * Return all events for the given date range
58 * @param string $strDate Date the events shall be found for,
60 * @param integer $nDaysPrevious Include number of days before $strDate
61 * @param integer $nDaysNext Include number of days after $strDate
63 * @return Event[] Array of matching event objects
65 public function getEvents($strDate, $nDaysPrevious, $nDaysNext)
67 $vcfFiles = glob($this->folder . '/{*,*/*,*/*/*}.vcf', GLOB_BRACE);
68 if (count($vcfFiles) == 0) {
69 throw new \Exception('No .vcf files found in folder');
73 foreach ($vcfFiles as $vcfFile) {
74 $vcard = VObject\Reader::read(file_get_contents($vcfFile));
76 if (isset($vcard->BDAY)) {
78 $this->getName($vcard),
80 $vcard->BDAY->getDateTime()->format('Y-m-d')
82 if ($event->isWithin($strDate, $nDaysPrevious, $nDaysNext)) {
87 if (isset($vcard->{'X-ANNIVERSARY'})) {
89 $this->getName($vcard),
91 $vcard->{'X-ANNIVERSARY'}->getDateTime()->format('Y-m-d')
93 if ($event->isWithin($strDate, $nDaysPrevious, $nDaysNext)) {
102 protected function getName(VCard $vcard)
104 return (string) $vcard->FN;