/** * Validate element value * * If a translation adapter is registered, any error messages will be * translated according to the current locale, using the given error code; * if no matching translation is found, the original message will be * utilized. * * Note: The *filtered* value is validated. * * @param array $data * @param mixed $context * @return boolean */ public function isValid($data, $context = null, $removeNotPresentFields = false) { if (!is_array($data)) { $this->_messages = array(); $this->_messages[self::NOT_TARIFF_LIST] = $this->_messageTemplatesUser[self::NOT_TARIFF_LIST]; return false; } $zones = array(); $defaultDest = array(); foreach ($data as $item) { if (!is_array($item)) { $this->_error(self::NOT_TARIFF); return false; } if (!$item instanceof ServiceTariffModel) { $item = new ServiceTariffModel($item); } $defaultDest[] = '-1'; //Default destination for default zone is defined on default tariff if (!isset($zones[$item->getZoneGroupId()])) { $zones[] = $item->getZoneGroupId(); } if ($item->getDestinationId() == "-1") { $defaultDest[] = $item->getZoneGroupId(); } } foreach ($zones as $zone) { if (!in_array($zone, $defaultDest)) { $this->_error(self::NOT_DEFAULT_DESTINATION, $zone); return false; } } return true; }