/**
  * 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;
 }
 /**
  * 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 (!($data instanceof ServiceTariffModel || $this->_acceptArrayAsModel && is_array($data))) {
         $this->_messages = array();
         $this->_messages[self::NOT_SERVICE_TARIFF] = $this->_messageTemplatesUser[self::NOT_SERVICE_TARIFF];
         return false;
     }
     if (!parent::isValid($data, $context, $removeNotPresentFields)) {
         return false;
     }
     if (!$data instanceof ServiceTariffModel) {
         $data = new ServiceTariffModel($data);
     }
     if ($data->getN3() !== null && $data->getN2() === null || $data->getN4() !== null && $data->getN2() === null || $data->getN5() !== null && $data->getN4() === null) {
         $this->_messages = array();
         $this->_messages[self::INVALID_SERVICE_TARIFF] = $this->_messageTemplatesUser[self::INVALID_SERVICE_TARIFF];
         return false;
     }
     if ($data->getN3() === null && $data->getN2() !== null && $data->getN4() !== null && $data->getT2Q() === $data->getT4Q()) {
         $this->_messages = array();
         $this->_messages[self::INVALID_SAME_SLOPE_IN_ROW] = $this->_messageTemplatesUser[self::INVALID_SAME_SLOPE_IN_ROW];
         return false;
     }
     return true;
 }