@param Record[] $records

@return array
969069
public static function orderRecords(array $records, $order)
    {

        if (!is_array($order))
        {
            $order = [ $order ];
        }

        $instructions = [ ];
        foreach ($order as $property)
        {
            $property  = trim($property);
            $sortorder = substr($property, -1);

            switch ($sortorder)
            {
                case '-';
                case '+':
                    $property = substr($property, 0, -1);
                    break;
                default:
                    $sortorder = '+';
                    break;

            }

            $instructions[] = [ 'property' => $property, 'order' => $sortorder ];

        }

        uasort($records, function (Record $a, Record $b) use ($instructions)
        {

            foreach ($instructions as $instruction)
            {
                $property = $instruction['property'];
                $order    = $instruction['order'];

                switch ($property)
                {
                    case '.id':
                        $valueA = $a->getId();
                        $valueB = $b->getId();
                        break;
                    case '.info.creation.username':
                        $valueA = $a->getCreationUserInfo()->getUsername();
                        $valueB = $b->getCreationUserInfo()->getUsername();
                        break;
                    case '.info.creation.firstname':
                        $valueA = $a->getCreationUserInfo()->getFirstname();
                        $valueB = $b->getCreationUserInfo()->getFirstname();
                        break;
                    case '.info.creation.lastname':
                        $valueA = $a->getCreationUserInfo()->getLastname();
                        $valueB = $b->getCreationUserInfo()->getLastname();
                        break;
                    case '.info.creation.timestamp':
                        $valueA = $a->getCreationUserInfo()->getTimestamp();
                        $valueB = $b->getCreationUserInfo()->getTimestamp();
                        break;
                    case '.info.lastchange.username':
                        $valueA = $a->getLastChangeUserInfo()->getUsername();
                        $valueB = $b->getLastChangeUserInfo()->getUsername();
                        break;
                    case '.info.lastchange.firstname':
                        $valueA = $a->getLastChangeUserInfo()->getFirstname();
                        $valueB = $b->getLastChangeUserInfo()->getFirstname();
                        break;
                    case '.info.lastchange.lastname':
                        $valueA = $a->getLastChangeUserInfo()->getLastname();
                        $valueB = $b->getLastChangeUserInfo()->getLastname();
                        break;
                    case '.info.lastchange.timestamp':
                        $valueA = $a->getLastChangeUserInfo()->getTimestamp();
                        $valueB = $b->getLastChangeUserInfo()->getTimestamp();
                        break;
                    default:
                        $valueA = $a->getProperty($property);
                        $valueB = $b->getProperty($property);
                        break;
                }

                if ($order == '+')
                {
                    if ($valueA < $valueB)
                    {
                        return -1;
                    }
                    if ($valueA > $valueB)
                    {
                        return 1;
                    }
                }
                else
                {
                    if ($valueA > $valueB)
                    {
                        return -1;
                    }
                    if ($valueA < $valueB)
                    {
                        return 1;
                    }
                }

            }

        });

        return $records;
    }
292506
protected function tableData($records)
    {
        return [
            'draw'            => request('draw') + 1,
            'recordsTotal'    => $this->queryHandler->getRecordsCount(),
            'recordsFiltered' => $this->queryHandler->getFilteredCount(),
            'data'            => $records->toArray(),
        ];
    }
609692
protected function transform_db_records_to_entities(array $records) {
        $preprocessors = $this->get_preprocessors();
        $result = array_map(function($record) {
            return ['record' => $record];
        }, $records);

        $result = array_reduce(array_keys($preprocessors), function($carry, $preprocessor) use ($records, $preprocessors) {
            $step = $preprocessors[$preprocessor];
            $dependencies = $step->execute($records);

            foreach ($dependencies as $index => $dependency) {
                // Add the new dependency to the list.
                $carry[$index] = array_merge($carry[$index], [$preprocessor => $dependency]);
            }

            return $carry;
        }, $result);

        return $this->from_db_records($result);
    }
1160197
private function processDoctrineLogRecord(array $record)
    {
        if (!isset($record['context']) || empty($record['context'])) {
            return $record;
        }

        $isDatabaseQueryContext = $this->arrayContainsOnlyNumericKeys($record['context']);
        if ($isDatabaseQueryContext) {
            $record['context'] = array('query params' => $record['context']);
        }

        return $record;
    }
743168
protected function processRecord(array $record): array
    {
        if ($this->processors) {
            foreach ($this->processors as $processor) {
                $record = PhpHelper::call($processor, $record);
            }
        }

        return $record;
    }
1009457
public function createView($records)
    {
        if ($records instanceof Content) {
            $this->processSingleRecord($records);
        } elseif ($records instanceof QueryResultset) {
            $this->processRecords($records);
        }

        return $records;
    }
983507
protected function filterRecord(array $record)
    {
        foreach ($this->filteredKeys as $key) {
            if (isset($record[$key]) {
                unset($record[$key]);
            }
        }
        
        // Convert datetime object to string
        if (! isset($record['datetime'])) {
            $record['datetime'] = new \DateTime("now");
        }
        $record['datetime'] = $record['datetime']->format(self::DATE_FORMAT);

        return $record;
    }
802658
public static function toScalarValues($record)
    {
        return array_map(
            function ($v) {
                if (!is_scalar($v)) {
                    return '<' . gettype($v) . '>';
                }
                return $v;
            },
            (array)$record
        );
    }
641876
protected function prepare(Collection $record)
    {
        $placeholders = $record->toArray();
        
        $message = $placeholders['message'];
        unset($placeholders['message']);
        
        $content = $message['content'];
        $context = $placeholders + $message['context'];
        
        $flattened = [];
        $this->flatten($context, [], $flattened);
        
        $message = $this->replace($content, $flattened);
        
        $placeholders['message'] = $message;
        
        return $placeholders;
    }
1088441
protected function processRecords(array $records)
    {
        $record = new Record();
        $formatter = $this->getFormatter();
        if ($this->isInstanceOf($formatter, FormatterInterface::class)) {
            $formatter->formatRecords($records, $record);
        }

        $this->write($record);

        return $this->bubble;
    }
548038
public function getPivot(RecordInterface $record): array
    {
        if (empty($matched = $this->matchOne($record))) {
            return [];
        }

        return $this->pivotData->offsetGet($matched);
    }
76196
public function setOrder(array $records)
    {
        $config = $this->getConfig();
        $table = $this->_table;

        $table->removeBehavior('Sequence');

        $return = $table->getConnection()->transactional(
            function ($connection) use ($table, $records) {
                $order = $this->_config['start'];
                $field = $this->_config['order'];

                /** @var string $primaryKeyField */
                $primaryKeyField = $table->getPrimaryKey();
                foreach ($records as $record) {
                    if (is_scalar($record)) {
                        $record = [$primaryKeyField => $record];
                    }

                    if (is_array($record)) {
                        $record = $table->newEntity($record, [
                            'fields' => array_keys($record),
                            'validate' => false,
                            'accessibleFields' => [
                                $primaryKeyField => true,
                            ],
                        ]);
                        $record->isNew(false);
                        $record->setDirty($primaryKeyField, false);
                    }

                    $record->setAccess($field, true);
                    $record->set($field, $order++);

                    $r = $table->save(
                        $record,
                        ['atomic' => false, 'checkRules' => false]
                    );
                    if ($r === false) {
                        return false;
                    }
                }

                return true;
            }
        );

        $table->addBehavior('ADmad/Sequence.Sequence', $config);

        return $return;
    }
781223
public function getDatatableParameters($record)
    {
        $datatableParameters = [
            'DT_RowId' => config('laratables.row_id_prefix').$record->{$record->getKeyName()},
        ];

        if (method_exists($this->class, 'laratablesRowClass')) {
            $datatableParameters['DT_RowClass'] = $record->laratablesRowClass();
        }

        if (method_exists($this->class, 'laratablesRowData')) {
            $datatableParameters['DT_RowData'] = $record->laratablesRowData();
        }

        return $datatableParameters;
    }
97143
public static function tably($records)
    {
        if (count($records) === 0) {
            return null;
        }
        
        $htmls = array();
        $htmls[] = '<table>';
        foreach ($records as $record) {
            $htmls[] = '<tr>';
            foreach ($record as $k => $v) {
                $htmls[] = sprintf('<td class="%s">%s</td>', Str::machine($k), $v);
            }
            $htmls[] = '</tr>';
        }
        $htmls[] = '</table>';
        return join("\n", $htmls);
    }
378409
public function saveRecords(array $records, DataDimensions $dataDimensions = null)
    {
        if (count($records) > 0)
        {
            $record          = reset($records);
            $contentTypeName = $record->getContentTypeName();

            if (!$dataDimensions)
            {
                $dataDimensions = $this->getCurrentDataDimensions();
            }

            $recordIds  = [ ];
            $allRecords = $this->getAllRecords($contentTypeName, $dataDimensions);

            foreach ($records as $record)
            {
                $record = $this->finalizeRecord($record, $dataDimensions);

                if ($record->getID() == '')
                {
                    $nextId = 1;
                    if (count($allRecords) > 0)
                    {

                        $nextId = max(array_keys($allRecords)) + 1;
                    }
                    $record->setID($nextId);
                    $record->setRevision(0);
                }

                $mergedRecord = $this->mergeExistingRecord($record, $dataDimensions);

                $mergedRecord->setRevision($mergedRecord->getRevision() + 1);
                $record->setRevision($mergedRecord->getRevision());
                $mergedRecord->setLastChangeUserInfo($this->userInfo);
                $record->setLastChangeUserInfo($this->userInfo);

                $allRecords[$mergedRecord->getID()] = $mergedRecord;
                $recordIds[]                        = $mergedRecord->getID();
            }

            $data = json_encode([ 'records' => $allRecords ], JSON_PRETTY_PRINT);

            if ($this->writeData($this->getConfiguration()->getUriRecords($contentTypeName), $data))
            {
                $this->stashAllRecords($allRecords, $dataDimensions);

                return $recordIds;

            }
            throw new AnyContentClientException('Error when saving records of content type ' . $this->getCurrentContentTypeName());
        }

        return [ ];
    }
818331
public function groupRecords($records)
    {
        if (!is_array($records) || empty($records)) {
            return;
        }

        $groups = array($this->get('element_name') => array());

        foreach ($records as $r) {
            $data = $r->getData($this->get('id'));
            $value = General::sanitize($data['value']);

            if (!isset($groups[$this->get('element_name')][$data['handle']])) {
                $groups[$this->get('element_name')][$data['handle']] = array(
                    'attr' => array('handle' => $data['handle'], 'value' => $value),
                    'records' => array(),
                    'groups' => array()
                );
            }

            $groups[$this->get('element_name')][$data['handle']]['records'][] = $r;
        }

        return $groups;
    }
1087129
protected function mergeRecords(array $records)
    {
        foreach ($records as $key => $record) {
            if (null === $id = array_get($record, static::ID_FIELD)) {
                throw new InternalServerErrorException('No ' .
                    static::ID_FIELD .
                    ' field found in supplied record(s). Cannot merge record(s) for PATCH operation.');
            }

            $rs = $this->getConnection()->getDocument($this->transactionTable, $id);
            $record = array_merge($rs, $record);
            $records[$key] = $record;
        }

        return $records;
    }