validateRow

@param $row
@return array
976109
private function validateRow($row)
    {
        if ($row === false)
            return $row;
        $resolver = new OptionsResolver();
        $resolver->setRequired([
            'class',
            'columns',
        ]);
        $resolver->setAllowedTypes('class', 'string');
        $resolver->setAllowedTypes('columns', 'array');
        $row = $resolver->resolve($row);
        if (empty($row['columns']))
            trigger_error(sprintf('An array of columns is compulsory for each row.'), E_USER_ERROR);
        $row['columns'] = $this->validateColumns($row['columns']);
        return $row;
    }
264562
public function applyFilter(array $row)
    {
        $wasTrueOneTime = false;
        $isApply = false;

        foreach ($this->getFilter()->getValues() as $filterValue) {
            $filter = $this->getFilter();
            $col = $filter->getColumn();

            $value = $row[$col->getUniqueId()];
            $value = $col->getType()->getFilterValue($value);

            if ($filter->getOperator() == DatagridFilter::BETWEEN) {
                //BETWEEN have to be tested in one call
                $isApply = DatagridFilter::isApply($value, $this->getFilter()->getValues(), $filter->getOperator());

                return $isApply;
            } else {
                $isApply = DatagridFilter::isApply($value, $filterValue, $filter->getOperator());
            }
            if (true === $isApply) {
                $wasTrueOneTime = true;
            }

            switch ($filter->getOperator()) {
                case DatagridFilter::NOT_LIKE:
                case DatagridFilter::NOT_LIKE_LEFT:
                case DatagridFilter::NOT_LIKE_RIGHT:
                case DatagridFilter::NOT_EQUAL:
                case DatagridFilter::NOT_IN:
                    if (false === $isApply) {
                        // normally one "match" is okay -> so it's applied
                        // but e.g. NOT_LIKE is not allowed to match so even if the othere rules are true
                        // it has to fail!
                        return false;
                    }
                    break;
            }
        }

        if (false === $isApply && true === $wasTrueOneTime) {
            return true;
        }

        return $isApply;
    }
1295894
protected static function filterBySubkey($row)
    {
        $result = false;
        if (is_array($row) && array_key_exists(self::$key, $row)) {
            if ('/' == substr(self::$value, 0, 1)) {
                $result = preg_match(self::$value, $row[self::$key]);
            } else {
                $result = self::$strict
                    ? self::$value === $row[self::$key]
                    : self::$value == $row[self::$key];
            }
        }

        return $result;
    }
472022
public function validate(array $rows, WithValidation $import)
    {
        $rules      = $this->rules($import);
        $messages   = $this->messages($import);
        $attributes = $this->attributes($import);

        try {
            $this->validator->make($rows, $rules, $messages, $attributes)->validate();
        } catch (IlluminateValidationException $e) {
            $failures = [];
            foreach ($e->errors() as $attribute => $messages) {
                $row           = strtok($attribute, '.');
                $attributeName = strtok('');
                $attributeName = $attributes['*.' . $attributeName] ?? $attributeName;

                $failures[] = new Failure(
                    $row,
                    $attributeName,
                    str_replace($attribute, $attributeName, $messages),
                    $rows[$row]
                );
            }

            if ($import instanceof SkipsOnFailure) {
                $import->onFailure(...$failures);
                throw new RowSkippedException(...$failures);
            }

            throw new ValidationException(
                $e,
                $failures
            );
        }
    }
405039
private function bindRowValues(array $row): array
    {
        $placeholders = [];
        foreach ($row as $key => $value) {
            $placeholder = $this->addBindingValue($key, $value);
            array_push($placeholders, $placeholder);
        }
        return $placeholders;
    }
949553
public function decode(string $row): array
    {
        $rows = explode(PHP_EOL, rtrim($row));
        return array_map(function($row) { return json_decode($row, true); }, $rows);
    }
31392
public function validate( array $data ) {

		$errors = [];

		foreach( $this->fields as $field ) {

			$f = $field->name;
			$v = isset($data[$f]) ? $data[$f] : null;

			list($clean, $errors[$f]) = $field->validate($v);

			if( !$errors[$f] )
				$data[$f] = $clean;

		}

		return [
			$data,
			array_filter($errors),
		];

	}
1307013
private function isValid($row)
    {
        $result = false;

        // Check if facet_display_mode is defaulted.
        if ((int) $row['facet_display_mode'] !== FilterDisplayMode::AUTO_DISPLAYED) {
            $result = true;
        }

        // Check remaining fields are not null.
        unset($row[$this->getIdFieldName()]);
        unset($row['attribute_id']);
        unset($row['facet_display_mode']);

        if (!empty(array_filter($row, 'strlen'))) { // Preserve 0 values.
            $result = true;
        }

        return $result;
    }
855764
public function getColumnValue(Row $row)
	{
		$value = parent::getColumnValue($row);

		if (!($value instanceof DateTime)) {
			/**
			 * Try to convert string to DateTime object
			 */
			try {
				$date = DateTimeHelper::tryConvertToDateTime($value);

				return $date->format($this->format);
			} catch (DataGridDateTimeHelperException $e) {
				/**
				 * Otherwise just return raw string
				 */
				return $value;
			}
		}

		return $value->format($this->format);
	}
1333710
protected function collectInvalidColumns(array $row)
    {
        $invalidColumns = [];

        foreach ($row as $column) {
            if (!$this->isColumnName($column)) {
                $invalidColumns[] = $column;
            }
        }
        return $invalidColumns;
    }
1303779
protected function formatRow($row)
    {
        foreach ($row as &$column) {
            if (!is_scalar($column)) {
                $column = $this->serialize($column);
            }
            switch ($this->quoting) {
                case self::QUOTE_NONE:
                    // do nothing... no quoting is happening here
                    break;
                case self::QUOTE_ALL:
                    $column = $this->quote($this->escape($column));
                    break;
                case self::QUOTE_NONNUMERIC:
                    if (preg_match("/[^0-9]/", $column)) {
                        $column = $this->quote($this->escape($column));
                    }
                    break;
                case self::QUOTE_MINIMAL:
                default:
                    if ($this->containsSpecialChars($column)) {
                        $column = $this->quote($this->escape($column));
                    }
                    break;
            }
        }

        return $row;
    }
632526
public function protect_attributes($row)
    {
        foreach ($this->protected_attributes as $attr)
        {
            if (is_object($row))
            {
                unset($row->$attr);
            }
            else
            {
                unset($row[$attr]);
            }
        }

        return $row;
    }
971873
private function convertColumns(array $row)
    {
        $result = [];

        foreach ($row as $fieldName => $value) {
            if (is_null($value)) {
                $result[$fieldName] = null;
                continue;
            }
            switch($this->columnTypes[$fieldName]) {
                case self::BOOL:
                    $value = is_null($value) ? null : $value == 't';
                    break;
                case self::INTEGER:
                case self::SMALLINT:
                case self::BIGINT:
                    $value = (int) $value;
                    break;
                case self::NUMERIC:
                    $value = (float) $value;
                    break;
                case self::JSON:
                    $value = json_decode($value, true);
                    break;
                case self::HSTORE:
                    $value = self::fromHStore($value);
                    break;
                case self::DATE:
                case self::TIMESTAMP:
                case self::TIMESTAMPTZ:
                    $value = self::fromTimestamp($value);
                    break;
                case self::SMALLINT_ARRAY:
                case self::INTEGER_ARRAY:
                    $value = self::fromArray($value);
                    if (!is_null($value)) {
                        $value = array_map(function($a) {
                            return $a === 'NULL' ? null : intval($a);
                        }, $value);
                    }
                    break;
                case self::BIGINT_ARRAY:
                case self::NUMERIC_ARRAY:
                    $value = self::fromArray($value);
                    if (!is_null($value)) {
                        $value = array_map(function($a) {
                            return $a === 'NULL' ? null : doubleval($a);
                        }, $value);
                    }
                    break;
                case self::TEXT_ARRAY:
                case self::VARCHAR_ARRAY:
                case self::CHAR_ARRAY:
                    $value = self::fromArray($value);
                    break;
                case self::HSTORE_ARRAY:
                    $array = self::fromArray($value);
                    $value = [];
                    foreach ($array as $val) {
                        $value[] = self::fromHStore($val);
                    }
                    break;
                case self::JSON_ARRAY:
                    $array = self::fromArray($value);
                    $value = [];
                    foreach ($array as $val) {
                        $value[] = json_decode($val, true);
                    }
                    break;
                case self::INTERVAL:
                    $value = self::fromInterval($value);
                    break;
            }

            $result[$fieldName] = $value;
        }
        return $result;
    }
1023757
private function parseS3CmdListRow($row)
    {
        $columns = explode(' ', preg_replace('/\s+/', ' ', $row));

        if (4 !== count($columns)) {
            throw new \RuntimeException(sprintf('Error processing result: %s', $row));
        }

        return new Backup($columns[3], $columns[2], new \DateTime(sprintf('%s %s', $columns[0], $columns[1])));
    }
174239
protected static function transformRow($row)
    {
        foreach ($row as $key => $value) {
            if ($value instanceof DateTime) {
                $row[$key] = $value->format('Y-m-d H:i:s');
            } else {
                if (is_object($value)) {
                    $row[$key] = (string) $value;
                } else {
                    $row[$key] = $value;
                }
            }
        }

        return $row;
    }
1080265
public function validateRowValues(array $row, $key)
    {
        $row = parent::validateRowValues($row, $key);

        $token = $this->loader->getTracker()->getToken($row['token'] ? $row['token'] : 'emptytoken');

        if ($token->exists) {
            // If token is not completed we can use it, otherwise it depends on the settings
            if ($token->isCompleted()) {
                switch ($this->getTokenCompleted()) {
                    case self::TOKEN_SKIP:
                        return false;

                    case self::TOKEN_ERROR:
                        $this->_addErrors(sprintf(
                                $this->_('Token %s is completed.'),
                                $token->getTokenId()
                                ), $key);
                        break;

                    // Intentional fall-through,
                    // other case are handled in SaveAnswerTask
                }
            }
        } else {
            switch ($this->getNoToken()) {
                case self::TOKEN_SKIP:
                    return false;

                case self::TOKEN_ERROR:
                    $this->_addErrors($this->getNoTokenError($row, $key), $key);
                    break;

                default:
                    $respTrack = $this->findRespondentTrackFor($row);

                    if ($respTrack) {
                        $row['resp_track_id'] == $respTrack;
                    } else {
                        $this->_addErrors(sprintf(
                                $this->_('No track for inserting found for %s.'),
                                implode(" / ", $row)
                                ), $key);
                    }
            }
        }

        return $row;
    }
318068
protected function getCheckedState($row, $data)
	{
		return ($this->value === null)
			? CHtml::value($data, $this->name)
			: $this->evaluateExpression($this->value, array('data' => $data, 'row' => $row));
	}