Exemplo n.º 1
0
 public static function createIncludedDateRangeFilter(DateRange $range)
 {
     return function ($booking) use($range) {
         $bookingRange = new DateRange($booking->start, $booking->end);
         return $range->includes($bookingRange);
     };
 }
 public function dataTableBookingSummary($bookings)
 {
     $ac = $this->_actionController;
     $actions = array('delete' => $ac->getAcl()->isAllowed('_user', 'facility_booking', 'write'), 'details' => $ac->getAcl()->isAllowed('_user', 'facility_booking', 'read'), 'edit' => $ac->getAcl()->isAllowed('_user', 'facility_booking', 'write'));
     $rows = array();
     foreach ($bookings as $booking) {
         $facility = $booking->facility;
         $bookingDateRange = new DateRange($booking->start, $booking->end);
         $rows[] = array('actions' => $actions, 'end' => $booking->end, 'id' => $booking->id, 'is_current' => $bookingDateRange->includes(new DateTime(date('Y-m-d'))), 'name' => implode(' ', $facility->getNamesOnDate($booking->start)), 'start' => $booking->start, 'uri' => $ac->getHelper('Url')->direct('view', 'facility', 'facility', array('id' => $facility->id)), 'delete_uri' => $ac->getHelper('Url')->direct('index', 'delete', 'booking', array('id' => $booking->id)), 'details_uri' => $ac->getHelper('Url')->direct('view', 'index', 'booking', array('id' => $booking->id)), 'edit_uri' => $ac->getHelper('Url')->direct('index', 'edit', 'booking', array('id' => $booking->id)));
     }
     return $rows;
 }
Exemplo n.º 3
0
 public function testIncludes()
 {
     $dr = new DateRange(new DateTime('2006-07-08'), new DateTime('2006-09-05'));
     $this->assertTrue($dr->includes(new DateTime('2006-07-08')));
     $this->assertTrue($dr->includes(new DateTime('2006-08-01')));
     $this->assertFalse($dr->includes(new DateTime('2006-07-07')));
     $this->assertTrue($dr->includes(new DateRange(new DateTime('2006-07-08'), new DateTime('2006-07-10'))));
     $this->assertTrue($dr->includes(new DateRange(new DateTime('2006-07-09'), new DateTime('2006-09-05'))));
     $this->assertFalse($dr->includes(new DateRange(new DateTime('2006-07-07'), new DateTime('2006-07-08'))));
     $this->assertFalse($dr->includes(new DateRange(new DateTime('2006-07-09'), new DateTime('2006-09-06'))));
 }
 protected function roomConfiguration($facility)
 {
     $ac = $this->_actionController;
     $view = $ac->view;
     $actions = array('copy' => $ac->getAcl()->isAllowed('_user', 'facility', 'write'), 'delete' => $ac->getAcl()->isAllowed('_user', 'facility', 'write'), 'edit' => $ac->getAcl()->isAllowed('_user', 'facility', 'write'));
     $rows = array();
     foreach ($facility->configs as $config) {
         $dateRange = new DateRange($config->start, $config->end);
         $row = array('actions' => $actions, 'id' => $config->id, 'is_current' => $dateRange->includes(new DateTime(date('Y-m-d'))), 'name' => $config->name, 'type' => $config->type->name, 'floor' => $config->floor, 'section' => $config->section, 'capacity' => $config->capacity, 'gender' => $config->gender, 'start' => $config->start ?: new DateTime('1900-01-01'), 'end' => $config->end ?: new DateTime('2099-01-01'), 'suite' => $config->suite, 'note' => $config->note, 'default_billing_rule' => $config->default_billing_rule ? $config->default_billing_rule->description : '', 'tags' => $config->tags, 'delete_uri' => $view->url(array('module' => 'facility', 'controller' => 'facilityconfig', 'action' => 'delete', 'id' => $config->id), null, true), 'edit_uri' => $view->url(array('module' => 'facility', 'controller' => 'facilityconfig', 'action' => 'edit', 'id' => $config->id), null, true), 'copy_uri' => $view->url(array('module' => 'facility', 'controller' => 'facilityconfig', 'action' => 'copy', 'id' => $config->id), null, true));
         $rows[] = $row;
     }
     return $rows;
 }
 protected function buildingConfiguration($facilityGroup)
 {
     $ac = $this->_actionController;
     $view = $ac->view;
     $actions = array('delete' => $ac->getAcl()->isAllowed('_user', 'facility', 'write'), 'edit' => $ac->getAcl()->isAllowed('_user', 'facility', 'write'));
     $rows = array();
     foreach ($facilityGroup->configs as $config) {
         $dateRange = new DateRange($config->start, $config->end);
         $row = array('actions' => $actions, 'id' => $config->id, 'is_current' => $dateRange->includes(new DateTime(date('Y-m-d'))), 'name' => $config->name, 'gender' => $config->gender, 'start' => $config->start ?: new DateTime('1900-01-01'), 'end' => $config->end ?: new DateTime('2099-01-01'), 'delete_uri' => $view->url(array('module' => 'facility', 'controller' => 'facilitygroupconfig', 'action' => 'delete', 'id' => $config->id), null, true), 'edit_uri' => $view->url(array('module' => 'facility', 'controller' => 'facilitygroupconfig', 'action' => 'edit', 'id' => $config->id), null, true));
         $rows[] = $row;
     }
     return $rows;
 }
 /**
  * Get last matching rule configuration.
  */
 protected function getMatchingConfiguration($rule, DateTime $date)
 {
     $overlapFilter = function ($config) use($date) {
         $configRange = new DateRange($config->start, $config->end);
         return $configRange->includes($date);
     };
     $overlappingConfigs = $rule->configs->filter($overlapFilter);
     if (count($overlappingConfigs) === 0) {
         throw new Exception\RuntimeException(sprintf('Could not find a rule configuration valid on %s' . ' for rule %s.', $date->format('Y-m-d'), $rule->id));
     }
     // Ordering is guaranteed by the Entity collection specification and
     // preserved by ArrayCollection#filter.
     return $overlappingConfigs->last();
 }
 public function dataTableMealplanDetail($bookings)
 {
     $ac = $this->_actionController;
     $view = $ac->view;
     if (count($bookings) === 0) {
         return array();
     }
     $actions = array('delete' => $ac->getAcl()->isAllowed('_user', 'mealplan_booking', 'write'), 'details' => $ac->getAcl()->isAllowed('_user', 'mealplan_booking', 'read'), 'edit' => $ac->getAcl()->isAllowed('_user', 'mealplan_booking', 'write'));
     $rows = array();
     foreach ($bookings as $booking) {
         $bookingDateRange = new DateRange($booking->start, $booking->end);
         $rows[] = array('actions' => $actions, 'created_at' => $booking->created_at, 'created_by' => $booking->created_by, 'updated_at' => $booking->updated_at, 'updated_by' => $booking->updated_by, 'end' => $booking->end, 'note' => $booking->note, 'id' => $booking->id, 'is_current' => $bookingDateRange->includes(new DateTime(date('Y-m-d'))), 'name' => $view->escape($booking->mealplan->name), 'start' => $booking->start, 'delete_uri' => $view->url(array('module' => 'mealplan', 'controller' => 'delete', 'action' => 'index', 'id' => $booking->id), null, true), 'details_uri' => $view->url(array('module' => 'mealplan', 'controller' => 'index', 'action' => 'view', 'id' => $booking->id), null, true), 'edit_uri' => $view->url(array('module' => 'mealplan', 'controller' => 'edit', 'action' => 'index', 'id' => $booking->id), null, true));
     }
     return $rows;
 }
 public function dataTableFacilityHold($facility)
 {
     $ac = $this->_actionController;
     $view = $ac->view;
     if (count($facility->holds) === 0) {
         return array();
     }
     $actions = array('delete' => $ac->getAcl()->isAllowed('_user', 'facility', 'write'), 'edit' => $ac->getAcl()->isAllowed('_user', 'facility', 'write'));
     $rows = array();
     foreach ($facility->holds as $hold) {
         $holdDateRange = new DateRange($hold->start, $hold->end);
         $row = array('actions' => $actions, 'start' => $hold->start ?: new DateTime('1000-01-01'), 'end' => $hold->end ?: new DateTime('9999-01-01'), 'description' => isset($hold->description) ? $view->escape($hold->description) : '', 'gender' => $hold->gender ?: 'U', 'id' => $hold->id, 'is_current' => $holdDateRange->includes(new DateTime(date('Y-m-d'))), 'space' => $hold->space ?: 0, 'delete_uri' => $view->url(array('module' => 'facility', 'controller' => 'hold', 'action' => 'delete', 'id' => $hold->id), null, true), 'edit_uri' => $view->url(array('module' => 'facility', 'controller' => 'hold', 'action' => 'edit', 'id' => $hold->id), null, true));
         $rows[] = $row;
     }
     return $rows;
 }
 public function dataTableContractSummary($signatures)
 {
     $ac = $this->_actionController;
     $view = $ac->view;
     if (count($signatures) === 0) {
         return array();
     }
     $actions = array('edit' => $ac->getAcl()->isAllowed('_user', 'contract', 'write'));
     $rows = array();
     foreach ($signatures as $signature) {
         $contract = $signature->contract;
         $contractDateRange = new DateRange($contract->start, $contract->end);
         $rows[] = array('actions' => $actions, 'contract' => $contract->name, 'id' => $signature->id, 'is_cancelled' => $signature->is_cancelled, 'is_cosigned' => $signature->is_cosigned, 'is_current' => $contractDateRange->includes(new DateTime(date('Y-m-d'))), 'is_signed' => $signature->is_signed, 'requires_cosigned' => $signature->requires_cosigned, 'signed_at' => $signature->signed_at, 'edit_uri' => $view->url(array('module' => 'contract', 'controller' => 'signature', 'action' => 'edit', 'id' => $signature->id), null, true));
     }
     return $rows;
 }
 public function dataTableFacilityBooking($facility)
 {
     $ac = $this->_actionController;
     $view = $ac->view;
     if (count($facility->bookings) === 0) {
         return array();
     }
     $actions = array('delete' => $ac->getAcl()->isAllowed('_user', 'facility_booking', 'write'), 'details' => $ac->getAcl()->isAllowed('_user', 'facility_booking', 'read'), 'edit' => $ac->getAcl()->isAllowed('_user', 'facility_booking', 'write'));
     $rows = array();
     foreach ($facility->bookings as $booking) {
         $bookingDateRange = new DateRange($booking->start, $booking->end);
         $row = array('actions' => $actions, 'id' => $booking->id, 'is_current' => $bookingDateRange->includes(new DateTime(date('Y-m-d'))), 'person_uri' => $ac->getHelper('Url')->direct('view', 'person', 'person', array('id' => $booking->person->id)), 'person_name' => $view->escape($booking->person->display_name), 'person_gender' => $booking->person->gender, 'start' => $booking->start ?: new DateTime('1900-01-01'), 'end' => $booking->end ?: new DateTime('2099-01-01'), 'delete_uri' => $view->url(array('module' => 'booking', 'controller' => 'delete', 'action' => 'index', 'id' => $booking->id), null, true), 'details_uri' => $view->url(array('module' => 'booking', 'controller' => 'index', 'action' => 'view', 'id' => $booking->id), null, true), 'edit_uri' => $view->url(array('module' => 'booking', 'controller' => 'edit', 'action' => 'index', 'id' => $booking->id), null, true));
         $rows[] = $row;
     }
     return $rows;
 }
Exemplo n.º 11
0
 /**
  * Test whether this DateRange overlaps the current DateRange
  *
  * @param  DateRange $arg Other DateRange to test
  * @return bool
  */
 public function overlaps(DateRange $arg)
 {
     return $arg->includes($this->getStart()) || $arg->includes($this->getEnd()) || $this->includes($arg);
 }
Exemplo n.º 12
0
 /**
  * Get the hold valid on the given date, if any
  *
  * @return Hold\Hold|null
  */
 public function getHoldOnDate(DateTime $date)
 {
     $ret = $this->holds->filter(function ($hold) use($date) {
         $holdRange = new DateRange($hold->start, $hold->end);
         return $holdRange->includes($date);
     })->first();
     return $ret === false ? null : $ret;
 }
Exemplo n.º 13
0
 /**
  * Get the configuration valid on the given date, if any.
  *
  * @param  DateTime           $date Date to test configurations against
  * @return Config\Config|null Configuration on the passed date
  */
 public function getConfigOnDate(DateTime $date)
 {
     foreach ($this->configs as $config) {
         $configRange = new DateRange($config->start, $config->end);
         if ($configRange->includes($date)) {
             return $config;
         }
     }
     return null;
 }