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(array $config)
42 $this->folder = $config['folder'];
43 if (!is_dir($this->folder)) {
45 'VCard folder does not exist: ' . $this->folder
51 * Return all events for the given date range
53 * @param string $strDate Date the events shall be found for,
55 * @param integer $nDaysPrevious Include number of days before $strDate
56 * @param integer $nDaysNext Include number of days after $strDate
58 * @return Event[] Array of matching event objects
60 public function getEvents($strDate, $nDaysPrevious, $nDaysNext)
62 $vcfFiles = glob($this->folder . '/{*,*/*,*/*/*}.vcf', GLOB_BRACE);
63 if (count($vcfFiles) == 0) {
64 throw new \Exception('No .vcf files found in folder');
68 foreach ($vcfFiles as $vcfFile) {
69 $vcard = VObject\Reader::read(file_get_contents($vcfFile));
71 if (isset($vcard->BDAY)) {
73 $this->getName($vcard),
75 $vcard->BDAY->getDateTime()->format('Y-m-d')
77 if ($event->isWithin($strDate, $nDaysPrevious, $nDaysNext)) {
82 if (isset($vcard->{'X-ANNIVERSARY'})) {
84 $this->getName($vcard),
86 $vcard->{'X-ANNIVERSARY'}->getDateTime()->format('Y-m-d')
88 if ($event->isWithin($strDate, $nDaysPrevious, $nDaysNext)) {
97 protected function getName(VCard $vcard)
99 return (string) $vcard->FN;