/** * @param callable $callback * @param string $scope * @param string $className * @param bool $withHidden * * @return array */ protected function mapFields($callback, $scope, $className, $withHidden) { $result = []; $fields = $this->cache->getFields($className); if (null !== $fields) { foreach ($fields as $field => $data) { if ($withHidden || !$data['h']) { $result[] = $callback($scope, $className, $field, $data['t']); } } } elseif ($this->modelManager->checkDatabase()) { $models = $this->modelManager->getModels($className); $fields = []; /** @var FieldConfigModel $model */ foreach ($models as $model) { $isHidden = $model->isHidden(); $field = $model->getFieldName(); $type = $model->getType(); $fields[$field] = ['t' => $type, 'h' => $isHidden]; if ($withHidden || !$isHidden) { $result[] = $callback($scope, $className, $field, $type); } } $this->cache->saveFields($className, $fields); } return $result; }
public function testGetFieldModelsWithHidden() { $entityModel = $this->createEntityModel(self::TEST_ENTITY); $fieldModel1 = $this->createFieldModel($entityModel, self::TEST_FIELD); $fieldModel2 = $this->createFieldModel($entityModel, self::TEST_FIELD2); $fieldModel2->setMode(ConfigModelManager::MODE_HIDDEN); $this->createRepositoryMock([$entityModel], [UnitOfWork::STATE_MANAGED]); $this->assertEquals([$fieldModel1, $fieldModel2], $this->configModelManager->getModels(self::TEST_ENTITY, true)); }
/** * Gets a list of ids for all configurable entities (if $className is not specified) * or all configurable fields of the given $className. * * @param string $scope * @param string|null $className * @param bool $withHidden Set true if you need ids of all configurable entities, * including entities marked as mode="hidden" * @return array */ public function getIds($scope, $className = null, $withHidden = false) { if (!$this->modelManager->checkDatabase()) { return []; } return array_map(function ($model) use($scope) { return $this->getConfigIdByModel($model, $scope); }, $this->modelManager->getModels($className, $withHidden)); }
/** * Gets a list of ids for all configurable entities (if $className is not specified) * or all configurable fields of the given $className. * * @param string $scope * @param string|null $className * @param bool $withHidden Set true if you need ids of all configurable entities, * including entities marked as mode="hidden" * @param bool $regenerateCaches Regenerate local caches before getting results * @return array */ public function getIds($scope, $className = null, $withHidden = false, $regenerateCaches = false) { if (!$this->modelManager->checkDatabase()) { return []; } if ($regenerateCaches) { $this->modelManager->clearCache(); } $models = $this->modelManager->getModels($className, $withHidden); return array_map(function ($model) use($scope) { return $this->getConfigIdByModel($model, $scope); }, $models); }
/** * @param $scope * @param $className * @return array */ public function getIds($scope, $className = null) { if (!$this->modelManager->checkDatabase()) { return array(); } $entityModels = $this->modelManager->getModels($className); return array_map(function (AbstractConfigModel $model) use($scope) { if ($model instanceof FieldConfigModel) { return new FieldConfigId($model->getEntity()->getClassName(), $scope, $model->getFieldName(), $model->getType()); } else { return new EntityConfigId($model->getClassName(), $scope); } }, $entityModels); }
/** * Gets a list of ids for all configurable entities (if $className is not specified) * or all configurable fields of the given $className. * * @param string $scope * @param string|null $className * @param bool $withHidden Set true if you need ids of all configurable entities, * including entities marked as mode="hidden" * @return array */ public function getIds($scope, $className = null, $withHidden = false) { if (!$this->modelManager->checkDatabase()) { return []; } $models = $this->modelManager->getModels($className, $withHidden); $ids = []; if ($className) { /** @var FieldConfigModel $model */ foreach ($models as $model) { $ids[] = new FieldConfigId($scope, $className, $model->getFieldName(), $model->getType()); } } else { /** @var EntityConfigModel $model */ foreach ($models as $model) { $ids[] = new EntityConfigId($scope, $model->getClassName()); } } return $ids; }
/** * @param string $className * @param string $fieldName * * @return array|null ['i' => field_model_id, 'h' => is_hidden_model, 't' => field_type] */ protected function findField($className, $fieldName) { $result = null; $fields = $this->cache->getFields($className); if (null === $fields && $this->modelManager->checkDatabase()) { $models = $this->modelManager->getModels($className); $fields = []; /** @var FieldConfigModel $model */ foreach ($models as $model) { $isHidden = $model->isHidden(); $field = $model->getFieldName(); $type = $model->getType(); $fields[$field] = ['i' => $model->getId(), 'h' => $isHidden, 't' => $type]; } $this->cache->saveFields($className, $fields); } if (null !== $fields && isset($fields[$fieldName])) { $result = $fields[$fieldName]; } return $result; }
public function testGetModels() { $meta = $this->em->getClassMetadata(EntityConfigModel::ENTITY_NAME); $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $em->expects($this->any())->method('getRepository')->will($this->returnValue(new FoundEntityConfigRepository($em, $meta))); $serviceLink = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\DependencyInjection\\Utils\\ServiceLink')->disableOriginalConstructor()->getMock(); $serviceLink->expects($this->any())->method('getService')->will($this->returnValue($em)); $configModelManager = new ConfigModelManager($serviceLink); $this->assertEquals(array(FoundEntityConfigRepository::getResultConfigEntity()), $configModelManager->getModels()); $this->assertEquals(array(FoundEntityConfigRepository::getResultConfigField()), $configModelManager->getModels(DemoEntity::ENTITY_NAME)); }
/** * @param EntityConfigModel[] $entityModels * @param array $entityStates * @return \PHPUnit_Framework_MockObject_MockObject */ protected function prepareEntityConfigRepository($entityModels = [], $entityStates = []) { $this->repo->expects($this->once())->method('findAll')->will($this->returnValue($entityModels)); $this->prepareCheckDetached($entityStates); $this->configModelManager->getModels(); }