Validates map coordinates
@return boolean|null
6524
protected function validateDataMapStore()
    {
        $field = 'data.map';
        $value = $this->getSubmitted($field);

        if (empty($value)) {
            return null;
        }

        $label = $this->translation->text('Map');

        if (!is_array($value) || count($value) != 2) {
            $this->setErrorInvalid($field, $label);
            return false;
        }

        if (count($value) != count(array_filter($value, 'is_numeric'))) {
            $this->setErrorInvalid($field, $label);
            return false;
        }

        return true;
    }
185189
protected function validateBasepathStore()
    {
        $field = 'basepath';

        if ($this->isExcluded($field) || $this->isError('domain')) {
            return null;
        }

        $value = $this->getSubmitted($field);

        if ($this->isUpdating() && !isset($value)) {
            $this->unsetSubmitted($field);
            return null;
        }

        if ($this->getSubmitted('default')) {
            $this->unsetSubmitted($field);
            return null; // Cannot update basepath of default store
        }

        $updating = $this->getUpdating();

        if (isset($updating['basepath'])
            && $updating['basepath'] === $value
            && $updating['domain'] === $this->getSubmitted('domain')) {
            return true;
        }

        if (preg_match('/^[a-z0-9-]{0,50}$/', $value) !== 1) {
            $this->setErrorInvalid($field, $this->translation->text('Path'));
            return false;
        }

        return true;
    }
201723
protected function validateCityAddress()
    {
        $field = 'city_id';

        if ($this->isExcluded($field) || $this->isError('country')) {
            return null;
        }

        $value = $this->getSubmitted($field);

        if ($this->isUpdating() && !isset($value)) {
            $this->unsetSubmitted($field);
            return null;
        }

        $label = $this->translation->text('City');
        $format = $this->getCountryFormatAddress();

        if (empty($value) && !empty($format['city_id']['required'])) {
            $this->setErrorRequired($field, $label);
            return false;
        }

        // City ID can be either numeric ID or non-numeric human name
        if (is_numeric($value)) {
            if ($this->city->get($value)) {
                return true;
            }
            $this->setErrorUnavailable($field, $label);
            return false;
        }

        if (empty($value)) {
            return true;
        }

        if (mb_strlen($value) > 255) {
            $this->setErrorLengthRange($field, $label);
            return false;
        }

        // Try to convert human name to a numeric ID
        $country = $this->getSubmitted('country');
        $state_id = $this->getSubmitted('state_id');

        if (empty($country) || empty($state_id)) {
            return true;
        }

        $conditions = array(
            'name' => $value,
            'country' => $country,
            'state_id' => $state_id
        );

        foreach ((array) $this->city->getList($conditions) as $city) {
            if (strcasecmp($city['name'], $value) === 0) {
                $this->setSubmitted($field, $city['city_id']);
                break;
            }
        }

        return true;
    }
1164333
protected function validateDestinationExistanceCopy()
    {
        if ($this->isError()) {
            return null;
        }

        $destinations = array();
        $directory = $this->getSubmitted('directory');

        $error = null;
        foreach ((array) $this->getSubmitted('files') as $index => $file) {

            /* @var $file \SplFileInfo */
            if ($file->isDir() && gplcart_path_normalize($file->getRealPath()) === $directory) {
                $error = $this->translation->text('Destination already exists');
                continue;
            }

            $destination = "$directory/" . $file->getBasename();

            if (file_exists($destination)) {
                $error = $this->translation->text('Destination already exists');
                continue;
            }

            $destinations[$index] = $destination;
        }

        if (isset($error)) {
            $this->setError('destination', $error);
        } else {
            $this->setSubmitted('destinations', $destinations);
        }

        return true;
    }
301744
protected function validateNumericCodeCurrency()
    {
        $field = 'numeric_code';

        if ($this->isExcluded($field)) {
            return null;
        }

        $value = $this->getSubmitted($field);

        if ($this->isUpdating() && !isset($value)) {
            $this->unsetSubmitted($field);
            return null;
        }

        $label = $this->translation->text('Numeric code');

        if (empty($value)) {
            $this->setErrorRequired($field, $label);
            return false;
        }

        if (preg_match('/^[0-9]{3}$/', $value) !== 1) {
            $this->setErrorInvalid($field, $label);
            return false;
        }

        $updating = $this->getUpdating();

        if (isset($updating['numeric_code']) && $updating['numeric_code'] == $value) {
            return true;
        }

        foreach ($this->currency->getList() as $currency) {
            if ($currency['numeric_code'] == $value) {
                $this->setErrorExists($field, $label);
                return false;
            }
        }

        return true;
    }
136820
protected function validateSkuCart()
    {
        if ($this->isError('store_id')) {
            return null;
        }

        $field = 'sku';
        $value = $this->getSubmitted($field);

        if (!isset($value)) {
            return null;
        }

        $label = $this->translation->text('SKU');

        if (empty($value)) {
            $this->setErrorRequired($field, $label);
            return false;
        }

        $store_id = $this->getSubmitted('store_id');
        $product = $this->product->getBySku($value, $store_id);

        if (empty($product['product_id'])) {
            $this->setErrorUnavailable($field, $label);
            return false;
        }

        $this->setSubmitted('product', $product);
        return true;
    }
521979
public function validate(
        string $path,
        $value,
        ValidatorContextInterface $context,
        ValidatorInterface $validator = null
    ) {
        if (null === $value) {
            return [];
        }

        if (!is_array($value)) {
            return [new Error(
                $path,
                'constraint.coordinatearray.invalidtype',
                ['type' => is_object($value) ? get_class($value) : gettype($value)]
            )];
        }

        if (!isset($value['lat']) || !isset($value['lon'])) {
            return [new Error($path, 'constraint.coordinatearray.invalidformat', ['value' => json_encode($value)])];
        }

        $lat = $value['lat'];
        $lon = $value['lon'];

        if ($lat < -90 || $lat > 90 || $lon < -180 || $lon > 180) {
            return [new Error($path, 'constraint.coordinatearray.invalidvalue', ['value' => json_encode($value)])];
        }

        return [];
    }
1031639
public function getRevEventGeo()
    {
        if (isset($this->_receive['Latitude'])) {
            return array(
                'x'         => $this->_receive['Latitude'],
                'y'         => $this->_receive['Longitude'],
                'precision' => $this->_receive['Precision'],
            );
        }
        return false;
    }
411301
public void validate() {
        if (this.mapStartPosition != null && this.bboxConfiguration != null
                && !this.bboxConfiguration.contains(this.mapStartPosition)) {
            throw new IllegalArgumentException(
                    "map start position is not valid, must be included in bounding box of the map, bbox: "
                            + this.bboxConfiguration.toString() + " - map start position: "
                            + this.mapStartPosition.toString());
        }
    }
1097411
public function field_validation($values) {
        $valuecount = 0;
        // The lat long class has two values that need to be checked.
        foreach ($values as $value) {
            if (isset($value->value) && !($value->value == '')) {
                $valuecount++;
            }
        }
        // If we have nothing filled in or both filled in then everything is okay.
        if ($valuecount == 0 || $valuecount == 2) {
            return false;
        }
        // If we get here then only one field has been filled in.
        return get_string('latlongboth', 'data');
    }
999058
public function valid()
    {
        // initialize/refresh cursor
        if ($this->cursor != 0 && !isset($this->elements[$this->index])) {
            $this->scan();
        }

        return isset($this->elements[$this->index]);
    }
206071
protected function validateDestinationRename()
    {
        if ($this->isError()) {
            return null;
        }

        $files = $this->getSubmitted('files');

        /* @var $file \SplFileInfo */
        $file = reset($files);
        $name = $this->getSubmitted('name');

        $directory = dirname($file->getRealPath());
        $destination = gplcart_path_normalize("$directory/$name");

        if (file_exists($destination)) {
            $this->setError('name', $this->translation->text('Destination already exists'));
            return false;
        }

        $this->setSubmitted('destination', $destination);
        return true;
    }
1234516
public function validate(
        string $path,
        $value,
        ValidatorContextInterface $context,
        ValidatorInterface $validator = null
    ) {
        if (null === $value || '' === $value) {
            return [];
        }

        if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
            return [new Error(
                $path,
                'constraint.coordinate.invalidtype',
                ['type' => is_object($value) ? get_class($value) : gettype($value)]
            )];
        }

        $value = (string) $value;

        $matches = [];

        if (!preg_match(self::PATTERN, $value, $matches)) {
            return [new Error($path, 'constraint.coordinate.invalidformat', ['value' => $value])];
        }

        $lat = (float) $matches[1];
        $lon = (float) $matches[3];

        if ($lat < -90 || $lat > 90 || $lon < -180 || $lon > 180) {
            return [new Error($path, 'constraint.coordinate.invalidvalue', ['value' => $value])];
        }

        return [];
    }
261527
protected function validatePaymentAddressOrder()
    {
        $field = 'payment_address';

        if ($this->isExcluded($field)) {
            return null;
        }

        $value = $this->getSubmitted($field);

        if (!isset($value) && $this->isUpdating()) {
            $this->unsetSubmitted($field);
            return null;
        }

        if (empty($value) && !$this->isError('shipping_address')) {
            $value = $this->getSubmitted('shipping_address');
        }

        $label = $this->translation->text('Payment address');

        if (empty($value)) {
            $this->setErrorRequired($field, $label);
            return false;
        }

        if (!is_numeric($value)) {
            $this->setErrorNumeric($field, $label);
            return false;
        }

        $address = $this->address->get($value);

        if (empty($address)) {
            $this->setErrorUnavailable($field, $label);
            return false;
        }

        $this->setSubmitted($field, $value);
        return true;
    }
620871
public function validateCodeCountryState()
    {
        $field = 'code';

        if ($this->isExcluded($field)) {
            return null;
        }

        $value = $this->getSubmitted($field);

        if ($this->isUpdating() && !isset($value)) {
            $this->unsetSubmitted($field);
            return null;
        }

        $updating = $this->getUpdating();

        if (isset($updating['code']) && $updating['code'] === $value) {
            return true;
        }

        $label = $this->translation->text('Code');

        if (empty($value)) {
            $this->setErrorRequired($field, $label);
            return false;
        }

        $existing = $this->state->getList(array('code' => $value, 'country' => $this->getSubmitted('country')));

        if (!empty($existing)) {
            $this->setErrorExists($field, $label);
            return false;
        }

        return true;
    }
685202
public function isValid(ValidatorMap $map, $value)
    {
        if (is_null($value) == false && is_numeric($value) == true) {
            return intval($value) <= intval($map->getValue());
        }

        return false;
    }
1246089
protected function validateAlias()
    {
        $field = 'alias';
        $value = $this->getSubmitted($field);

        if (empty($value)) {
            $this->unsetSubmitted($field);
            return null;
        }

        $label = $this->translation->text('Alias');

        if (mb_strlen($value) > 255) {
            $this->setErrorLengthRange($field, $label, 0, 255);
            return false;
        }

        if (preg_match('/^[A-Za-z0-9_.-]+$/', $value) !== 1) {
            $this->setErrorInvalid($field, $label);
            return false;
        }

        $updating = $this->getUpdating();

        if (isset($updating['alias']) && $updating['alias'] === $value) {
            return true; // Do not check own alias on update
        }

        if ($this->alias->exists($value)) {
            $this->setErrorExists($field, $label);
            return false;
        }

        return true;
    }