/** @inheritdoc */
 protected function saveData($post_id, WP_Post $post, $update)
 {
     $config = $_POST[static::GLOBAL_POST_KEY];
     $holidays = $this->getHolidaysFromPostData($config);
     $persistence = new Persistence($post);
     $persistence->saveHolidays($holidays);
 }
 /** @inheritdoc */
 protected function saveData($post_id, WP_Post $post, $update)
 {
     $config = $_POST['opening-hours'];
     $periods = $this->getPeriodsFromPostData($config);
     $persistence = new Persistence($post);
     $persistence->savePeriods($periods);
 }
 /** @inheritdoc */
 protected function saveData($post_id, WP_Post $post, $update)
 {
     $config = $_POST[static::GLOBAL_POST_KEY];
     $ios = $this->getIrregularOpeningsFromPostData($config);
     $persistence = new Persistence($post);
     $persistence->saveIrregularOpenings($ios);
 }
 public function setUpSetWithData(array $args = array(), array $periods = array(), array $holidays = array(), array $irregularOpenings = array())
 {
     $post = $this->setUpBasicSet($args);
     $persistence = new Persistence($post);
     if (count($periods) > 0) {
         $persistence->savePeriods($periods);
     }
     if (count($holidays) > 0) {
         $persistence->saveHolidays($holidays);
     }
     if (count($irregularOpenings) > 0) {
         $persistence->saveIrregularOpenings($irregularOpenings);
     }
     return $post;
 }
 public function testIrregularOpeningPersistence()
 {
     $ts = new TestScenario($this->factory);
     $post = $ts->setUpBasicSet();
     $persistence = new Persistence($post);
     $ios = array(new IrregularOpening('IO1', '2016-02-03', '13:00', '17:00'), new IrregularOpening('IO2', '2016-03-03', '16:30', '19:00'));
     $persistence->saveIrregularOpenings($ios);
     // Check meta
     $meta = get_post_meta($post->ID, Persistence::IRREGULAR_OPENINGS_META_KEY, true);
     $this->assertTrue(is_array($meta));
     $this->assertEquals(2, count($meta));
     $io1 = $meta[0];
     $io2 = $meta[1];
     $this->assertEquals('IO1', $io1['name']);
     $this->assertEquals('2016-02-03', $io1['date']);
     $this->assertEquals('13:00', $io1['timeStart']);
     $this->assertEquals('17:00', $io1['timeEnd']);
     $this->assertEquals('IO2', $io2['name']);
     $this->assertEquals('2016-03-03', $io2['date']);
     $this->assertEquals('16:30', $io2['timeStart']);
     $this->assertEquals('19:00', $io2['timeEnd']);
     // Load Irregular Openings
     $ios = $persistence->loadIrregularOpenings();
     $this->assertTrue(is_array($ios));
     $this->assertEquals(2, count($ios));
     $io1 = $ios[0];
     $io2 = $ios[1];
     $this->assertEquals('IO1', $io1->getName());
     $this->assertEquals(new DateTime('2016-02-03'), $io1->getDate());
     $this->assertEquals(new DateTime('2016-02-03 13:00'), $io1->getTimeStart());
     $this->assertEquals(new DateTime('2016-02-03 17:00'), $io1->getTimeEnd());
     $this->assertEquals('IO2', $io2->getName());
     $this->assertEquals(new DateTime('2016-03-03'), $io2->getDate());
     $this->assertEquals(new DateTime('2016-03-03 16:30'), $io2->getTimeStart());
     $this->assertEquals(new DateTime('2016-03-03 19:00'), $io2->getTimeEnd());
 }
 public function testGetPeriodsByDay()
 {
     $ts = new TestScenario($this->factory);
     $post = $ts->setUpBasicSet();
     $persistence = new Persistence($post);
     $persistence->savePeriods(array(new Period(1, '13:00', '17:00'), new Period(1, '18:00', '21:00'), new Period(2, '13:00', '17:00')));
     $set = new Set($post);
     $day1 = $set->getPeriodsByDay(1);
     $this->assertEquals(2, count($day1));
     $this->assertEquals(1, $day1[0]->getWeekday());
     $this->assertEquals(1, $day1[1]->getWeekday());
     $day2 = $set->getPeriodsByDay(2);
     $this->assertTrue(is_array($day2));
     $this->assertEquals(1, count($day2));
     $this->assertEquals(2, $day2[0]->getWeekday());
     $day3 = $set->getPeriodsByDay(3);
     $this->assertTrue(is_array($day3));
     $this->assertEquals(0, count($day3));
     $days12 = $set->getPeriodsByDay(array(1, 2));
     $this->assertEquals(3, count($days12));
 }
Exemple #7
0
 /** Sets up the Set instance */
 public function setUp()
 {
     $childPosts = get_posts(array('post_type' => SetCpt::CPT_SLUG, 'post_parent' => $this->getId()));
     foreach ($childPosts as $post) {
         if (self::postMatchesCriteria($post)) {
             $this->id = $post->ID;
             $this->post = $post;
             break;
         }
     }
     /** Action: op_set_before_setup */
     do_action(self::WP_ACTION_BEFORE_SETUP, $this);
     $persistence = new Persistence($this->post);
     $this->periods = ArrayObject::createFromArray($persistence->loadPeriods());
     $this->holidays = ArrayObject::createFromArray($persistence->loadHolidays());
     $this->irregularOpenings = ArrayObject::createFromArray($persistence->loadIrregularOpenings());
     $post_detail_description = get_post_detail('description', $this->id);
     $post_parent_detail_description = get_post_detail('description', $this->parentId);
     if (!empty($post_detail_description)) {
         $this->description = $post_detail_description;
     } elseif (!empty($post_parent_detail_description)) {
         $this->description = $post_parent_detail_description;
     }
 }