Process row data.

@param \Cake\ORM\Table $table Table instance
@param mixed[] $csvFields Table csv fields
@param mixed[] $data Entity data
@return mixed[]
189261
protected function _processData(Table $table, array $csvFields, array $data) : array
    {
        $schema = $table->getSchema();
        foreach ($data as $field => $value) {
            if (!empty($csvFields) && in_array($field, array_keys($csvFields))) {
                switch ($csvFields[$field]->getType()) {
                    case 'related':
                        $data[$field] = $this->_findRelatedRecord($table, $field, $value);
                        break;
                    case 'list':
                        $data[$field] = $this->_findListValue($table, $csvFields[$field]->getLimit(), $value);
                        break;
                    case 'country':
                        $data[$field] = $this->_findListValue($table, 'countries', $value);
                        break;
                }
            } else {
                if ('uuid' === $schema->columnType($field)) {
                    $data[$field] = $this->_findRelatedRecord($table, $field, $value);
                } else {
                    $data[$field] = $value;
                }
            }
        }

        return $data;
    }
1360250
protected function prepareRows(array $data)
    {
        $rows = [];

        foreach ($data as $date => $levels) {
            $rows[$date] = array_merge(compact('date'), $levels);
        }

        return $rows;
    }
299597
protected static function validateDisplayColumns(array $data, array $fields): array
    {
        foreach ($data as $k => $v) {
            if (in_array($v, $fields)) {
                continue;
            }
            unset($data[$k]);
        }

        return $data;
    }
175035
private function getFileIdsByField(array $data, string $field) : array
    {
        $result = Hash::extract($data, sprintf('%s.%s_ids', $this->table->getAlias(), $field));
        $result = empty($result) ? Hash::extract($data, sprintf('%s_ids', $field)) : $result;
        $result = array_filter((array)$result);

        return $result;
    }
998182
public function insertRecord($table, array $data)
    {
        $dbHandle = $this->getDatabaseConnection();

        $fieldSet = array_keys($data);

        // Prepare sets
        $valueSet = array();
        foreach ($data as $key => $value) {
            $valueSet[':' . $key] = $value;
        }

        if (count($fieldSet) == 0 || count($valueSet) == 0) {
            throw new \Exception('Missing data for insert query', 1363894664);
        }

        $fieldSet[] = 'tstamp';
        $valueSet[':tstamp'] = time();

        $fieldSet[] = 'crdate';
        $valueSet[':crdate'] = time();

        $query = 'INSERT INTO ' . $table . ' (`' . implode('`,`', $fieldSet) . '`)
                  VALUES (' . implode(', ', array_keys($valueSet)) . ')';

        $statement = $dbHandle->prepare($query);
        $executeResult = $statement->execute($valueSet);

        $this->checkQueryError($statement, $executeResult, $valueSet);
        return $dbHandle->lastInsertId();
    }
513882
public function insert($table, array $data)
     {
         try {
             krsort($data);

             $fieldNme = implode('`,`', array_keys($data));
             $fieldValues = ':'.implode(',:', array_keys($data));
             $this->_beginTransaction();

             $stmt = $this->conn->prepare("INSERT INTO $table (`$fieldNme`) VALUES ($fieldValues)");

             foreach ($data as $key => $values) {
                 $stmt->bindValue(":$key", $values);
             }
             $this->_commit();
             $stmt->execute();
             unset($stmt);
         } catch (Exception $e) {
             $this->_Rollback();
             echo 'error insert '.$e->getMessage();
         }
     }
832797
protected function _process(Table $table, $chunkCount, $chunkSize, $fields) {
        $query = $table->find();
        if ($table->hasFinder('purifier')) {
            $query->find('purifier');
        }

        $fields[] = $table->primaryKey();

        $results = $query
            ->select($fields)
            ->offset($chunkCount)
            ->limit($chunkSize)
            ->orderDesc($table->aliasField($table->primaryKey()))
            ->all();

        if (empty($results)) {
            return;
        }

        foreach ($results as $result) {
            try {
                $table->save($result);
                $chunkCount++;
            } catch (\Exception $e) {
                $this->abort($e->getMessage());
            }
        }
    }
793726
protected function getTableFields( $_table ) {

        $_sql = "SHOW COLUMNS FROM {$_table}";
        $_ret = $this->execute( $_sql );
        $_fields = array();
        if ( $_ret != false ) {
            while ( ($_rows = $_ret->fetch()) != false ) {
                $_fields[] = $_rows[0];
            }
        }
        return $_fields;
    }
1100172
public function run(array $fields, $table, $connection = null, $method = 'table')
	{
		$table = substr($table, strlen(\DB::getTablePrefix()));
		$this->table = $table;
        if (!is_null($connection)) $method = 'connection(\''.$connection.'\')->'.$method;
		$compiled = $this->compiler->compile($this->getTemplate(), ['table'=>$table,'method'=>$method]);
		return $this->replaceFieldsWith($this->getItems($fields), $compiled);
	}
1273011
public function rowsFromRaw($data)
	{
		$rows = new Rows;

		if ($data && count($data) > 0)
		{
			foreach ($data as $row)
			{
				$rows->push(self::newFromResults($row));
			}
		}

		return $rows;
	}
1106038
public static function actionButtons(ResultSetInterface $resultSet, Table $table, array $data) : array
    {
        $view = new View();
        list($plugin, $controller) = pluginSplit($table->getRegistryAlias());

        foreach ($resultSet as $key => $entity) {
            if (!$entity->get('model_id')) {
                $data[$key][] = '';
                continue;
            }

            $url = [
                'prefix' => false,
                'plugin' => $plugin,
                'controller' => $controller,
                'action' => 'view',
                $entity->get('model_id')
            ];
            $link = $view->Html->link('<i class="fa fa-eye"></i>', $url, [
                'title' => __('View'),
                'class' => 'btn btn-default',
                'escape' => false
            ]);

            $html = '<div class="btn-group btn-group-xs" role="group">' . $link . '</div>';

            $data[$key][] = $html;
        }

        return $data;
    }
538914
public function withData(array $data, array $fields = [])
    {
        $clone = clone $this;
        $clone->_fields = !empty($fields) ? \array_intersect_key($data, \array_flip($fields)) : $data;
        $clone->_errors = [];

        return $clone;
    }
848919
public function invoke(array $data)
	{
		$columns = $this->getColumns() ?: $this->grid->getColumns();

		$csv_data_model = new CsvDataModel($data, $columns, $this->grid->getTranslator());

		if ($this->grid->getPresenter() instanceof Nette\Application\UI\Presenter) {
			$this->grid->getPresenter()->sendResponse(new CSVResponse(
				$csv_data_model->getSimpleData(),
				$this->name,
				$this->output_encoding,
				$this->delimiter,
				$this->include_bom
			));

			exit(0);
		}
	}
1121966
private function SetObjData($_table, $_fields, $_data)
    {
        $this->table = $_table;
        $this->fields = $_fields;
        $this->data[] = array();

        if (isset($_data[0]) and is_array($_data[0])) {
            for ($i=0; $i<count($_data); $i++) {
                foreach ($this->fields as $field) {
                    if (isset($_data[$i][$field]) and !$this->IsFieldLocked($field)) {
                        $this->data[$i][$field] = $this->Escape($_data[$i][$field]);
                    }
                }
            }
        } else {
            foreach ($this->fields as $field) {
                if (isset($_data[$field]) and !$this->IsFieldLocked($field)) {
                    $this->data[0][$field] = $this->Escape($_data[$field]);
                }
            }
        }
    }
348720
private function filter_table_data($table, $data) {
		$table_fields = $this->get_columns($table);
		$result = [];

		foreach ($table_fields as $field) {
			if (array_key_exists($field, $data)) {
				$result[ $field ] = $data[$field];
			}
		}

		if (count($data) == 0) {
			return [];
		}
		return $result;
	}
859988
private function updateFromCsv(array $data, string $table, array $fields) : void
    {
        $tableFields = [];
        // get existing table column names
        foreach ($fields as $field) {
            $tableFields[] = $field->getName();
        }

        // keep track of edited columns
        $editedColumns = [];
        foreach ($data as $col) {
            $csvField = new CsvField($col);
            $dbFields = $this->factory->fieldToDb($csvField, $table);

            if (empty($dbFields)) {
                continue;
            }

            foreach ($dbFields as $dbField) {
                // edit existing column
                if (in_array($dbField->getName(), $tableFields)) {
                    $editedColumns[] = $dbField->getName();
                    $this->updateColumn($dbField);
                } else { // add new column
                    $this->createColumn($dbField);
                }
            }
        }

        // remove unneeded columns
        foreach (array_diff($tableFields, $editedColumns) as $fieldName) {
            $this->deleteColumn($fieldName);
        }
    }
415370
public function table(array $data)
    {
        $columns = array();

        foreach ($data as $rkey => $row) {
            foreach ($row as $ckey => $cell) {
                $length = strlen($cell);
                if (empty($columns[$ckey]) || $columns[$ckey] < $length) {
                    $columns[$ckey] = $length;
                }
            }
        }

        $table = '';

        foreach ($data as $rkey => $row) {
            foreach ($row as $ckey => $cell) {
                $table .= str_pad($cell, $columns[$ckey]) . '   ';
            }
            $table .= PHP_EOL;
        }

        $this->line($table);
    }