<?php

namespace Webkul\DamBundle\Datasource\Orm;

use Oro\Bundle\DataGridBundle\Datasource\ResultRecord;
use Webkul\DamBundle\Listener\ClassDefinationForCompatibility;

$versionCompatiblility = new ClassDefinationForCompatibility();
$versionCompatiblility->createClassAliases();

class ResultRecordHydrator implements \HydratorInterface
{
    /**
     * {@inheritdoc}
     */
    public function hydrate($qb, array $options = [])
    {
        $records = [];

        foreach ($qb->getQuery()->execute() as $record) {
            if ('array' === gettype($record) && isset($record[0])) {
                $newRecord = $record[0];
                
                if (count($record) > 1) {
                    foreach ($record as $key => $value) {
                        if (!is_numeric($key)) {
                            $newRecord->$key = $value;
                        }
                    }
                }
                $record = $newRecord;
              
                if (array($record)) {
                    $record['is_checked'] = false;
                }
            } else {
                if (array($record)) {
                    $record['is_checked'] = false;
                }
            }
            
            
            $records[] = new ResultRecord($record);
        }
        
        
        return $records;
    }
}
