public function getValues($suppressArrayNotation = false)
 {
     $values = parent::getValues($suppressArrayNotation);
     // Return a data structure with headers and data parsed for use
     $parsed = array('header' => array(), 'data' => array());
     $createHeader = function ($rows) {
         $header = array();
         $c = 'A';
         for ($i = 0; $i < count($rows[0]); $i++) {
             $header[] = $c;
             // Make use of PHP's string incrementing behavior to make
             // spreadsheet-like column headers
             //
             // http://php.net/manual/en/language.operators.increment.php
             $c++;
         }
         return $header;
     };
     if ((bool) $values['has_header']) {
         $parsed['header'] = array_slice($this->rawArray, 0, 1);
         $parsed['header'] = $parsed['header'][0];
         $parsed['data'] = array_slice($this->rawArray, 1);
     } else {
         $parsed['header'] = $createHeader($this->rawArray);
         $parsed['data'] = $this->rawArray;
     }
     $values['parsed'] = $parsed;
     return $values;
 }
 public function isValid($data)
 {
     if (!parent::isValid($data)) {
         return false;
     }
     $startDate = new DateTime($data['start']);
     $endDate = new DateTime($data['end']);
     if ($startDate > $endDate) {
         $this->start->addError($this->getTranslator()->translate('The start date must be on or before the end date.'));
         $this->end->addError($this->getTranslator()->translate('The end date must be on or after the start date.'));
         return false;
     }
     $facilityGroup = $this->em->find('Tillikum\\Entity\\FacilityGroup\\FacilityGroup', $data['facilitygroup_id']);
     $qb = $this->em->createQueryBuilder()->select('c.start, c.end')->from('Tillikum\\Entity\\FacilityGroup\\Config\\Config', 'c')->where('c.start <= :proposedEnd')->andWhere('c.end >= :proposedStart')->andWhere('c.facility_group = :facilityGroup')->setParameter('facilityGroup', $facilityGroup)->setParameter('proposedStart', $startDate)->setParameter('proposedEnd', $endDate);
     if ($this->entity && isset($this->entity->id)) {
         $qb->andWhere('c != :entity')->setParameter('entity', $this->entity);
     }
     if (count($rows = $qb->getQuery()->getResult()) > 0) {
         foreach ($rows as $row) {
             $errorMessage = sprintf($this->getTranslator()->translate('An existing configuration from %s to %s overlaps your intended configuration.'), $row['start']->format('Y-m-d'), $row['end']->format('Y-m-d'));
             $this->start->addError($errorMessage);
             $this->end->addError($errorMessage);
         }
         return false;
     }
     return true;
 }
 public function init()
 {
     parent::init();
     $id = new \Zend_Form_Element_Hidden('id', array('decorators' => array('ViewHelper')));
     $through = new \Tillikum_Form_Element_Date('through', array('label' => 'Billed through'));
     $this->addElements(array($id, $through, $this->createSubmitElement(array('label' => 'Next...'))));
 }
 public function isValid($data)
 {
     $dissolvedData = $data;
     if ($this->isArray()) {
         $dissolvedData = $this->_dissolveArrayValue($data, $this->getElementsBelongTo());
     }
     $skipDetailedValidation = true;
     foreach (array('rule_id', 'start', 'end') as $member) {
         if (!empty($dissolvedData[$member])) {
             $skipDetailedValidation = false;
             $this->rule_id->setRequired(true);
             $this->start->setRequired(true);
             $this->end->setRequired(true);
         }
     }
     if (!parent::isValid($data)) {
         return false;
     }
     if ($skipDetailedValidation) {
         return true;
     }
     $data = $dissolvedData;
     $startDate = new DateTime($data['start']);
     $endDate = new DateTime($data['end']);
     if ($startDate > $endDate) {
         $this->start->addError($this->getTranslator()->translate('The start date must be on or before the end date.'));
         $this->end->addError($this->getTranslator()->translate('The end date must be on or after the start date.'));
         return false;
     }
     return true;
 }
 public function init()
 {
     parent::init();
     $username = new \Zend_Form_Element_Text('username', array('label' => 'User name', 'required' => true));
     $password = new \Zend_Form_Element_Password('password', array('label' => 'Password', 'required' => true));
     $this->addElements(array($username, $password, $this->createSubmitElement(array('label' => 'Log in'))));
 }
 public function init()
 {
     parent::init();
     $identity = new \Zend_Form_Element_Hidden('identity', array('decorators' => array('ViewHelper')));
     $isDryRun = new \Zend_Form_Element_Checkbox('is_dry_run', array('attribs' => array('checked' => 'checked'), 'description' => 'The job will run normally, but avoid making' . ' permanent changes to your data.', 'label' => 'Is this a "dry run"?'));
     $this->setMethod('POST')->addElements(array($identity, $isDryRun, $this->createSubmitElement(array('label' => 'Run job', 'order' => PHP_INT_MAX))));
 }
 public function init()
 {
     parent::init();
     $id = new \Zend_Form_Element_Hidden('id', array('decorators' => array('ViewHelper')));
     $facilityGroup = new \Zend_Form_Element_Select('facility_group', array('description' => 'Building names listed here are from the latest' . ' building configuration.', 'label' => 'Which building is this facility a member of?', 'multiOptions' => array()));
     $this->addElements(array($id, $facilityGroup, $this->createSubmitElement(array('label' => 'Save'))));
 }
 public function init()
 {
     parent::init();
     $typeId = new \Zend_Form_Element_Select('type_id', array('label' => 'Email type', 'multiOptions' => array(), 'required' => true));
     $value = new \Zend_Form_Element_Text('value', array('filters' => array('StringTrim'), 'label' => 'Email address', 'required' => true, 'validators' => array('EmailAddress')));
     $isPrimary = new \Zend_Form_Element_Checkbox('is_primary', array('label' => 'Is this the person’s primary email address?'));
     $this->addElements(array($typeId, $value, $isPrimary));
 }
 public function init()
 {
     parent::init();
     $id = new \Zend_Form_Element_Text('id', array('label' => 'Tag ID', 'required' => true));
     $name = new \Zend_Form_Element_Text('name', array('label' => 'Tag name', 'required' => true));
     $isActive = new \Zend_Form_Element_Checkbox('is_active', array('description' => 'Deactivating tags will hide them from menus' . ' around the application, but do not affect' . ' users who are currently tagged.', 'label' => 'Is this tag active?', 'value' => true));
     $warning = new \Zend_Form_Element_Text('warning', array('description' => 'The text entered here, if any, will appear' . ' when a person is tagged with this tag.', 'label' => 'Warning text'));
     $this->addElements(array($id, $name, $isActive, $warning, $this->createSubmitElement(array('label' => 'Save'))));
 }
 public function init()
 {
     parent::init();
     $name = new Zend_Form_Element_Text('name', array('label' => 'Name'));
     $capacity = new Zend_Form_Element_Text('capacity', array('label' => 'Capacity', 'validators' => array(new Zend_Validate_Int())));
     $type = new Zend_Form_Element_Select('ftype', array('label' => 'Facility Type', 'required' => true, 'multiOptions' => array('building' => 'Building', 'community' => 'Community', 'floor' => 'Floor', 'homestay' => 'Homestay Family', 'room' => 'Room', 'suite' => 'Suite', 'wing' => 'Wing')));
     $submit = new Tillikum_Form_Element_Submit('submit');
     $this->addElements(array($name, $capacity, $type, $submit));
 }
 public function init()
 {
     parent::init();
     $input = new Zend_Form_Element_Textarea('textinput', array('label' => 'Tab-separated input', 'description' => 'This input is generated automatically if you perform a copy-paste operation from most spreadsheet software.', 'required' => true));
     $is_include_header = new Zend_Form_Element_Checkbox('is_include_header', array('label' => 'Does the spreadsheet include column headers?'));
     $submit = new Tillikum_Form_Element_Submit('submit');
     $submit->setLabel('Next…');
     $this->setMethod('POST')->addElements(array($input, $is_include_header, $submit));
 }
 public function init()
 {
     parent::init();
     $ruleId = new \Zend_Form_Element_Select('rule_id', array('label' => 'Rule', 'required' => true));
     $currency = new \Zend_Form_Element_Hidden('currency', array('decorators' => array('ViewHelper'), 'required' => true, 'value' => 'USD'));
     $amount = new \Tillikum_Form_Element_Number('amount', array('attribs' => array('min' => '-9999.99', 'max' => '9999.99', 'step' => '0.01', 'title' => 'Value must be precise to no more than 2' . ' decimal places'), 'label' => 'Amount', 'required' => true, 'validators' => array('Float', new \Zend_Validate_Between(-9999.99, 9999.99))));
     $effective = new \Tillikum_Form_Element_Date('effective', array('label' => 'Effective date', 'required' => true, 'value' => date('Y-m-d')));
     $description = new \Zend_Form_Element_Textarea('description', array('attribs' => array('class' => 'short'), 'label' => 'Description', 'required' => true, 'filters' => array('StringTrim')));
     $this->setMethod('POST')->addElements(array($ruleId, $currency, $amount, $effective, $description, $this->createSubmitElement(array('label' => 'Create'))));
 }
 public function init()
 {
     parent::init();
     $personId = new \Zend_Form_Element_Hidden('person_id', array('decorators' => array('ViewHelper'), 'required' => true));
     $contractId = new \Zend_Form_Element_Select('contract_id', array('label' => 'Contract', 'required' => true));
     $signedAt = new \Tillikum_Form_Element_Date('signed_at', array('description' => 'Determines age at time of signing. Leave blank for today’s date.', 'label' => 'When was the contract originally signed?'));
     $isCosigned = new \Zend_Form_Element_Checkbox('is_cosigned', array('label' => 'Is the contract cosigned?'));
     $isCancelled = new \Zend_Form_Element_Checkbox('is_cancelled', array('label' => 'Is the contract cancelled?'));
     $this->addElements(array($personId, $contractId, $signedAt, $isCosigned, $isCancelled, $this->createSubmitElement(array('label' => 'Sign'))));
 }
 public function init()
 {
     parent::init();
     $strategy = new \Zend_Form_Element_Select('strategy', array('label' => 'Strategy', 'multiOptions' => array(), 'required' => true));
     $code = new \Zend_Form_Element_Text('code', array('required' => true, 'label' => 'Code', 'filters' => array('StringTrim')));
     $description = new \Zend_Form_Element_Text('description', array('label' => 'Description', 'filters' => array('StringTrim')));
     $start = new \Tillikum_Form_Element_Date('start', array('label' => 'Start date', 'required' => true));
     $end = new \Tillikum_Form_Element_Date('end', array('label' => 'End date', 'required' => true));
     $this->addElements(array($strategy, $code, $description, $start, $end));
 }
 public function init()
 {
     parent::init();
     $id = new \Zend_Form_Element_Hidden('id', array('decorators' => array('ViewHelper')));
     $mealplanId = new \Zend_Form_Element_Select('mealplan_id', array('label' => 'Meal plan', 'multiOptions' => array(), 'required' => true));
     $start = new \Tillikum_Form_Element_Date('start', array('label' => 'Start date', 'required' => true));
     $end = new \Tillikum_Form_Element_Date('end', array('label' => 'End date', 'required' => true));
     $note = new \Zend_Form_Element_Textarea('note', array('attribs' => array('class' => 'short'), 'label' => 'Notes'));
     $this->addElements(array($id, $mealplanId, $start, $end, $note, $this->createSubmitElement(array('label' => 'Next...'))));
 }
 public function init()
 {
     parent::init();
     $date = new \Tillikum_Form_Element_Date('date', array('label' => 'Facility configuration date', 'required' => true));
     $facilityGroupIds = new \Zend_Form_Element_Multiselect('facilitygroup_ids', array('label' => 'Facility group', 'multiOptions' => array()));
     $gender = new \Zend_Form_Element_Text('gender', array('label' => 'Gender'));
     $capacity = new \Tillikum_Form_Element_Number('capacity', array('attribs' => array('min' => 0), 'label' => 'Capacity'));
     $availableSpace = new \Tillikum_Form_Element_Number('available_space', array('attribs' => array('min' => 0), 'label' => 'Spaces available (at minimum)'));
     $tags = new \Zend_Form_Element_Multiselect('tags', array('label' => 'Tags', 'multiOptions' => array()));
     $this->addElements(array($date, $facilityGroupIds, $gender, $capacity, $availableSpace, $tags, $this->createSubmitElement(array('label' => 'Search'))));
 }
 public function isValid($data)
 {
     if (!parent::isValid($data)) {
         return false;
     }
     $startDate = new DateTime($data['start']);
     $endDate = new DateTime($data['end']);
     if ($startDate > $endDate) {
         $this->start->addError($this->getTranslator()->translate('The start date must be on or before the end date.'));
         $this->end->addError($this->getTranslator()->translate('The end date must be on or after the start date.'));
         return false;
     }
     $facility = $this->em->find('Tillikum\\Entity\\Facility\\Facility', $data['facility_id']);
     $holdQueryBuilder = $this->em->createQueryBuilder()->select('h')->from('Tillikum\\Entity\\Facility\\Hold\\Hold', 'h')->where('h.start <= :proposedEnd')->andWhere('h.end >= :proposedStart')->andWhere('h.facility = :facility')->orderBy('h.start')->setParameter('facility', $facility)->setParameter('proposedStart', $startDate)->setParameter('proposedEnd', $endDate);
     if ($this->entity && isset($this->entity->id)) {
         $holdQueryBuilder->andWhere('h != :entity')->setParameter('entity', $this->entity);
     }
     $holds = $holdQueryBuilder->getQuery()->getResult();
     $bookings = $this->em->createQueryBuilder()->select('b')->from('Tillikum\\Entity\\Booking\\Facility\\Facility', 'b')->where('b.start <= :proposedEnd')->andWhere('b.end >= :proposedStart')->andWhere('b.facility = :facility')->orderBy('b.start')->setParameter('facility', $facility)->setParameter('proposedStart', $startDate)->setParameter('proposedEnd', $endDate)->getQuery()->getResult();
     $configs = $this->em->createQueryBuilder()->select('c')->from('Tillikum\\Entity\\Facility\\Config\\Config', 'c')->where('c.facility = :facility')->orderBy('c.start')->setParameter('facility', $facility)->getQuery()->getResult();
     if (count($holds) > 0) {
         foreach ($holds as $hold) {
             $errorMessage = sprintf($this->getTranslator()->translate('An existing hold from %s to %s overlaps your intended hold.'), $hold->start->format('Y-m-d'), $hold->end->format('Y-m-d'));
             $this->start->addError($errorMessage);
             $this->end->addError($errorMessage);
         }
         return false;
     }
     $occupancyInputs = array(new OccupancyInput($startDate, $data['space'] * -1, sprintf('start of the hold you specified from %s to %s', $startDate->format('Y-m-d'), $endDate->format('Y-m-d'))), new OccupancyInput(date_modify(clone $endDate, '+1 day'), $data['space'], sprintf('end of the hold you specified from %s to %s', $startDate->format('Y-m-d'), $endDate->format('Y-m-d'))));
     foreach ($bookings as $booking) {
         $occupancyInputs[] = new OccupancyInput($booking->start, -1, sprintf('start of a booking from %s to %s', $booking->start->format('Y-m-d'), $booking->end->format('Y-m-d')));
         $occupancyInputs[] = new OccupancyInput(date_modify(clone $booking->end, '+1 day'), 1, sprintf('end of a booking from %s to %s', $booking->start->format('Y-m-d'), $booking->end->format('Y-m-d')));
     }
     $currentConfigSpace = 0;
     foreach ($configs as $config) {
         $occupancyInputs[] = new OccupancyInput($config->start, $config->capacity - $currentConfigSpace, sprintf('start of a facility configuration from %s to %s', $config->start->format('Y-m-d'), $config->end->format('Y-m-d')));
         $currentConfigSpace = $config->capacity;
     }
     foreach ($holds as $hold) {
         $occupancyInputs[] = new OccupancyInput($hold->start, $hold->space * -1, sprintf('start of a hold from %s to %s', $hold->start->format('Y-m-d'), $hold->end->format('Y-m-d')));
         $occupancyInputs[] = new OccupancyInput(date_modify(clone $hold->end, '+1 day'), $hold->space, sprintf('end of a hold from %s to %s', $hold->start->format('Y-m-d'), $hold->end->format('Y-m-d')));
     }
     $occupancyEngine = new OccupancyEngine($occupancyInputs);
     $occupancyResult = $occupancyEngine->run();
     if (!$occupancyResult->getIsSuccess()) {
         $errorMessage = sprintf($this->getTranslator()->translate('There is no available space in this facility to add another ' . 'hold during the specified time period. The problem occurred ' . 'at the %s.'), $occupancyResult->getCulprit()->getDescription());
         $this->start->addError($errorMessage);
         $this->end->addError($errorMessage);
         return false;
     }
     return true;
 }
 public function init()
 {
     parent::init();
     $id = new \Zend_Form_Element_Hidden('id', array('decorators' => array('ViewHelper')));
     $givenName = new \Zend_Form_Element_Text('given_name', array('filters' => array('StringTrim'), 'label' => 'Given name'));
     $middleName = new \Zend_Form_Element_Text('middle_name', array('filters' => array('StringTrim'), 'label' => 'Middle name'));
     $familyName = new \Zend_Form_Element_Text('family_name', array('filters' => array('StringTrim'), 'label' => 'Family name'));
     $displayName = new \Zend_Form_Element_Text('display_name', array('description' => 'This should be used if the person’s name' . ' should not be formatted' . ' “family, given middle”.', 'filters' => array('StringTrim'), 'label' => 'Display name'));
     $gender = new \Zend_Form_Element_Text('gender', array('filters' => array('StringTrim'), 'label' => 'Gender'));
     $tags = new \Zend_Form_Element_Multiselect('tags', array('label' => 'Tags', 'multiOptions' => array()));
     $note = new \Zend_Form_Element_Textarea('note', array('attribs' => array('class' => 'short'), 'filters' => array('StringTrim'), 'label' => 'Notes'));
     $this->addElements(array($id, $givenName, $middleName, $familyName, $displayName, $gender, $tags, $note, $this->createSubmitElement(array('label' => 'Save'))));
 }
 public function isValid($data)
 {
     $isValid = parent::isValid($data);
     if (!$isValid) {
         return $isValid;
     }
     foreach ($this->requiredElements as $element) {
         if (!in_array($element, $data['map'])) {
             $this->getSubForm('map')->addError("Missing required element ({$element})");
             $isValid = false;
         }
     }
     return $isValid;
 }
 public function init()
 {
     parent::init();
     $name = new \Tillikum_Form_Element_Search('name', array('attribs' => array('placeholder' => 'Type the name of a facility'), 'description' => 'A facility is anything that can be booked,' . ' such as a room.', 'label' => 'Facility name'));
     $this->addElements(array($name));
 }
 public function checkMappedData($map, $rows)
 {
     $personGateway = new \TillikumX\Model\PersonGateway();
     $identity = \Zend_Auth::getInstance()->hasIdentity() ? Zend_Auth::getInstance()->getIdentity() : '_system';
     $rowNum = 1;
     $this->data = $rangesByFacility = array();
     foreach ($rows as $row) {
         $person = $personGateway->fetch($row[$map['id']]);
         if (null === $person) {
             return array('result' => false, 'reason' => sprintf('The person with ID %s does not exist.', $row[$map['id']]), 'row' => $rowNum);
         }
         $bookingInput = array('facility' => $row[$map['booking_facility']], 'start' => $row[$map['booking_start']], 'end' => $row[$map['booking_end']]);
         $rates = array();
         for ($i = 0; $i < 3; $i++) {
             $mapOffset = $i + 1;
             if (!isset($map["booking_rate{$mapOffset}_id"]) || !isset($row[$map["booking_rate{$mapOffset}_id"]])) {
                 continue;
             }
             $rate = array('rate' => $row[$map["booking_rate{$mapOffset}_id"]]);
             if (isset($map["booking_rate{$mapOffset}_start"])) {
                 $rate['start'] = $row[$map["booking_rate{$mapOffset}_start"]];
             }
             if (isset($map["booking_rate{$mapOffset}_end"])) {
                 $rate['end'] = $row[$map["booking_rate{$mapOffset}_end"]];
             }
             $bookingInput['rates'][] = $rate;
         }
         if (isset($map['booking_billing_effective'])) {
             $bookingInput['billing_effective'] = $row[$map['booking_billing_effective']];
         }
         if (isset($map['booking_billing_through'])) {
             $bookingInput['billing_through'] = $row[$map['booking_billing_through']];
         }
         $mealplanInput = array();
         if (isset($map['mealplan_plan'])) {
             $mealplanInput['plan'] = $row[$map['mealplan_plan']];
         }
         if (isset($map['mealplan_start'])) {
             $mealplanInput['start'] = $row[$map['mealplan_start']];
         }
         if (isset($map['mealplan_end'])) {
             $mealplanInput['end'] = $row[$map['mealplan_end']];
         }
         for ($i = 0; $i < 1; $i++) {
             $mapOffset = $i + 1;
             if (!isset($map["mealplan_rate{$mapOffset}_id"]) || !isset($row[$map["mealplan_rate{$mapOffset}_id"]])) {
                 continue;
             }
             $rate = array('rate' => $row[$map["mealplan_rate{$mapOffset}_id"]]);
             if (isset($map["mealplan_rate{$mapOffset}_start"])) {
                 $rate['start'] = $row[$map["mealplan_rate{$mapOffset}_start"]];
             }
             if (isset($map["mealplan_rate{$mapOffset}_end"])) {
                 $rate['end'] = $row[$map["mealplan_rate{$mapOffset}_end"]];
             }
             $mealplanInput['rates'][] = $rate;
         }
         if (isset($map['mealplan_billing_effective'])) {
             $mealplanInput['billing_effective'] = $row[$map['mealplan_billing_effective']];
         }
         if (isset($map['mealplan_billing_through'])) {
             $mealplanInput['billing_through'] = $row[$map['mealplan_billing_through']];
         }
         // Set up our form
         $bookingForm = new \Tillikum_Form();
         $bookingForm->setElementsBelongTo('booking');
         $facilitySubForm = new \Tillikum\Form\Booking\Facility();
         $facilitySubForm->setElementsBelongTo('facility');
         $facilitySubForm->setPerson($person);
         $bookingForm->addSubForm($facilitySubForm, 'facility');
         $mealplanSubForm = new \Tillikum\Form\Booking\Mealplan();
         $mealplanSubForm->setElementsBelongTo('mealplan');
         $mealplanSubForm->setPerson($person);
         $mealplanSubForm->plan->setRequired(false);
         $mealplanSubForm->start->setRequired(false);
         $mealplanSubForm->end->setRequired(false);
         $bookingForm->addSubForm($mealplanSubForm, 'mealplan');
         if (array_key_exists($bookingInput['facility'], $rangesByFacility)) {
             foreach ($rangesByFacility[$bookingInput['facility']] as $range) {
                 $facilitySubForm->addExtraDateRange($range);
             }
         }
         $massInput = array('facility' => $bookingInput, 'mealplan' => $mealplanInput);
         if (!$bookingForm->isValid($massInput)) {
             $it = new RecursiveArrayIterator($bookingForm->getMessages());
             $itit = new RecursiveIteratorIterator($it);
             foreach ($itit as $message) {
                 return array('result' => false, 'reason' => $message, 'row' => $rowNum);
             }
         }
         $values = $bookingForm->getValues(true);
         $facilityBooking = $values['facility']['booking'];
         $facilityBooking->created_by = $identity;
         $facilityBooking->updated_by = $identity;
         $ffnHelper = Zend_Controller_Action_HelperBroker::getStaticHelper('FullFacilityName');
         $view = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer')->view;
         $facilityNameArray = $ffnHelper->fullFacilityName($facilityBooking->facility, null, $facilityBooking->start);
         if ($facilityBooking->billing) {
             $bookingCharges = $facilityBooking->processCharges($view->fullFacilityName($facilityNameArray));
             foreach ($bookingCharges as $charge) {
                 $charge->created_by = $identity;
                 $this->data[$person->id]['charges'][] = $charge;
             }
         }
         $this->data[$person->id]['bookings'][] = $facilityBooking;
         $mealplanBooking = $values['mealplan']['booking'];
         if (null !== $mealplanBooking) {
             $mealplanBooking->created_by = $identity;
             $mealplanBooking->updated_by = $identity;
             if ($mealplanBooking->billing) {
                 $mealplanCharges = $mealplanBooking->processCharges($mealplanBooking->plan);
                 foreach ($mealplanCharges as $charge) {
                     $charge->created_by = $identity;
                     $this->data[$person->id]['charges'][] = $charge;
                 }
             }
             $this->data[$person->id]['mealplans'][] = $mealplanBooking;
         }
         $rangesByFacility[$bookingInput['facility']][] = new \Vo\DateRange($facilityBooking->start, $facilityBooking->end);
     }
     return array('result' => true);
 }
 public function init()
 {
     parent::init();
     $format = new \Zend_Form_Element_Select('format', array('label' => 'In which format do you want to see the report data?', 'multiOptions' => array('csv' => 'CSV (download a file, open with spreadsheet software)', 'html' => 'HTML (view report in a table in your browser)'), 'required' => true));
     $this->setMethod('GET')->addElements(array($format, $this->createSubmitElement(array('label' => 'Generate report', 'order' => PHP_INT_MAX))));
 }
 public static function setDefaultOptions(array $options)
 {
     self::$defaultOptions = $options;
 }
 public function isValid($data)
 {
     if (!parent::isValid($data)) {
         return false;
     }
     $startDate = new DateTime($data['start']);
     $endDate = new DateTime($data['end']);
     if ($startDate > $endDate) {
         $this->start->addError($this->getTranslator()->translate('The start date must be on or before the end date.'));
         $this->end->addError($this->getTranslator()->translate('The end date must be on or after the start date.'));
         return false;
     }
     $configRange = new DateRange($startDate, $endDate);
     $facility = $this->em->find('Tillikum\\Entity\\Facility\\Facility', $data['facility_id']);
     $bookings = $this->em->createQueryBuilder()->select('b')->from('Tillikum\\Entity\\Booking\\Facility\\Facility', 'b')->where('b.start <= :proposedEnd')->andWhere('b.end >= :proposedStart')->andWhere('b.facility = :facility')->orderBy('b.start')->setParameter('facility', $facility)->setParameter('proposedStart', $configRange->getStart())->setParameter('proposedEnd', $configRange->getEnd())->getQuery()->getResult();
     $qb = $this->em->createQueryBuilder()->select('c')->from('Tillikum\\Entity\\Facility\\Config\\Config', 'c')->where('c.facility = :facility')->orderBy('c.start')->setParameter('facility', $this->entity->facility);
     if ($this->entity && isset($this->entity->id)) {
         $qb->andWhere('c != :entity')->setParameter('entity', $this->entity);
     }
     $configs = $qb->getQuery()->getResult();
     $overlappingQueryBuilder = $this->em->createQueryBuilder()->select('c')->from('Tillikum\\Entity\\Facility\\Config\\Config', 'c')->where('c.start <= :proposedStart')->andWhere('c.end >= :proposedEnd')->andWhere('c.facility = :facility')->setParameter('proposedStart', $configRange->getStart())->setParameter('proposedEnd', $configRange->getEnd())->setParameter('facility', $this->entity->facility);
     if ($this->entity && isset($this->entity->id)) {
         $overlappingQueryBuilder->andWhere('c != :entity')->setParameter('entity', $this->entity);
     }
     $overlappingConfigs = $overlappingQueryBuilder->getQuery()->getResult();
     $holds = $this->em->createQueryBuilder()->select('h')->from('Tillikum\\Entity\\Facility\\Hold\\Hold', 'h')->where('h.start <= :proposedEnd')->andWhere('h.end >= :proposedStart')->andWhere('h.facility = :facility')->orderBy('h.start')->setParameter('facility', $facility)->setParameter('proposedStart', $configRange->getStart())->setParameter('proposedEnd', $configRange->getEnd())->getQuery()->getResult();
     if (count($overlappingConfigs) > 0) {
         foreach ($overlappingConfigs as $config) {
             $errorMessage = sprintf($this->getTranslator()->translate('An existing configuration from %s to %s overlaps your intended configuration.'), $config->start->format('Y-m-d'), $config->end->format('Y-m-d'));
             $this->start->addError($errorMessage);
             $this->end->addError($errorMessage);
         }
         return false;
     }
     $occupancyInputs = array(new OccupancyInput($configRange->getStart(), $data['capacity'], sprintf('start of the facility configuration you specified from %s to %s', $configRange->getStart()->format('Y-m-d'), $configRange->getEnd()->format('Y-m-d'))));
     foreach ($configs as $config) {
         $occupancyInputs[] = new OccupancyInput($config->start, $config->capacity, sprintf('start of a facility configuration from %s to %s', $config->start->format('Y-m-d'), $config->end->format('Y-m-d')));
         if (!empty($data['suite'])) {
             $suiteConfigs = $this->em->createQueryBuilder()->select('c')->from('Tillikum\\Entity\\Facility\\Config\\Room\\Room', 'c')->join('c.suite', 's')->where('c.start <= :proposedEnd')->andWhere('c.end >= :proposedStart')->andWhere('s.id = :suiteId')->setParameter('proposedStart', $configRange->getStart())->setParameter('proposedEnd', $configRange->getEnd())->setParameter('suiteId', $data['suite'])->getQuery()->getResult();
             foreach ($suiteConfigs as $suiteConfig) {
                 if (!empty($suiteConfig->gender)) {
                     $suiteGenderSpec = isset($suiteGenderSpec) ? $suiteGenderSpec->andSpec(new GenderMatchSpecification($suiteConfig->gender)) : new GenderMatchSpecification($suiteConfig->gender);
                 }
             }
         }
     }
     // We need to re-sort since the user-specified input will not be sorted
     usort($occupancyInputs, function ($a, $b) {
         if ($a->getDate() == $b->getDate()) {
             return 0;
         }
         return $a->getDate() < $b->getDate() ? -1 : 1;
     });
     // Actually calculate moments after re-sorting
     $currentConfigSpace = 0;
     foreach ($occupancyInputs as $idx => $input) {
         $oldValue = $input->getValue();
         $occupancyInputs[$idx] = new OccupancyInput($input->getDate(), $input->getValue() - $currentConfigSpace, $input->getDescription());
         $currentConfigSpace = $oldValue;
     }
     foreach ($bookings as $booking) {
         $occupancyInputs[] = new OccupancyInput($booking->start, -1, sprintf('start of a booking from %s to %s', $booking->start->format('Y-m-d'), $booking->end->format('Y-m-d')));
         $occupancyInputs[] = new OccupancyInput(date_modify(clone $booking->end, '+1 day'), 1, sprintf('end of a booking from %s to %s', $booking->start->format('Y-m-d'), $booking->end->format('Y-m-d')));
         if (!empty($booking->person->gender)) {
             $bookingGenderSpec = isset($bookingGenderSpec) ? $bookingGenderSpec->andSpec(new GenderMatchSpecification($booking->person->gender)) : new GenderMatchSpecification($booking->person->gender);
         }
     }
     foreach ($holds as $hold) {
         $occupancyInputs[] = new OccupancyInput($hold->start, $hold->space * -1, sprintf('start of a hold from %s to %s', $hold->start->format('Y-m-d'), $hold->end->format('Y-m-d')));
         $occupancyInputs[] = new OccupancyInput(date_modify(clone $hold->end, '+1 day'), $hold->space, sprintf('end of a hold from %s to %s', $hold->start->format('Y-m-d'), $hold->end->format('Y-m-d')));
         if (!empty($hold->gender)) {
             $holdGenderSpec = isset($holdGenderSpec) ? $holdGenderSpec->andSpec(new GenderMatchSpecification($hold->gender)) : new GenderMatchSpecification($hold->gender);
         }
     }
     $occupancyEngine = new OccupancyEngine($occupancyInputs);
     $occupancyResult = $occupancyEngine->run();
     if (!$occupancyResult->getIsSuccess()) {
         $this->capacity->addError(sprintf($this->getTranslator()->translate('There are too many claims on space in this facility ' . 'to change the capacity of this configuration. The ' . 'problem occurred at the %s.'), $occupancyResult->getCulprit()->getDescription()));
         return false;
     }
     if (isset($holdGenderSpec) && !$holdGenderSpec->isSatisfiedBy($data['gender'])) {
         $this->addWarning(sprintf($this->getTranslator()->translate('The desired configuration gender does not meet the' . ' gender requirements of an overlapping facility hold.')));
     }
     if (isset($bookingGenderSpec) && !$bookingGenderSpec->isSatisfiedBy($data['gender'])) {
         $this->addWarning(sprintf($this->getTranslator()->translate('The desired configuration gender does not meet the' . ' gender requirements of an overlapping booking.')));
     }
     if (isset($suiteGenderSpec) && !$suiteGenderSpec->isSatisfiedBy($data['gender'])) {
         $this->addWarning(sprintf($this->getTranslator()->translate('The desired configuration gender does not meet the' . ' gender requirements of an overlapping booking in a' . ' related suite.')));
     }
     return true;
 }
 public function init()
 {
     parent::init();
     $search = new \Tillikum_Form_Element_Search('search', array('attribs' => array('placeholder' => 'Person’s name or identifier'), 'label' => 'Search'));
     $this->setMethod('GET')->addElements(array($search, $this->createSubmitElement(array('label' => 'Search'))));
 }
 public function init()
 {
     parent::init();
     $description = new \Zend_Form_Element_Text('description', array('label' => 'Description', 'required' => true));
     $this->setMethod('POST')->addElements(array($description, $this->createSubmitElement(array('label' => 'Save', 'order' => PHP_INT_MAX))));
 }
 public function init()
 {
     parent::init();
     $name = new \Tillikum_Form_Element_Search('name', array('attribs' => array('placeholder' => 'Type the name of a facility group'), 'description' => 'A facility group is a container for facilities,' . ' such as a building.', 'label' => 'Find a facility group'));
     $this->addElements(array($name));
 }
 public function init()
 {
     parent::init();
     $type = new \Zend_Form_Element_Select('type', array('label' => 'Which type of facility configuration do you want to add?', 'multiOptions' => self::$typeOptions, 'required' => true));
     $this->addElements(array($type, $this->createSubmitElement(array('label' => 'Next...'))));
 }
 public function isValid($data)
 {
     if (!parent::isValid($data)) {
         return false;
     }
     if ($this->isArray()) {
         $data = $this->_dissolveArrayValue($data, $this->getElementsBelongTo());
     }
     $startDate = new DateTime($data['start']);
     $endDate = new DateTime($data['end']);
     if ($startDate > $endDate) {
         $this->start->addError($this->getTranslator()->translate('The start date must be on or before the end date.'));
         $this->end->addError($this->getTranslator()->translate('The end date must be on or after the start date.'));
         return false;
     }
     $bookingRange = new DateRange($startDate, $endDate);
     $bookingFacility = $this->em->find('Tillikum\\Entity\\Facility\\Facility', $data['facility_id']);
     $person = $this->booking->person;
     $bookings = $this->em->createQueryBuilder()->select('b')->from('Tillikum\\Entity\\Booking\\Facility\\Facility', 'b')->where('b.start <= :proposedEnd')->andWhere('b.end >= :proposedStart')->andWhere('b.facility = :facility')->andWhere('b.person != :person')->orderBy('b.start')->setParameter('facility', $bookingFacility)->setParameter('person', $person)->setParameter('proposedStart', $bookingRange->getStart())->setParameter('proposedEnd', $bookingRange->getEnd())->getQuery()->getResult();
     $configs = $this->em->createQueryBuilder()->select('c')->from('Tillikum\\Entity\\Facility\\Config\\Config', 'c')->where('c.facility = :facility')->orderBy('c.start')->setParameter('facility', $bookingFacility)->getQuery()->getResult();
     $holds = $this->em->createQueryBuilder()->select('h')->from('Tillikum\\Entity\\Facility\\Hold\\Hold', 'h')->where('h.start <= :proposedEnd')->andWhere('h.end >= :proposedStart')->andWhere('h.facility = :facility')->orderBy('h.start')->setParameter('facility', $bookingFacility)->setParameter('proposedStart', $bookingRange->getStart())->setParameter('proposedEnd', $bookingRange->getEnd())->getQuery()->getResult();
     $occupancyInputs = array(new OccupancyInput($bookingRange->getStart(), -1, sprintf('start of the booking range you specified from %s to %s', $bookingRange->getStart()->format('Y-m-d'), $bookingRange->getEnd()->format('Y-m-d'))), new OccupancyInput(date_modify(clone $bookingRange->getEnd(), '+1 day'), 1, sprintf('end of the booking range you specified from %s to %s', $bookingRange->getStart()->format('Y-m-d'), $bookingRange->getEnd()->format('Y-m-d'))));
     foreach ($bookings as $booking) {
         $occupancyInputs[] = new OccupancyInput($booking->start, -1, sprintf('start of a booking from %s to %s', $booking->start->format('Y-m-d'), $booking->end->format('Y-m-d')));
         $occupancyInputs[] = new OccupancyInput(date_modify(clone $booking->end, '+1 day'), 1, sprintf('end of a booking from %s to %s', $booking->start->format('Y-m-d'), $booking->end->format('Y-m-d')));
         if (!empty($booking->person->gender)) {
             $bookingGenderSpec = isset($bookingGenderSpec) ? $bookingGenderSpec->andSpec(new GenderMatchSpecification($booking->person->gender)) : new GenderMatchSpecification($booking->person->gender);
         }
     }
     $currentConfigSpace = 0;
     foreach ($configs as $config) {
         $occupancyInputs[] = new OccupancyInput($config->start, $config->capacity - $currentConfigSpace, sprintf('start of a facility configuration from %s to %s', $config->start->format('Y-m-d'), $config->end->format('Y-m-d')));
         $currentConfigSpace = $config->capacity;
         if (!empty($config->gender)) {
             $facilityGenderSpec = isset($facilityGenderSpec) ? $facilityGenderSpec->andSpec(new GenderMatchSpecification($config->gender)) : new GenderMatchSpecification($config->gender);
         }
         if (!empty($config->suite)) {
             $suiteConfigs = $this->em->createQueryBuilder()->select('c')->from('Tillikum\\Entity\\Facility\\Config\\Room\\Room', 'c')->where('c.start <= :proposedEnd')->andWhere('c.end >= :proposedStart')->andWhere('c.suite = :suite')->setParameter('proposedStart', $bookingRange->getStart())->setParameter('proposedEnd', $bookingRange->getEnd())->setParameter('suite', $config->suite)->getQuery()->getResult();
             foreach ($suiteConfigs as $suiteConfig) {
                 if (!empty($suiteConfig->gender)) {
                     $suiteGenderSpec = isset($suiteGenderSpec) ? $suiteGenderSpec->andSpec(new GenderMatchSpecification($suiteConfig->gender)) : new GenderMatchSpecification($suiteConfig->gender);
                 }
             }
         }
     }
     foreach ($holds as $hold) {
         $occupancyInputs[] = new OccupancyInput($hold->start, $hold->space * -1, sprintf('start of a hold from %s to %s', $hold->start->format('Y-m-d'), $hold->end->format('Y-m-d')));
         $occupancyInputs[] = new OccupancyInput(date_modify(clone $hold->end, '+1 day'), $hold->space, sprintf('end of a hold from %s to %s', $hold->start->format('Y-m-d'), $hold->end->format('Y-m-d')));
         if (!empty($hold->gender)) {
             $holdGenderSpec = isset($holdGenderSpec) ? $holdGenderSpec->andSpec(new GenderMatchSpecification($hold->gender)) : new GenderMatchSpecification($hold->gender);
         }
     }
     $occupancyEngine = new OccupancyEngine($occupancyInputs);
     $occupancyResult = $occupancyEngine->run();
     if (!$occupancyResult->getIsSuccess()) {
         $this->facility_name->addError(sprintf($this->getTranslator()->translate('There is no available space in this facility to book another' . ' resident during the specified time period. The problem' . ' occurred at the %s.'), $occupancyResult->getCulprit()->getDescription()));
         return false;
     }
     if (isset($bookingGenderSpec) && !$bookingGenderSpec->isSatisfiedBy($person->gender)) {
         $this->addWarning(sprintf($this->getTranslator()->translate('The person you are booking with gender %s did not meet' . ' the gender requirements of the other people booked' . ' to this facility for the desired time period.'), $person->gender));
     }
     if (isset($facilityGenderSpec) && !$facilityGenderSpec->isSatisfiedBy($person->gender)) {
         $this->addWarning(sprintf($this->getTranslator()->translate('The person you are booking with gender %s did not meet' . ' the gender requirements of the configurations for this' . ' facility for the desired time period.'), $person->gender));
     }
     if (isset($holdGenderSpec) && !$holdGenderSpec->isSatisfiedBy($person->gender)) {
         $this->addWarning(sprintf($this->getTranslator()->translate('The person you are booking with gender %s did not meet' . ' the gender requirements of the holds on this facility' . ' for the desired time period.'), $person->gender));
     }
     if (isset($suiteGenderSpec) && !$suiteGenderSpec->isSatisfiedBy($person->gender)) {
         $this->addWarning(sprintf($this->getTranslator()->translate('The person you are booking with gender %s did not meet' . ' the gender requirements of the other people booked to' . ' this suite for the specified time period.'), $person->gender));
     }
     return true;
 }
 public function init()
 {
     $options = $this->getOptions();
     \Tillikum_Form::setDefaultOptions($options);
     return $this;
 }