Ejemplo n.º 1
0
 public function testFilterInvalidValue()
 {
     $from = new \DateTime('2010-10-10 06:00:00');
     $to = new \DateTime('2010-10-12 08:30:00');
     $filter = new DateRange($from, $to);
     $this->assertFalse($filter->apply('foo'));
 }
 public function __construct(Date $base, $weekStart = Timestamp::WEEKDAY_MONDAY)
 {
     $firstDayOfMonth = Date::create($base->getYear() . '-' . $base->getMonth() . '-01');
     $lastDayOfMonth = Date::create($base->getYear() . '-' . $base->getMonth() . '-' . date('t', $base->toStamp()));
     $start = $firstDayOfMonth->getFirstDayOfWeek($weekStart);
     $end = $lastDayOfMonth->getLastDayOfWeek($weekStart);
     $this->monthRange = DateRange::create()->lazySet($firstDayOfMonth, $lastDayOfMonth);
     $this->fullRange = DateRange::create()->lazySet($start, $end);
     $rawDays = $this->fullRange->split();
     $this->fullLength = 0;
     foreach ($rawDays as $rawDay) {
         $day = CalendarDay::create($rawDay->toStamp());
         if ($this->monthRange->contains($day)) {
             $day->setOutside(false);
         } else {
             $day->setOutside(true);
         }
         $this->days[$day->toDate()] = $day;
         $weekNumber = floor($this->fullLength / 7);
         if (!isset($this->weeks[$weekNumber])) {
             $this->weeks[$weekNumber] = CalendarWeek::create();
         }
         $this->weeks[$weekNumber]->addDay($day);
         ++$this->fullLength;
     }
     ++$this->fullLength;
 }
Ejemplo n.º 3
0
 public function testCreatingNewSeriesSetsAllSharedDataAndCreatesInstances()
 {
     $userId = 32;
     $resourceId = 10;
     $title = 'Title';
     $description = 'some long decription';
     $tz = 'America/Chicago';
     $userSession = new FakeUserSession();
     $startDateCst = '2010-02-02 12:15';
     $endDateCst = '2010-02-04 17:15';
     $startDateUtc = Date::Parse($startDateCst, $tz)->ToUtc();
     $endDateUtc = Date::Parse($endDateCst, $tz)->ToUtc();
     $dateRange = DateRange::Create($startDateCst, $endDateCst, $tz);
     $repeatedDate = DateRange::Create('2010-01-01', '2010-01-02', 'UTC');
     $repeatOptions = $this->getMock('IRepeatOptions');
     $repeatDates = array($repeatedDate);
     $repeatOptions->expects($this->once())->method('GetDates')->with($this->equalTo($dateRange->ToTimezone($userSession->Timezone)))->will($this->returnValue($repeatDates));
     $resource = new FakeBookableResource($resourceId);
     $series = ReservationSeries::Create($userId, $resource, $title, $description, $dateRange, $repeatOptions, $userSession);
     $this->assertEquals($userId, $series->UserId());
     $this->assertEquals($resource, $series->Resource());
     $this->assertEquals($title, $series->Title());
     $this->assertEquals($description, $series->Description());
     $this->assertTrue($series->IsRecurring());
     $this->assertEquals($repeatOptions, $series->RepeatOptions());
     $instances = array_values($series->Instances());
     $this->assertEquals(count($repeatDates) + 1, count($instances), "should have original plus instances");
     $this->assertTrue($startDateUtc->Equals($instances[0]->StartDate()));
     $this->assertTrue($endDateUtc->Equals($instances[0]->EndDate()));
     $this->assertTrue($repeatedDate->GetBegin()->Equals($instances[1]->StartDate()));
     $this->assertTrue($repeatedDate->GetEnd()->Equals($instances[1]->EndDate()));
 }
Ejemplo n.º 4
0
    public static function getCurrentRange()
    {
        $result = Db::getInstance()->getRow('
		SELECT `id_date_range`, `time_end`
		FROM `' . _DB_PREFIX_ . 'date_range`
		WHERE `time_end` = (SELECT MAX(`time_end`) FROM `' . _DB_PREFIX_ . 'date_range`)');
        if (!$result['id_date_range'] || strtotime($result['time_end']) < strtotime(date('Y-m-d H:i:s'))) {
            // The default range is set to 1 day less 1 second (in seconds)
            $rangeSize = 86399;
            $dateRange = new DateRange();
            $dateRange->time_start = date('Y-m-d');
            $dateRange->time_end = strftime('%Y-%m-%d %H:%M:%S', strtotime($dateRange->time_start) + $rangeSize);
            $dateRange->add();
            return $dateRange->id;
        }
        return $result['id_date_range'];
    }
 public static function makeDatesListByRange(DateRange $range, IntervalUnit $unit, $hash = true)
 {
     $date = $unit->truncate($range->getStart());
     if ('Date' == get_class($range->getStart())) {
         $date = Date::create($date->toStamp());
     }
     $dates = array();
     do {
         if ($hash) {
             $dates[$date->toString()] = $date;
         } else {
             $dates[] = $date;
         }
         $date = $date->spawn('+ 1' . $unit->getName());
     } while ($range->getEnd()->toStamp() >= $date->toStamp());
     return $dates;
 }
Ejemplo n.º 6
0
 /**
  * @return array Mutates the filter values so that it is readily prepared for processing.
  */
 public function getMutatedValues()
 {
     $operator = head($this->values);
     $dates = explode(' - ', last($this->values));
     switch ($operator) {
         case 'before':
             return [DateRange::before(Carbon::createFromFormat(Filterable::$date_format, head($dates), 'GB')->startOfDay())];
         case 'in':
             return [new DateRange(Carbon::createFromFormat(Filterable::$date_format, head($dates), 'GB')->subDay()->endOfDay(), Carbon::createFromFormat(Filterable::$date_format, last($dates), 'GB')->addDay()->startOfDay())];
         case 'not_in':
             return [new DateRange(Carbon::createFromFormat(Filterable::$date_format, last($dates), 'GB')->addDay()->startOfDay(), Carbon::createFromFormat(Filterable::$date_format, head($dates), 'GB')->subDay()->endOfDay())];
         case 'after':
             return [DateRange::after(Carbon::createFromFormat(Filterable::$date_format, last($dates), 'GB')->endOfDay())];
     }
 }
Ejemplo n.º 7
0
    public static function setPageViewed($id_page)
    {
        $id_date_range = DateRange::getCurrentRange();
        // Try to increment the visits counter
        Db::getInstance()->Execute('
		UPDATE `' . _DB_PREFIX_ . 'page_viewed`
		SET `counter` = `counter` + 1
		WHERE `id_date_range` = ' . intval($id_date_range) . '
		AND `id_page` = ' . intval($id_page));
        // If no one has seen the page in this date range, it is added
        if (Db::getInstance()->Affected_Rows() == 0) {
            Db::getInstance()->Execute('
			INSERT INTO `' . _DB_PREFIX_ . 'page_viewed` (`id_date_range`,`id_page`,`counter`)
			VALUES (' . intval($id_date_range) . ',' . intval($id_page) . ',1)');
        }
    }
Ejemplo n.º 8
0
    public static function setPageViewed($id_page)
    {
        $id_date_range = DateRange::getCurrentRange();
        $context = Context::getContext();
        // Try to increment the visits counter
        $sql = 'UPDATE `' . _DB_PREFIX_ . 'page_viewed`
				SET `counter` = `counter` + 1
				WHERE `id_date_range` = ' . (int) $id_date_range . '
					AND `id_page` = ' . (int) $id_page . '
					AND `id_shop` = ' . (int) $context->shop->id;
        Db::getInstance()->execute($sql);
        // If no one has seen the page in this date range, it is added
        if (Db::getInstance()->Affected_Rows() == 0) {
            Db::getInstance()->insert('page_viewed', array('id_date_range' => (int) $id_date_range, 'id_page' => (int) $id_page, 'counter' => 1, 'id_shop' => (int) $context->shop->id, 'id_shop_group' => (int) $context->shop->id_shop_group));
        }
    }
 public function testConflictsIfResourceReservationExistsAtSameTime()
 {
     $resourceId = 1;
     $currentId = 19;
     $currentDate = new DateRange(Date::Now()->AddDays(10), Date::Now()->AddDays(15));
     $current = new TestReservation('ref', $currentDate);
     $current->SetReservationId($currentId);
     $series = new ExistingReservationSeries();
     $series->WithPrimaryResource(new FakeBookableResource($resourceId));
     $series->WithResource(new FakeBookableResource($resourceId + 1));
     $series->WithCurrentInstance($current);
     $reservations = array(new TestReservationItemView($currentId + 1, $currentDate->GetBegin(), $currentDate->GetEnd(), $resourceId));
     $this->strategy->expects($this->once())->method('GetItemsBetween')->with($this->anything(), $this->anything())->will($this->returnValue($reservations));
     $rule = new ExistingResourceAvailabilityRule($this->strategy, $this->timezone);
     $ruleResult = $rule->Validate($series);
     $this->assertFalse($ruleResult->IsValid());
 }
Ejemplo n.º 10
0
 public function GetReservations(DateRange $dateRangeUtc, $scheduleId, $targetTimezone)
 {
     $reservationListing = $this->_coordinatorFactory->CreateReservationListing($targetTimezone);
     $reservations = $this->_repository->GetReservationList($dateRangeUtc->GetBegin(), $dateRangeUtc->GetEnd(), null, null, $scheduleId, null);
     Log::Debug("Found %s reservations for schedule %s between %s and %s", count($reservations), $scheduleId, $dateRangeUtc->GetBegin(), $dateRangeUtc->GetEnd());
     foreach ($reservations as $reservation) {
         $reservationListing->Add($reservation);
     }
     $blackouts = $this->_repository->GetBlackoutsWithin($dateRangeUtc, $scheduleId);
     Log::Debug("Found %s blackouts for schedule %s between %s and %s", count($blackouts), $scheduleId, $dateRangeUtc->GetBegin(), $dateRangeUtc->GetEnd());
     foreach ($blackouts as $blackout) {
         $reservationListing->AddBlackout($blackout);
     }
     return $reservationListing;
 }
 public function setDate($val)
 {
     if ($val == "0000-00-00 in press") {
         //handle non dates
         $val = "";
     }
     $this["published"] = trim($val) == "" ? "in press" : $val;
     //we can't really reliably determine this, we should also store it as text
     if (empty($val)) {
         return $this->published_at = null;
     }
     if (preg_match("/^\\d{4}\$/", $val)) {
         //strtotime can't handle YYYY
         $val = "Jan 1, " . $val;
     }
     $range = DateRange::parseString($val);
     if (isset($range)) {
         //try date range
         return $this->published_at = DTStore::date($range->getStartDate());
     } else {
         if (strtotime($val) !== false) {
             //try regular parse
             return $this->published_at = DTStore::date(strtotime($val));
         } else {
             if (preg_match("/(\\d{4})/", $val, $matches)) {
                 //try just a year
                 return $this->published_at = DTSTore::date(strtotime("Jan 1, " . $matches[1]));
             } else {
                 return $this->published_at = null;
             }
         }
     }
     //give up
 }
Ejemplo n.º 12
0
 /**
  * Does another range start before this one does?
  *
  * @param DateRange $other_range
  * @return bool True if the other range starts before this one.
  */
 function startsBefore($other_range)
 {
     $this_start = $this->getStartDate();
     $other_start = $other_range->getStartDate();
     return $this_start->before($other_start);
 }
Ejemplo n.º 13
0
 /**
  * @param  DateTime|null $onDate optional, will default to 'now'
  * @return bool
  */
 public function isEnabled(DateTime $onDate = null)
 {
     $onDate = $onDate ?: new DateTime();
     return $this->dateRange->includes($onDate);
 }
Ejemplo n.º 14
0
 /**
  * @param Date $date
  * @return bool
  */
 public function OccursOn(Date $date)
 {
     return $this->Date->OccursOn($date);
 }
 public function testLoadsExistingReservationAndUpdatesData()
 {
     $seriesId = 109809;
     $expectedSeries = new ExistingReservationSeries();
     $currentDuration = new DateRange(Date::Now()->AddDays(1), Date::Now()->AddDays(2), 'UTC');
     $removedResourceId = 190;
     $resource = new FakeBookableResource(1);
     $additionalId1 = $this->page->resourceIds[0];
     $additionalId2 = $this->page->resourceIds[1];
     $additional1 = new FakeBookableResource($additionalId1);
     $additional2 = new FakeBookableResource($additionalId2);
     $reservation = new Reservation($expectedSeries, $currentDuration);
     $expectedSeries->WithId($seriesId);
     $expectedSeries->WithCurrentInstance($reservation);
     $expectedSeries->WithPrimaryResource($resource);
     $expectedSeries->WithResource(new FakeBookableResource($removedResourceId));
     $expectedSeries->WithAttribute(new AttributeValue(100, 'to be removed'));
     $referenceNumber = $this->page->existingReferenceNumber;
     $timezone = $this->user->Timezone;
     $this->persistenceService->expects($this->once())->method('LoadByReferenceNumber')->with($this->equalTo($referenceNumber))->will($this->returnValue($expectedSeries));
     $this->resourceRepository->expects($this->at(0))->method('LoadById')->with($this->equalTo($this->page->resourceId))->will($this->returnValue($resource));
     $this->resourceRepository->expects($this->at(1))->method('LoadById')->with($this->equalTo($additionalId1))->will($this->returnValue($additional1));
     $this->resourceRepository->expects($this->at(2))->method('LoadById')->with($this->equalTo($additionalId2))->will($this->returnValue($additional2));
     $this->page->repeatType = RepeatType::Daily;
     $roFactory = new RepeatOptionsFactory();
     $repeatOptions = $roFactory->CreateFromComposite($this->page, $this->user->Timezone);
     $expectedDuration = DateRange::Create($this->page->GetStartDate() . " " . $this->page->GetStartTime(), $this->page->GetEndDate() . " " . $this->page->GetEndTime(), $timezone);
     $attachment = new FakeUploadedFile();
     $this->page->attachment = $attachment;
     $this->page->hasEndReminder = false;
     $existingSeries = $this->presenter->BuildReservation();
     $expectedAccessories = array(new ReservationAccessory(1, 2, 'accessoryname'));
     $expectedAttributes = array(1 => new AttributeValue(1, 'something'));
     $this->assertEquals($seriesId, $existingSeries->SeriesId());
     $this->assertEquals($this->page->seriesUpdateScope, $existingSeries->SeriesUpdateScope());
     $this->assertEquals($this->page->title, $existingSeries->Title());
     $this->assertEquals($this->page->description, $existingSeries->Description());
     $this->assertEquals($this->page->userId, $existingSeries->UserId());
     $this->assertEquals($resource, $existingSeries->Resource());
     $this->assertEquals($repeatOptions, $existingSeries->RepeatOptions());
     $this->assertEquals(array($additional1, $additional2), $existingSeries->AdditionalResources());
     $this->assertEquals($this->page->participants, $existingSeries->CurrentInstance()->AddedParticipants());
     $this->assertEquals($this->page->invitees, $existingSeries->CurrentInstance()->AddedInvitees());
     $this->assertTrue($expectedDuration->Equals($existingSeries->CurrentInstance()->Duration()), "Expected: {$expectedDuration} Actual: {$existingSeries->CurrentInstance()->Duration()}");
     $this->assertEquals($this->user, $expectedSeries->BookedBy());
     $this->assertEquals($expectedAccessories, $existingSeries->Accessories());
     $this->assertEquals($expectedAttributes, $existingSeries->AttributeValues());
     $expectedAttachment = ReservationAttachment::Create($attachment->OriginalName(), $attachment->MimeType(), $attachment->Size(), $attachment->Contents(), $attachment->Extension(), $seriesId);
     $this->assertEquals(array($expectedAttachment), $expectedSeries->AddedAttachments());
     $this->assertEquals($this->page->removedFileIds, $existingSeries->RemovedAttachmentIds());
     $this->assertEquals(new ReservationReminder($this->page->GetStartReminderValue(), $this->page->GetStartReminderInterval()), $existingSeries->GetStartReminder());
     $this->assertEquals(ReservationReminder::None(), $existingSeries->GetEndReminder());
 }
Ejemplo n.º 16
0
 public function SetReservationDate(DateRange $reservationDate)
 {
     $this->startDate = $reservationDate->GetBegin();
     $this->endDate = $reservationDate->GetEnd();
 }
Ejemplo n.º 17
0
 /**
  * @return Date
  */
 public function EndDate()
 {
     return $this->date->GetEnd();
 }
 /**
  * Renders date input
  * @param $name
  * @param DateRange|null $range
  * @return string
  */
 public function renderDateInput($name, DateRange $range = null)
 {
     return $this->renderTag('input', array('type' => 'text', 'name' => $name, 'id' => $this->generateId($name), 'class' => 'datepicker-field', 'value' => $range ? $this->formatDateValue($range->getMinDate()) : null));
 }
Ejemplo n.º 19
0
 /**
  * @return DateRange
  */
 private function GetReservationDuration()
 {
     $startDate = $this->_page->GetStartDate();
     $startTime = $this->_page->GetStartTime();
     $endDate = $this->_page->GetEndDate();
     $endTime = $this->_page->GetEndTime();
     $timezone = $this->userSession->Timezone;
     return DateRange::Create($startDate . ' ' . $startTime, $endDate . ' ' . $endTime, $timezone);
 }
 public function testOverlaps()
 {
     $this->assertTrue(DateRange::create()->lazySet(Date::create('2007-03-28'), Date::create('2008-03-27'))->overlaps(DateRange::create()->lazySet(Date::create('2007-05-14'), Date::create('2008-03-29'))));
     $this->assertFalse(DateRange::create()->lazySet(Date::create('2007-03-28'), Date::create('2008-03-27'))->overlaps(DateRange::create()->lazySet(Date::create('2005-05-14'), Date::create('2006-03-29'))));
 }
 /**
  *
  * @param sfForm $form
  * @return boolean 
  */
 public function applyMoreThanAllowedForADay(LeaveParameterObject $leaveAssignmentData)
 {
     $fromTime = date('H:i:s', strtotime($leaveAssignmentData->getFromTime()));
     $toTime = date('H:i:s', strtotime($leaveAssignmentData->getToTime()));
     $totalDuration = 0;
     if ($leaveAssignmentData->getFromDate() == $leaveAssignmentData->getToDate()) {
         $totalDuration = $this->getLeaveRequestService()->getTotalLeaveDuration($leaveAssignmentData->getEmployeeNumber(), $leaveAssignmentData->getFromDate());
     }
     if ($totalDuration + $leaveAssignmentData->getLeaveTotalTime() > $this->getWorkShiftDurationForEmployee($leaveAssignmentData->getEmployeeNumber())) {
         $dateRange = new DateRange();
         $dateRange->setFromDate($leaveAssignmentData->getFromDate());
         $dateRange->setToDate($leaveAssignmentData->getToDate());
         $searchParameters['dateRange'] = $dateRange;
         $searchParameters['employeeFilter'] = $leaveAssignmentData->getEmployeeNumber();
         $parameter = new ParameterObject($searchParameters);
         $leaveRequests = $this->getLeaveRequestService()->searchLeaveRequests($parameter);
         if (count($leaveRequests['list']) > 0) {
             foreach ($leaveRequests['list'] as $leaveRequest) {
                 $this->overlapLeaves[] = $leaveRequest->getLeave();
             }
         }
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 22
0
 public function __construct()
 {
     parent::__construct(Date::Now(), Date::Now());
 }
Ejemplo n.º 23
0
$series = $reservationRepository->LoadByReferenceNumber($params['rn']);
if (!$series) {
    header('HTTP/1.1 404 Not Found', true, 404);
    $response = array('reference_number' => $rn, 'message' => 'Reservation could not be found');
    print json_encode($response);
    return;
}
$series->ApplyChangesTo(SeriesUpdateScope::FullSeries);
if ($params['starts_at'] || $params['ends_at']) {
    if (!$params['starts_at']) {
        $params['starts_at'] = $series->CurrentInstance()->Duration()->GetBegin();
    }
    if (!$params['ends_at']) {
        $params['ends_at'] = $series->CurrentInstance()->Duration()->GetEnd();
    }
    $timing = DateRange::Create($params['starts_at'], $params['ends_at'], $tz);
    $series->UpdateDuration($timing);
}
if ($user->Id() == $series->UserId()) {
    $series->WithOwner($user->Id());
}
$title = $series->Title();
if ($params['summary']) {
    $title = $params['summary'];
}
$description = $series->Description();
if ($params['description']) {
    $description = $params['description'];
}
$series->Update($user->Id(), $resource, $title, $description, $user_session);
$vfactory = new ReservationValidationFactory();
Ejemplo n.º 24
0
    print json_encode(array('message' => "You must not set both contact_info and rid"));
    return;
}
if ($contact_info) {
    $resource = $resourceRepository->LoadByContactInfo($contact_info);
} elseif ($rid) {
    $resource = $resourceRepository->LoadByPublicId($rid);
} else {
    header('HTTP/1.1 406 Not Acceptable', true, 406);
    print json_encode(array('message' => "contact_info or rid has to be set"));
    return;
}
/*************************************************
 	date
 *************************************************/
$timing = DateRange::Create($starts_at, $ends_at, $tz);
/*************************************************
 	Action
 *************************************************/
$series = ReservationSeries::Create($user->Id(), $resource, $title, $description, $timing, new RepeatNone(), $user_session);
$reservationAction = ReservationAction::Create;
$pfactory = new ReservationPersistenceFactory();
$persistenceService = $pfactory->Create($reservationAction);
$vfactory = new ReservationValidationFactory();
$validationService = $vfactory->Create($reservationAction, $user_session);
$nfactory = new ReservationNotificationFactory();
$notificationService = $nfactory->Create($reservationAction, $user_session);
#	$handler = new ReservationHandler($persistenceService, $validationService, $notificationService);
$validationResult = $validationService->Validate($series);
$result = $validationResult->CanBeSaved();
if ($result) {
Ejemplo n.º 25
0
 public function testBindDisplayDatesSetsPageToArrayOfDatesInGivenTimezoneForRange()
 {
     $tz = 'America/New_York';
     $daysVisible = 7;
     $schedule = new Schedule(1, '', false, 4, $daysVisible);
     $page = $this->getMock('ISchedulePage');
     $start = Date::Now();
     $end = Date::Now()->AddDays(10);
     $expectedRange = new DateRange($start, $end);
     $expectedPrev = $expectedRange->GetBegin()->AddDays(-$daysVisible);
     $expectedNext = $expectedRange->GetBegin()->AddDays($daysVisible);
     $page->expects($this->once())->method('SetDisplayDates')->with($this->equalTo($expectedRange));
     $page->expects($this->once())->method('SetPreviousNextDates')->with($this->equalTo($expectedPrev), $this->equalTo($expectedNext));
     $pageBuilder = new SchedulePageBuilder();
     $pageBuilder->BindDisplayDates($page, $expectedRange, $schedule);
 }
Ejemplo n.º 26
0
 /**
  * @param DateRange $dateRange
  * @return array|DateRange[]
  */
 public function Split(DateRange $dateRange)
 {
     $ranges = array();
     $start = $dateRange->GetBegin();
     $end = $dateRange->GetEnd();
     if (!$this->SameYear($start, $end)) {
         $current = $start;
         while (!$this->SameYear($current, $end)) {
             $next = $this->GetFirstOfYear($current, 1);
             $ranges[] = new DateRange($current, $next);
             $current = $next;
             if ($this->SameYear($current, $end)) {
                 $ranges[] = new DateRange($current, $end);
             }
         }
     } else {
         $ranges[] = $dateRange;
     }
     return $ranges;
 }
 /**
  * Returns DatePeriod starting from $Date splitted by $interval
  * 
  * @param DateTime $Date Start date
  * @param string $interval Interval, for ex. "1 hour"
  * @return DatePeriod
  */
 protected function _getPeriodByDate(DateTime $Date, $interval = null)
 {
     $Range = new DateRange(clone $Date);
     return $Range->period($this->_getInterval($interval));
 }
Ejemplo n.º 28
0
 public function Update($blackoutInstanceId, DateRange $blackoutDate, $resourceIds, $title, IReservationConflictResolution $reservationConflictResolution, IRepeatOptions $repeatOptions, $scope)
 {
     if (!$blackoutDate->GetEnd()->GreaterThan($blackoutDate->GetBegin())) {
         return new BlackoutDateTimeValidationResult();
     }
     $userId = ServiceLocator::GetServer()->GetUserSession()->UserId;
     $blackoutSeries = $this->LoadBlackout($blackoutInstanceId, $userId);
     if ($blackoutSeries == null) {
         return new BlackoutSecurityValidationResult();
     }
     $blackoutSeries->Update($userId, $scope, $title, $blackoutDate, $repeatOptions, $resourceIds);
     $conflictingBlackouts = $this->GetConflictingBlackouts($blackoutSeries);
     $conflictingReservations = array();
     if (empty($conflictingBlackouts)) {
         $conflictingReservations = $this->GetConflictingReservations($blackoutSeries, $reservationConflictResolution);
     }
     $blackoutValidationResult = new BlackoutValidationResult($conflictingBlackouts, $conflictingReservations);
     if ($blackoutValidationResult->CanBeSaved()) {
         $this->blackoutRepository->Update($blackoutSeries);
     }
     return $blackoutValidationResult;
 }
Ejemplo n.º 29
0
 protected function getPresentationClass($presentation, $questionName, $configs = null)
 {
     $event = new OW_Event('base.questions_field_get_label', array('presentation' => $presentation, 'fieldName' => $questionName, 'configs' => $configs, 'type' => 'edit'));
     OW::getEventManager()->trigger($event);
     $label = $event->getData();
     $class = null;
     $event = new OW_Event('base.questions_field_init', array('type' => 'search', 'presentation' => $presentation, 'fieldName' => $questionName, 'configs' => $configs));
     OW::getEventManager()->trigger($event);
     $class = $event->getData();
     if (empty($class)) {
         switch ($presentation) {
             case BOL_QuestionService::QUESTION_PRESENTATION_TEXT:
             case BOL_QuestionService::QUESTION_PRESENTATION_TEXTAREA:
                 $class = new TextField($questionName);
                 break;
             case BOL_QuestionService::QUESTION_PRESENTATION_CHECKBOX:
                 $class = new CheckboxField($questionName);
                 break;
             case BOL_QuestionService::QUESTION_PRESENTATION_RADIO:
             case BOL_QuestionService::QUESTION_PRESENTATION_SELECT:
             case BOL_QuestionService::QUESTION_PRESENTATION_MULTICHECKBOX:
                 $class = new Selectbox($questionName);
                 break;
             case BOL_QuestionService::QUESTION_PRESENTATION_BIRTHDATE:
             case BOL_QuestionService::QUESTION_PRESENTATION_AGE:
                 $class = new USEARCH_CLASS_AgeRangeField($questionName);
                 if (!empty($configs) && mb_strlen(trim($configs)) > 0) {
                     $configsList = json_decode($configs, true);
                     foreach ($configsList as $name => $value) {
                         if ($name = 'year_range' && isset($value['from']) && isset($value['to'])) {
                             $class->setMinYear($value['from']);
                             $class->setMaxYear($value['to']);
                         }
                     }
                 }
                 $class->addValidator(new USEARCH_CLASS_AgeRangeValidator($class->getMinAge(), $class->getMaxAge()));
                 break;
             case self::QUESTION_PRESENTATION_RANGE:
                 $class = new Range($fieldName);
                 if (empty($this->birthdayConfig)) {
                     $birthday = $this->findQuestionByName("birthdate");
                     if (!empty($birthday)) {
                         $this->birthdayConfig = $birthday->custom;
                     }
                 }
                 $rangeValidator = new RangeValidator();
                 if (!empty($this->birthdayConfig) && mb_strlen(trim($this->birthdayConfig)) > 0) {
                     $configsList = json_decode($this->birthdayConfig, true);
                     foreach ($configsList as $name => $value) {
                         if ($name = 'year_range' && isset($value['from']) && isset($value['to'])) {
                             $class->setMinValue(date("Y") - $value['to']);
                             $class->setMaxValue(date("Y") - $value['from']);
                             $rangeValidator->setMinValue(date("Y") - $value['to']);
                             $rangeValidator->setMaxValue(date("Y") - $value['from']);
                         }
                     }
                 }
                 $class->addValidator($rangeValidator);
                 break;
             case self::QUESTION_PRESENTATION_DATE:
                 $class = new DateRange($fieldName);
                 if (!empty($configs) && mb_strlen(trim($configs)) > 0) {
                     $configsList = json_decode($configs, true);
                     foreach ($configsList as $name => $value) {
                         if ($name = 'year_range' && isset($value['from']) && isset($value['to'])) {
                             $class->setMinYear($value['from']);
                             $class->setMaxYear($value['to']);
                         }
                     }
                 }
                 $class->addValidator(new DateValidator($class->getMinYear(), $class->getMaxYear()));
                 break;
             case BOL_QuestionService::QUESTION_PRESENTATION_URL:
                 $class = new TextField($questionName);
                 $class->addValidator(new UrlValidator());
                 break;
         }
         if (!empty($label)) {
             $class->setLabel($label);
         }
         if (empty($class)) {
             $class = BOL_QuestionService::getInstance()->getSearchPresentationClass($presentation, $questionName, $configs);
         }
     }
     return $class;
 }
Ejemplo n.º 30
0
 private function BuildDateRange($startDate, $startTime, $endDate, $endTime)
 {
     $s = date('Y-m-d', $startDate) . ' ' . $this->MinutesToTime($startTime);
     $e = date('Y-m-d', $endDate) . ' ' . $this->MinutesToTime($endTime);
     return DateRange::Create($s, $e, Configuration::Instance()->GetDefaultTimezone());
 }