X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=DataObjects%2FCore_holiday.php;h=b45313398be3547fbdddc7d68d98779c489e728e;hp=45ac129e8d82515074711e687b5e76e5c3319c77;hb=HEAD;hpb=fc8a9c7f01badbe12e4849a9250422bccb3640c6 diff --git a/DataObjects/Core_holiday.php b/DataObjects/Core_holiday.php index 45ac129e..cd26445d 100644 --- a/DataObjects/Core_holiday.php +++ b/DataObjects/Core_holiday.php @@ -20,9 +20,26 @@ class Pman_Core_DataObjects_Core_holiday extends DB_DataObject static $map = array( - 'hk' => 'http://www.1823.gov.hk/common/ical/gc/en.ics' + 'hk' => 'http://www.1823.gov.hk/common/ical/gc/en.ics', + 'cny' => 'https://raw.githubusercontent.com/andrewlkho/cny.ics/master/cny.ics', // CNY ); + + function applyFilters($q, $au, $roo) + { + if (isset($q['date_from'])) { + $dt = date("Y-m-d",strtotime($q['date_from'])); + $this->whereAdd("holiday_date > '$dt'"); + } + if (isset($q['date_to'])) { + $dt = date("Y-m-d",strtotime($q['date_to'])); + $this->whereAdd("holiday_date < '$dt'"); + } + + + } + + function updateHolidays($country) { @@ -43,7 +60,14 @@ class Pman_Core_DataObjects_Core_holiday extends DB_DataObject - $data = file_get_contents("http://www.1823.gov.hk/common/ical/gc/en.ics"); + $data = file_get_contents("https://www.1823.gov.hk/common/ical/gc/en.ics", false, + stream_context_create(array( + "ssl"=>array( + "verify_peer"=>false, + "verify_peer_name"=>false, + ), + )) + ); $vevents = explode('BEGIN:VEVENT', $data); @@ -65,13 +89,15 @@ class Pman_Core_DataObjects_Core_holiday extends DB_DataObject $fmt = substr($matches[1], 0, 4) . "-" . substr($matches[1], 4, 2) . "-" . substr($matches[1], 6, 2); $end_dt = date('Y-m-d', strtotime($fmt)); } - + if(preg_match('/^SUMMARY[^:]*:(.*)/', $line, $matches)){ + $name = trim($matches[1]); + } } if(empty($start_dt) || empty($end_dt)){ continue; } - + //DB_DataObject::DebugLevel(1); //var_dump($start_dt); var_dump($end_dt); exit; for ($i = strtotime($start_dt); $i < strtotime($end_dt) ; $i += (60 * 60 * 24)) { @@ -81,7 +107,13 @@ class Pman_Core_DataObjects_Core_holiday extends DB_DataObject $d->holiday_date = date('Y-m-d', $i); if (!$d->count()) { $d->insert(); - } + + } else { + $d->find(true); + $dd = clone($d); + $d->name = $name; + $d->update($dd); + } } @@ -89,5 +121,12 @@ class Pman_Core_DataObjects_Core_holiday extends DB_DataObject } } + function isHoliday($country, $date) + { + $d = DB_DataObject::Factory('core_holiday'); + $d->country = $country; + $d->holiday_date = $date; + return $d->count(); + } }