Fetches children resources.

@param array $data
@param Context $context
@throws \Doctrine\ORM\Mapping\MappingException
518880
private function fetchChildrenResources(array &$data, Context $context)
    {
        $resourceName = $this->config->getResourceName();
        //$resourceNamePlural = $this->config->getResourceName(true);

        $resource = $context->getResource($resourceName);

        $childrenConfigurations = $this->get('ekyna_admin.pool_registry')->getChildren($this->config);
        foreach ($childrenConfigurations as $childConfig) {
            $childResourceName = $childConfig->getResourceName(true);
            if (!array_key_exists($childResourceName, $data)) {

                $customizeQb = null;

                /** @var \Doctrine\ORM\Mapping\ClassMetadataInfo $metadata */
                $metadata = $this->get($childConfig->getServiceKey('metadata'));

                // Look for many to one
                if ($metadata->hasAssociation($resourceName)) {
                    $mapping = $metadata->getAssociationMapping($resourceName);
                    if ($mapping['type'] === ClassMetadataInfo::MANY_TO_ONE) {
                        $customizeQb = function (QueryBuilder $qb, $alias) use ($resourceName, $resource) {
                            $qb
                                ->andWhere(sprintf($alias . '.%s = :resource', $resourceName))
                                ->setParameter('resource', $resource);
                        };
                    } else {
                        throw new \RuntimeException(sprintf('"%s" is not a supported association type.', $childResourceName));
                    }
                // Look for many to many
                } /*elseif ($metadata->hasAssociation($resourceNamePlural)) {
                    $mapping = $metadata->getAssociationMapping($resourceNamePlural);
                    if ($mapping['type'] === ClassMetadataInfo::MANY_TO_MANY) {
                        $customizeQb = function (QueryBuilder $qb, $alias) use ($resourceNamePlural, $resource) {
                            $qb
                                ->join($alias.'.'.$resourceNamePlural, 'parent')
                                ->where('parent.id = :resource')
                                ->setParameter('resource', $resource);
                        };
                    } else {
                        throw new \RuntimeException(sprintf('"%s" is not a supported association type.', $childResourceName));
                    }
                }*/ else {
                    throw new \RuntimeException(sprintf('Association "%s" not found.', $childResourceName));
                }

                $table = $this->getTableFactory()
                    ->createBuilder($childConfig->getTableType(), [
                        'name' => $childConfig->getId(),
                        'customize_qb' => $customizeQb,
                    ])
                    ->getTable($context->getRequest());

                //$table->getConfig()->setCustomizeQb($customizeQb);

                $data[$childResourceName] = $table->createView();
            }
        }
    }
776609
public function populate($data = array())
    {
        parent::populate($data);

        if (isset($data['scheduleOccurrenceAuto']) && $data['scheduleOccurrenceAuto'] !== null) {
            $this->scheduleOccurrenceAuto = $data['scheduleOccurrenceAuto'];
        }

        if (isset($data['occurrenceNumber']) && $data['occurrenceNumber'] !== null) {
            $this->occurrenceNumber = $data['occurrenceNumber'];
        }

        if (isset($data['winningOccurrenceNumber']) && $data['winningOccurrenceNumber'] !== null) {
            $this->occurrenceNumber = $data['winningOccurrenceNumber'];
        }

        if (isset($data['occurrenceType']) && $data['occurrenceType'] !== null) {
            $this->occurrenceType = $data['occurrenceType'];
        }
    }
357293
function dataArray(data, context) {
  data = Array.isArray(data) ? data : [data];
  return context ? data.map(d => Object.assign(Object.create(context), d)) : data;
}
404774
public function render(array $data, ContextInterface $context)
    {
        $data = $this->applyButtonClasses($data);

        return parent::render($data, $context);
    }
933478
protected function _afterSelect(DatabaseContext $context)
    {
        $rowset = $context->data;

        if($rowset instanceof DatabaseRowsetInterface)
        {
            $users = array();

            foreach($rowset as $row)
            {
                if(!empty($row->modified_by)) {
                    $users[] = $row->modified_by;
                }
            }

            //Lazy load the users
            $this->getObject('user.provider')->fetch($users, true);
        }
    }
1173851
public static function decode($data, array $context = [])
    {
        $context = array_merge(static::$defaultDecodeContext, $context);

        return static::decodeData($data, $context);
    }
233279
public static function setContextData(array $contextData = [])
    {
        $existContext = [];
        $coroutineId = self::getCoroutineId();
        if (isset(self::$context[$coroutineId][self::DATA_KEY])) {
            $existContext = self::$context[$coroutineId][self::DATA_KEY];
        }
        self::$context[$coroutineId][self::DATA_KEY] = ArrayHelper::merge($contextData, $existContext);
    }
512269
public function load(LoadingContext $context, ParentChildMap $map)
    {
        $filteredParentMap = new ParentChildMap();
        $parentItemMap     = new \SplObjectStorage();
        $relatedEntityMap  = $context->getIdentityMap($this->mapper->getObjectType());

        foreach ($map->getItems() as $item) {
            $relatedId = $item->getParent()->getColumn($this->foreignKeyToRelated);

            if ($relatedId === null) {
                $item->setChild(null);
            } elseif ($this->reference instanceof RelationIdentityReference) {
                $item->setChild((int)$relatedId);
            } elseif ($relatedEntityMap->has($relatedId)) {
                $item->setChild($relatedEntityMap->get($relatedId));
            } else {
                $filteredParentMap->add($item->getParent(), null);
                $parentItemMap[$item->getParent()] = $item;
            }
        }

        if ($filteredParentMap->getAllChildren()) {
            parent::load($context, $filteredParentMap);

            foreach ($filteredParentMap->getItems() as $item) {
                /** @var ParentChildItem $originalItem */
                $originalItem = $parentItemMap[$item->getParent()];
                $originalItem->setChild($item->getChild());
            }
        }
    }
43965
protected function getData(array $context)
    {
        $data = [];
        switch ($context['action']) {
            case 'UPDATE':
                $diff = $this->diff($context['old'], $context['new']);
                foreach ($diff as $item) {
                    list($k, $old, $new) = $item;
                    if (isset($context['new'][$k])) {
                        $data[$k] = [$old, $new];
                    }
                }
                break;
            case 'INSERT':
                foreach ($context['new'] as $k => $val) {
                    $data[$k] = [null, $val];
                }
                break;
            case 'DELETE':
                foreach ($context['old'] as $k => $val) {
                    $data[$k] = [$val, null];
                }
                break;
        }

        return $data;
    }
1007328
protected static function encode($data, array $context)
    {
        $result = base64_encode($data);

        if (false === $result) {
            static::throwEncodingException($data);
        }

        if ($context['base64_encode_url_safe']) {
            return str_replace('=', '', strtr($result, '+/', '-_'));
        }

        return $result;
    }
828477
protected function _fetchData(KViewContext $context)
    {
        $model = $this->getModel();

        //Auto-assign the data from the model
        if($this->_auto_fetch)
        {
            //Set the data
            $name   = $this->getName();
            $entity = $model->fetch();
            $context->data->$name = $entity;

            //Set the parameters
            if($this->isCollection())
            {
                $context->parameters = $model->getState()->getValues();
                $context->parameters->total = $model->count();
            }
            else {
                $context->parameters = $entity->getProperties();
                $context->parameters->total = 1;
            }
        }
        else $context->parameters = $model->getState()->getValues();

        //Set the layout and view in the parameters.
        $context->parameters->layout = $context->layout;
        $context->parameters->view   = $this->getName();
    }
689073
protected function _fetchData(ViewContextTemplate $context)
    {
        $model = $this->getModel();

        //Set the data
        $name = $this->getName();
        $context->data->$name = $context->entity;

        //Set the parameters
        if($this->isCollection())
        {
            $context->parameters->merge($model->getState()->getValues());
            $context->parameters->total = $model->count();
        }
        else
        {
            $context->parameters->merge($context->entity->getProperties());
            $context->parameters->total = 1;
        }

        //Set the layout and view in the parameters.
        $context->parameters->layout = $context->layout;
        $context->parameters->view   = $this->getName();

        $context->parameters->url    = $this->getUrl();
    }
653282
public static function getDataCacheKey($data, Context $context)
    {
        $group = $context->hasAttribute('groups') ? $context->getAttribute('groups') : '*';
        $version = $context->hasAttribute('version') ? $context->getAttribute('version') : '*';

        $dataArray = [
            'data' => $data,
            'serializationFormat' => $context->getFormat(),
            'serializationGroups' => $group,
            'serializationVersion' => $version,
        ];

        try {
            return \sha1(\serialize($dataArray));
        } catch (\Exception $e) {
            return;
        }
    }
353012
public function loadAllObjects(LoadingContext $context, array $rows) : array
    {
        $objects = [];

        foreach ($rows as $key => $row) {
            $objects[$key] = $this->constructNewObjectFromRow($row);
        }

        $this->loadAll($context, $objects, $rows);

        return $objects;
    }
736841
public function persist(PersistenceContext $context, ParentChildrenMap $map)
    {
        $primaryKey        = $map->getPrimaryKeyColumn();
        $relatedPrimaryKey = $this->mapper->getPrimaryTable()->getPrimaryKeyColumnName();
        $children          = $map->getAllChildren();
        $rows              = $this->reference->syncRelated($context, [], $children);

        /** @var Row[] $childRowMap */
        $childRowMap = [];
        foreach ($children as $key => $child) {
            $childRowMap[Identity::hash($child)] = $rows[$key];
        }

        // Clear join rows and reinsert to sync
        if ($map->hasAnyParentsWithPrimaryKeys()) {
            $delete = Delete::from($this->joinTable)
                ->where($this->getInvalidatedRelationExpr($map));
            $context->queue($delete);
        }

        $parentIdColumn  = $this->parentForeignKeyColumn->getName();
        $relatedIdColumn = $this->relatedForeignKeyColumn->getName();
        $joinTableRows   = [];

        foreach ($map->getItems() as $item) {
            $parent = $item->getParent();

            foreach ($item->getChildren() as $child) {
                $joinRow = new Row($this->joinTable);

                if ($parent->hasColumn($primaryKey)) {
                    $joinRow->setColumn($parentIdColumn, $parent->getColumn($primaryKey));
                } else {
                    $parent->onInsertPrimaryKey(function ($id) use ($joinRow, $parentIdColumn) {
                        $joinRow->setColumn($parentIdColumn, $id);
                    });
                }

                $childRow = $childRowMap[Identity::hash($child)];
                if ($childRow->hasColumn($relatedPrimaryKey)) {
                    $joinRow->setColumn($relatedIdColumn, $childRow->getColumn($relatedPrimaryKey));
                } else {
                    $childRow->onInsertPrimaryKey(function ($id) use ($joinRow, $relatedIdColumn) {
                        $joinRow->setColumn($relatedIdColumn, $id);
                    });
                }

                $joinTableRows[] = $joinRow;
            }
        }

        if (!empty($joinTableRows)) {
            $context->upsert(new RowSet($this->joinTable, $joinTableRows));
        }
    }
271877
public function loadCollectionValues(LoadingContext $context, array $rows) : array
    {
        $primaryKey = $this->primaryKeyColumn->getName();
        $ids        = [];

        foreach ($rows as $key => $row) {
            $ids[$key] = $row->getColumn($primaryKey);
        }

        return $ids;
    }
224914
public static function setContextDataByChildKey(string $key, string $child, $val)
    {
        $coroutineId = self::getCoroutineId();
        self::$context[$coroutineId][self::DATA_KEY][$key][$child] = $val;
    }