function doValidate($entity, booking_errorstack $errors) { parent::doValidate($entity, $errors); if (!isset($errors['type']) && !in_array($entity['type'], self::allowed_types(), true)) { $errors['type'] = lang('Invalid Resource Type'); } }
protected function doValidate($entity, booking_errorstack $errors) { parent::doValidate($entity, $errors); // Make sure the template allocation doesn't overlap with any // other existing template allocation if ($entity['to_'] <= $entity['from_']) { $errors['to'] = lang('TO needs to be later than FROM'); } if ($entity['cost'] < 0) { $errors['cost'] = lang('COST needs to be non-negative'); } if (!$entity['resources']) { return; } $id = $this->_marshal($entity['id'] ? $entity['id'] : -1, 'int'); $from_ = $this->_marshal($entity['from_'], 'time'); $to_ = $this->_marshal($entity['to_'], 'time'); $wday = $this->_marshal($entity['wday'], 'int'); $resources = $this->_marshal($entity['resources'], 'intarray'); $season_id = intval($entity['season_id']); $this->db->query("SELECT 1 FROM bb_wtemplate_alloc a1, " . "bb_wtemplate_alloc_resource ar1 " . "WHERE ar1.allocation_id<>{$id} AND ar1.allocation_id=a1.id AND " . " ar1.resource_id IN {$resources} AND " . " a1.season_id = {$season_id} AND " . " a1.wday = {$wday} AND " . " ((a1.from_ >= {$from_} AND a1.from_ < {$to_}) OR " . "\t (a1.to_ > {$from_} AND a1.to_ <= {$to_}) OR " . "\t (a1.from_ < {$from_} AND a1.to_ > {$to_})) ", __LINE__, __FILE__); if ($this->db->next_record()) { $errors['overlaps'] = lang("This allocation overlaps another allocation"); } $this->db->query("SELECT 1 FROM bb_season_boundary " . "WHERE wday = {$wday} AND from_ <= {$from_} AND to_ >= {$to_} AND season_id = {$season_id}", __LINE__, __FILE__); if (!$this->db->next_record()) { $errors['overlaps'] = lang("This allocation is outside season boundaries"); } }