@param array $dataItem

@return array

@throws DbException
198173
private function getKeyValue(array $dataItem): array
    {
        $result = [];
        $keyId = null;

        foreach ($this->mappingList as $mapKey => $mapItem) {
            $name = $mapItem[FieldsInterface::ARRAY_NAME];
            $type = $mapItem[FieldsInterface::ARRAY_TYPE] ?? FieldsInterface::TYPE_STRING;

            if (!key_exists($mapKey, $dataItem)) {
                $msg = vsprintf('Item "%s" not found in %s', [$mapKey, var_export($dataItem, true),]);
                throw new DbException($msg, DbException::WRONG_MAPPING);
            }

            $result[$name] = $this->convert($dataItem[$mapKey], $type);

            if (key_exists(FieldsInterface::ARRAY_KEY_PK, $mapItem)) {
                $keyId = $result[$name];
            }
        }

        return [$keyId, $result];
    }
1301451
public function setDataLinked(array &$data) {
		$this->_data   = [];
		$this->_models = [];
		
		$modelClass = $this->getModel();
		
		foreach ($data as $key => &$item) {
			if (is_object($item)) {
				if (! $item instanceof $modelClass) {
					throw new Exception('Model must be an instance of "' . $modelClass . '"');
				}
				
				$this->_data[$key]   = &$item->getDataLinked();
				$this->_models[$key] = $item;
			}
			elseif (is_array($item)) {
				$this->_data[$key] = &$item;
			}
			else {
				throw new Exception('Unknown type of item: "' . gettype($item) . '"');
			}
		}
		unset($item);
		
		$this->_pointer = 0;
		$this->_map     = array_keys($this->_data);
		
		return $this;
	}
440889
private function getCollectionData(
        DataProviderInterface $provider,
        string $fieldname,
        array $data,
        string $getMethod
    ): array {
        $data[$fieldname] = [];
        foreach ($provider->{$getMethod}() as $child) {
            $data[$fieldname][] = $child->toArray();
        }
        return $data;
    }
1274150
private function parseTraceItem(array $traceItem)
    {
        $text = '';
        $info = [
            'file' => $this->getArrayValue($traceItem, 'file', 'unknown'),
            'function' => $this->getArrayValue($traceItem, 'function', 'unknown'),
            'line' => $this->getArrayValue($traceItem, 'line', 'unknown'),
            'class' => $this->getArrayValue($traceItem, 'class', 'unknown'),
            'type' => $this->getArrayValue($traceItem, 'type', 'unknown'),
        ];
        $text .= $this->formatter->arrayToKeyValueList($info);

        return "\n" . $this->formatter->indent($text);
    }
378819
public function insert( $query, array $data = [ ] )
    {
        $id = NULL;

        $statement = $this->database->prepare( $query );

        if ( FALSE === $statement )
        {
            $this->close();

            throw new DatabaseException( 'Failed to create prepared statement.' );
        }

        $result = $statement->execute( $data );

        $this->query = $statement->queryString;

        if ( FALSE !== $result )
        {
            $result = ( int ) $this->database->lastInsertId();
        }

        return $result;
    }
1017587
private function getDataProviderCollectionData(
        DataProviderInterface $provider,
        string $fieldname,
        array $data,
        string $getMethod
    ): array {
        $data[$fieldname] = [];
        foreach ($provider->{$getMethod}() as $child) {
            $anyDataProvider = new AnyDataProvider($child);
            $data[$fieldname][] = $anyDataProvider->toArray();
        }
        return $data;
    }
1089663
protected function itemToArray($item)
    {
        if (is_array($item)) {
            return $item;
        } elseif (method_exists($item, 'toArray')) {
            return $item->toArray();
        } elseif (method_exists($item, 'getArrayCopy')) {
            return $item->getArrayCopy();
        }

        throw new Exception\RuntimeException(sprintf(
            'Items as part of this DataSource, with type "%s" cannot be cast to an array',
            is_object($item) ? get_class($item) : gettype($item)
        ));
    }
812891
public function getItems($offset, $limit) {
		if ($this->_data === null) {
			throw new RuntimeException('Wasn\'t data been provided');
		}
		
		$items = array_slice($this->_data, $offset, $limit);
		
		if ($this->_wrapIntoCollection) {
			return new Collection($items, $this->_modelClass, $this->_primary);
		} else {
			return new ArrayIterator($items);
		}
	}
514518
public function setToSql(): array
    {
        if (!$this->set) {
            throw new SqlException('Undefined UPDATE SET columns.');
        }

        $sql = $params = [];

        foreach ($this->set as $item) {
            $sqlPart = $item['sql'];

            $item['params'] && $params = array_merge($params, $item['params']);

            $sql[] = $sqlPart;
        }

        $sql = 'SET ' . implode(', ', $sql);

        return [$sql, $params];
    }
535627
protected function prepareDataForEntity(array $data)
    {
        /**
         * @var \Everon\DataMapper\Interfaces\Schema\Column $Column
         */
        foreach ($this->getMapper()->getTable()->getColumns() as $name => $Column) {
            if (array_key_exists($name, $data) === false) {
                if ($Column->isPk()) {
                    $data[$name] = null;
                }
                else if ($Column->isNullable() === false) {
                    throw new Exception\Domain('Missing Entity data: "%s" for "%s"', [$name, $this->getMapper()->getTable()->getName()]);
                }
                
                $data[$name] = null;
            }
            
            $data[$name] = $Column->getColumnDataForEntity($data[$name]);
        }

        return $data;
    }
471404
public function execute(array $params = []) : array
    {
        foreach ($params as $paramName => $paramValue) {
            $type = is_int($paramValue) ? \SQLITE3_INTEGER : \SQLITE3_TEXT;
            $this->getStatement()->bindValue($paramName, $paramValue, $type);
        }
        $result = $this->getStatement()->execute();

        $results = [];
        while ($row = $result->fetchArray(\SQLITE3_ASSOC)) {
            $results[] = $row;
        }

        return $results;
    }
1222311
private static function fetchData(databox $databox, array $subdefIds)
    {
        $found = [];
        $missing = [];

        foreach ($subdefIds as $index => $subdefId) {
            try {
                $data = self::doGetDataFromCache($databox, $subdefId);
            } catch (Exception $exception) {
                $data = false;
            }

            if (is_array($data)) {
                $found[$index] = $data;

                continue;
            }

            $missing[$index] = $subdefId;
        }

        if (!$missing) {
            return $found;
        }

        $dbalData = $databox->get_connection()->fetchAll(
            self::getSelectSql(),
            ['subdef_id' => array_values($missing)],
            ['subdef_id' => Connection::PARAM_INT_ARRAY]
        );

        foreach ($dbalData as $item) {
            $itemSubdefId = $item['subdef_id'];

            $databox->set_data_to_cache($item, self::generateCacheKey($itemSubdefId));

            $foundIndexes = array_keys(array_intersect($missing, [$itemSubdefId]));

            foreach ($foundIndexes as $foundIndex) {
                $found[$foundIndex] = $item;
                unset($missing[$foundIndex]);
            }
        }

        return $found;
    }
513624
public function prepareDataSource(array $dataSource)
    {
        if (isset($dataSource['data']['items'])) {
            foreach ($dataSource['data']['items'] as & $item) {
                if (isset($item['stockist_id'])) {
                    $item[$this->getData('name')] = [
                        'edit' => [
                            'href' => $this->_urlBuilder->getUrl(
                                static::URL_PATH_EDIT,
                                [
                                    'stockist_id' => $item['stockist_id']
                                ]
                            ),
                            'label' => __('Edit')
                        ],
                        'delete' => [
                            'href' => $this->_urlBuilder->getUrl(
                                static::URL_PATH_DELETE,
                                [
                                    'stockist_id' => $item['stockist_id']
                                ]
                            ),
                            'label' => __('Delete'),
                            'confirm' => [
                                'title' => __('Delete "${ $.$data.name }"'),
                                'message' => __('Are you sure you wan\'t to delete the Store "${ $.$data.name }" ?')
                            ]
                        ]
                    ];
                }
            }
        }
        return $dataSource;
    }
689545
public function getItemsAfter(ActivityFeedItem $targetItem): array
    {
        $newerItems = [];

        foreach($this->getItems() as $item) {
            if ($item->equals($targetItem)) {
                break;
            }

            $newerItems[] = $item;
        }

        return $newerItems;
    }
1000999
protected function fetchData(int $dataOffset, array $line): array
    {
        $data = parent::fetchData($dataOffset, $line);

        //Forming pivot data presence
        return array_merge(
            [ORMInterface::PIVOT_DATA => array_slice($data, 0, $this->countPivot)],
            array_slice($data, $this->countPivot)
        );
    }
62027
public function collection($resourceKey, array $data)
    {
        $resources = [];

        foreach ($data as $resource) {
            $resources[] = $this->item($resourceKey, $resource)['data'];
        }

        return ['data' => $resources];
    }
485684
public function update(array $data) : int
    {
        $table = $this->definition->getName();
        $columns = $this->definition->getFullColumns();
        $update = [];
        foreach ($data as $column => $value) {
            if (isset($columns[$column])) {
                $update[$column] = $this->normalizeValue($columns[$column], $value);
            }
        }
        if (!count($update)) {
            throw new DBException('No valid columns to update');
        }
        $sql = 'UPDATE '.$table.' SET ';
        $par = [];
        $sql .= implode(', ', array_map(function ($v) { return $v . ' = ?'; }, array_keys($update))) . ' ';
        $par = array_merge($par, array_values($update));
        if (count($this->where)) {
            $sql .= 'WHERE ';
            $tmp = [];
            foreach ($this->where as $v) {
                $tmp[] = $v[0];
                $par = array_merge($par, $v[1]);
            }
            $sql .= implode(' AND ', $tmp) . ' ';
        }
        if (count($this->order)) {
            $sql .= $this->order[0];
            $par = array_merge($par, $this->order[1]);
        }
        return $this->db->query($sql, $par)->affected();
    }