* @package WB * @subpackage Table */ WBClass::load('WBDatasource_XReference'); /** * Public Holidays * * @version 0.1.0 * @package WB * @subpackage db */ class WBDatasource_Holiday extends WBStdClass { /** * Table access * @var WBDatasource_Table */ private $table; const TABLE_HOLIDAY = 'holiday'; private $fuzzy = 1; /** * Constructor * * Parameter: * * @param array $parameter */ public function __construct( $parameter = array() ) { $this->table = WBClass::create('WBDatasource_Table'); } /** * Save Public Holiday * * @param array $data * @return string holiday id */ public function save($data) { $old = $this->getByDate($data['holiday']); if (empty($old)) { return $this->table->save(self::TABLE_HOLIDAY, '__new', $data); } return $old[0]['id']; } private function getByDate($date) { $clause = array(); $clause[] = array( 'field' => 'holiday', 'value' => $date ); if (1 > $this->fuzzy) { return $this->table->get(self::TABLE_HOLIDAY, null, null, $clause); } $clause[0]['relation'] = 'ge'; $date = strtotime($date) + 24 * 3600 * $this->fuzzy; $date = date('Y-m-d 00:00:00', $date); $clause[] = array( 'field' => 'holiday', 'relation' => 'le', 'value' => $date ); return $this->table->get(self::TABLE_HOLIDAY, null, null, $clause); } /** * Check Date for Holiday * * @param string date * @return bool true of date is a holiday */ public function isHoliday($date = null) { if (empty($date)) { $date = time(); } else { $date = strtotime($date); } $date = gmdate('Y-m-d', $date); $old = $this->getByDate($date); if (count($old)) { return true; } return false; } }