コード例 #1
0
ファイル: ConfigModelTest.php プロジェクト: hugeval/platform
 public function testEntityConfigModel()
 {
     $className = 'Test\\TestClass';
     $entityModel = new EntityConfigModel($className);
     $this->assertEmpty($entityModel->getId());
     $this->assertEquals($className, $entityModel->getClassName());
     $className1 = 'Test\\TestClass1';
     $entityModel->setClassName($className1);
     $this->assertEquals($className1, $entityModel->getClassName());
 }
コード例 #2
0
 /**
  * Test class is NOT extend and should NOT be persisted
  */
 public function testNewNotExtendEntity()
 {
     $configModel = new EntityConfigModel('Oro\\Bundle\\EntityExtendBundle\\Tests\\Unit\\Fixtures\\TestClass2');
     $entityConfig = new Config(new EntityConfigId('Oro\\Bundle\\EntityExtendBundle\\Tests\\Unit\\Fixtures\\TestClass2', 'extend'));
     /**
      * value of NEW Config should be empty
      */
     $this->assertEquals([], $entityConfig->all());
     $this->configProvider->expects($this->any())->method('getConfig')->will($this->returnValue($entityConfig));
     $event = new EntityConfigEvent($configModel->getClassName(), $this->configManager);
     $listener = new EntityConfigListener();
     $listener->updateEntity($event);
     $this->assertEquals([], $this->configManager->getUpdateConfig());
 }
コード例 #3
0
 public function test()
 {
     $this->assertEquals('test', $this->configField->getFieldName($this->configField->setFieldName('test')));
     $this->assertEquals('string', $this->configField->getType($this->configField->setType('string')));
     $this->assertEquals('Acme\\Bundle\\DemoBundle\\Entity\\TestAccount', $this->configEntity->getClassName($this->configEntity->setClassName('Acme\\Bundle\\DemoBundle\\Entity\\TestAccount')));
     /** test ConfigField set/getEntity */
     $this->configField->setEntity($this->configEntity);
     $this->assertEquals($this->configEntity, $this->configField->getEntity());
     /** test ConfigField getOptions */
     $this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $this->configField->getOptions());
     /** test ConfigEntity addField */
     $this->configEntity->addField($this->configField);
     $this->assertEquals($this->configField, $this->configEntity->getField('test'));
     /** test ConfigEntity setFields */
     $this->configEntity->setFields(array($this->configField));
     $this->assertEquals(array($this->configField), $this->configEntity->getFields());
     /** test ConfigValue */
     $this->configValue->setCode('is_extend')->setScope('extend')->setValue(true)->setField($this->configField);
     $this->assertEquals(array('code' => 'is_extend', 'scope' => 'extend', 'value' => true, 'serializable' => false), $this->configValue->toArray());
     /** test Config setValues() */
     $this->configEntity->setValues(array($this->configValue));
     $this->assertEquals($this->configValue, $this->configEntity->getValue('is_extend', 'extend'));
 }
コード例 #4
0
 /**
  * Test class is NOT extend and should NOT be persisted
  */
 public function testNewNotExtendEntity()
 {
     $configModel = new EntityConfigModel('Oro\\Bundle\\EntityExtendBundle\\Tests\\Unit\\Fixtures\\TestClass2');
     $entityConfig = new Config(new EntityConfigId('Oro\\Bundle\\EntityExtendBundle\\Tests\\Unit\\Fixtures\\TestClass2', 'extend'));
     /**
      * value of NEW Config should be empty
      */
     $this->assertEquals([], $entityConfig->all());
     $configProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $configProvider->expects($this->any())->method('getConfig')->will($this->returnValue($entityConfig));
     $configManager = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->setMethods(['getProvider'])->getMock();
     $configManager->expects($this->any())->method('getProvider')->with('extend')->will($this->returnValue($configProvider));
     $event = new EntityConfigEvent($configModel->getClassName(), $configManager);
     $extendConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $configSubscriber = new ConfigSubscriber($extendConfigProvider);
     $configSubscriber->updateEntityConfig($event);
     /** @var ConfigManager $cm */
     $cm = $event->getConfigManager();
     $this->assertObjectHasAttribute('persistConfigs', $cm);
     $this->assertAttributeEquals(null, 'persistConfigs', $cm);
 }
コード例 #5
0
 /**
  * @Route(
  *      "/unremove/{id}",
  *      name="oro_entityextend_entity_unremove",
  *      requirements={"id"="\d+"},
  *      defaults={"id"=0}
  * )
  * Acl(
  *      id="oro_entityextend_entity_unremove",
  *      label="oro.entity_extend.action.config_entity_grid.unremove",
  *      type="action",
  *      group_name=""
  * )
  */
 public function unremoveAction(EntityConfigModel $entity)
 {
     if (!$entity) {
         throw $this->createNotFoundException('Unable to find EntityConfigModel entity.');
     }
     /** @var ConfigManager $configManager */
     $configManager = $this->get('oro_entity_config.config_manager');
     $entityConfig = $configManager->getProvider('extend')->getConfig($entity->getClassName());
     if ($entityConfig->get('owner') == ExtendScope::OWNER_SYSTEM) {
         return new Response('', Codes::HTTP_FORBIDDEN);
     }
     $entityConfig->set('state', class_exists($entity->getClassName()) ? ExtendScope::STATE_UPDATE : ExtendScope::STATE_NEW);
     $configManager->persist($entityConfig);
     $configManager->flush();
     return new JsonResponse(array('message' => 'Item was restored', 'successful' => true), Codes::HTTP_OK);
 }
コード例 #6
0
 /**
  * Return configured layout actions and requirejs modules
  *
  * @param  EntityConfigModel $entity
  * @return array
  */
 protected function getLayoutParams(EntityConfigModel $entity)
 {
     $configManager = $this->get('oro_entity_config.config_manager');
     $actions = [];
     $requireJsModules = [];
     foreach ($configManager->getProviders() as $provider) {
         $layoutActions = $provider->getPropertyConfig()->getLayoutActions(PropertyConfigContainer::TYPE_FIELD);
         foreach ($layoutActions as $config) {
             if (isset($config['filter'])) {
                 foreach ($config['filter'] as $key => $value) {
                     if (is_array($value)) {
                         $error = true;
                         foreach ($value as $v) {
                             if ($provider->getConfig($entity->getClassName())->get($key) == $v) {
                                 $error = false;
                             }
                         }
                         if ($error) {
                             continue 2;
                         }
                     } elseif ($provider->getConfig($entity->getClassName())->get($key) != $value) {
                         continue 2;
                     }
                 }
             }
             if (isset($config['entity_id']) && $config['entity_id'] == true) {
                 $config['args'] = ['id' => $entity->getId()];
             }
             $actions[] = $config;
         }
         $requireJsModules = array_merge($requireJsModules, $provider->getPropertyConfig(PropertyConfigContainer::TYPE_FIELD)->getRequireJsModules());
     }
     return [$actions, $requireJsModules];
 }
コード例 #7
0
 /**
  * @Route("/update/{id}", name="oro_entityextend_field_update", requirements={"id"="\d+"}, defaults={"id"=0})
  * Acl(
  *      id="oro_entityextend_field_update",
  *      label="Update custom field",
  *      type="action",
  *      group_name=""
  * )
  */
 public function updateAction(EntityConfigModel $entity)
 {
     $request = $this->getRequest();
     $fieldName = $request->getSession()->get(sprintf(self::SESSION_ID_FIELD_NAME, $entity->getId()));
     $fieldType = $request->getSession()->get(sprintf(self::SESSION_ID_FIELD_TYPE, $entity->getId()));
     if (!$fieldName || !$fieldType) {
         return $this->redirect($this->generateUrl('oro_entityextend_field_create', ['id' => $entity->getId()]));
     }
     /** @var ConfigManager $configManager */
     $configManager = $this->get('oro_entity_config.config_manager');
     $extendProvider = $configManager->getProvider('extend');
     $extendEntityConfig = $extendProvider->getConfig($entity->getClassName());
     $relationValues = [];
     $relationOptions = explode('||', $fieldType);
     $relationName = $relationOptions[0];
     if (isset($relationOptions[1])) {
         $fieldName = $relationOptions[1];
     }
     $relationOptions = explode('|', $relationOptions[0]);
     /**
      * fieldType example: relation|manyToOne|testentity5_relation_7
      * check if fieldType has 3rd option [fieldName]
      */
     if (count($relationOptions) == 4) {
         $fieldType = ExtendHelper::getReversRelationType($relationOptions[0]);
         $relations = $extendEntityConfig->get('relation');
         if (isset($relations[$relationName])) {
             $relationValues['target_entity'] = $relations[$relationName]['target_entity'];
             $relationValues['relation_key'] = $relationName;
         }
     }
     $newFieldModel = $configManager->createConfigFieldModel($entity->getClassName(), $fieldName, $fieldType);
     $extendFieldConfig = $extendProvider->getConfig($entity->getClassName(), $fieldName);
     $extendFieldConfig->set('owner', ExtendManager::OWNER_CUSTOM);
     $extendFieldConfig->set('state', ExtendManager::STATE_NEW);
     $extendFieldConfig->set('extend', true);
     foreach ($relationValues as $key => $value) {
         $extendFieldConfig->set($key, $value);
     }
     $form = $this->createForm('oro_entity_config_type', null, ['config_model' => $newFieldModel]);
     if ($request->getMethod() == 'POST') {
         $form->submit($request);
         if ($form->isValid()) {
             //persist data inside the form
             $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('oro.entity_extend.controller.config_field.message.saved'));
             if ($extendEntityConfig->get('state') != ExtendManager::STATE_NEW) {
                 $extendEntityConfig->set('state', ExtendManager::STATE_UPDATED);
             }
             $extendEntityConfig->set('upgradeable', true);
             $configManager->persist($extendEntityConfig);
             $configManager->flush();
             return $this->get('oro_ui.router')->actionRedirect(['route' => 'oro_entityconfig_field_update', 'parameters' => ['id' => $newFieldModel->getId()]], ['route' => 'oro_entityconfig_view', 'parameters' => ['id' => $entity->getId()]]);
         }
     }
     /** @var ConfigProvider $entityConfigProvider */
     $entityConfigProvider = $this->get('oro_entity_config.provider.entity');
     $entityConfig = $entityConfigProvider->getConfig($entity->getClassName());
     $fieldConfig = $entityConfigProvider->getConfig($entity->getClassName(), $newFieldModel->getFieldName());
     return $this->render('OroEntityConfigBundle:Config:fieldUpdate.html.twig', ['entity_config' => $entityConfig, 'field_config' => $fieldConfig, 'field' => $newFieldModel, 'form' => $form->createView(), 'formAction' => $this->generateUrl('oro_entityextend_field_update', array('id' => $entity->getId())), 'require_js' => $configManager->getProvider('extend')->getPropertyConfig()->getRequireJsModules()]);
 }
コード例 #8
0
ファイル: ConfigManager.php プロジェクト: nmallare/platform
 /**
  * Gets config id for the given model
  *
  * @param EntityConfigModel|FieldConfigModel $model
  * @param string                             $scope
  * @return ConfigIdInterface
  */
 public function getConfigIdByModel($model, $scope)
 {
     if ($model instanceof FieldConfigModel) {
         return new FieldConfigId($scope, $model->getEntity()->getClassName(), $model->getFieldName(), $model->getType());
     } else {
         return new EntityConfigId($scope, $model->getClassName());
     }
 }
コード例 #9
0
 /**
  * @Route("/update/{id}", name="oro_entityextend_field_update", requirements={"id"="\d+"}, defaults={"id"=0})
  * Acl(
  *      id="oro_entityextend_field_update",
  *      label="oro.entity_extend.action.config_field_grid.update",
  *      type="action",
  *      group_name=""
  * )
  */
 public function updateAction(EntityConfigModel $entity)
 {
     $request = $this->getRequest();
     $fieldName = $request->getSession()->get(sprintf(self::SESSION_ID_FIELD_NAME, $entity->getId()));
     $fieldType = $request->getSession()->get(sprintf(self::SESSION_ID_FIELD_TYPE, $entity->getId()));
     if (!$fieldName || !$fieldType) {
         return $this->redirect($this->generateUrl('oro_entityextend_field_create', ['id' => $entity->getId()]));
     }
     /** @var ConfigManager $configManager */
     $configManager = $this->get('oro_entity_config.config_manager');
     $extendProvider = $configManager->getProvider('extend');
     $extendEntityConfig = $extendProvider->getConfig($entity->getClassName());
     $fieldOptions = ['extend' => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM, 'state' => ExtendScope::STATE_NEW]];
     // check if a field type is complex, for example reverse relation or public enum
     $fieldTypeParts = explode('||', $fieldType);
     if (count($fieldTypeParts) > 1) {
         if (in_array($fieldTypeParts[0], ['enum', 'multiEnum'])) {
             // enum
             $fieldType = $fieldTypeParts[0];
             $fieldOptions['enum']['enum_code'] = $fieldTypeParts[1];
         } else {
             $firstPartItems = explode('|', $fieldTypeParts[0]);
             if (count($firstPartItems) === 4) {
                 // reverse relation
                 $fieldType = ExtendHelper::getReverseRelationType($firstPartItems[0]);
                 $relationKey = $fieldTypeParts[0];
                 $fieldOptions['extend']['relation_key'] = $relationKey;
                 $relations = $extendEntityConfig->get('relation');
                 $fieldOptions['extend']['target_entity'] = $relations[$relationKey]['target_entity'];
             }
         }
     }
     $newFieldModel = $configManager->createConfigFieldModel($entity->getClassName(), $fieldName, $fieldType);
     $this->updateFieldConfigs($configManager, $newFieldModel, $fieldOptions);
     $form = $this->createForm('oro_entity_config_type', null, ['config_model' => $newFieldModel]);
     if ($request->getMethod() == 'POST') {
         $form->submit($request);
         if ($form->isValid()) {
             //persist data inside the form
             $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('oro.entity_extend.controller.config_field.message.saved'));
             $extendEntityConfig->set('upgradeable', true);
             $configManager->persist($extendEntityConfig);
             $configManager->flush();
             return $this->get('oro_ui.router')->redirectAfterSave(['route' => 'oro_entityconfig_field_update', 'parameters' => ['id' => $newFieldModel->getId()]], ['route' => 'oro_entityconfig_view', 'parameters' => ['id' => $entity->getId()]]);
         }
     }
     /** @var ConfigProvider $entityConfigProvider */
     $entityConfigProvider = $this->get('oro_entity_config.provider.entity');
     $entityConfig = $entityConfigProvider->getConfig($entity->getClassName());
     $fieldConfig = $entityConfigProvider->getConfig($entity->getClassName(), $newFieldModel->getFieldName());
     return $this->render('OroEntityConfigBundle:Config:fieldUpdate.html.twig', ['entity_config' => $entityConfig, 'field_config' => $fieldConfig, 'field' => $newFieldModel, 'form' => $form->createView(), 'formAction' => $this->generateUrl('oro_entityextend_field_update', ['id' => $entity->getId()]), 'require_js' => $configManager->getProvider('extend')->getPropertyConfig()->getRequireJsModules()]);
 }
コード例 #10
0
ファイル: ConfigController.php プロジェクト: kstupak/platform
 /**
  * @param array             $action
  * @param EntityConfigModel $entity
  * @param ConfigProvider    $provider
  *
  * @return bool
  */
 protected function isLayoutActionApplicable(array $action, EntityConfigModel $entity, ConfigProvider $provider)
 {
     if (!isset($action['filter'])) {
         return true;
     }
     $result = true;
     foreach ($action['filter'] as $key => $value) {
         if ($key === 'mode') {
             if ($entity->getMode() !== $value) {
                 $result = false;
                 break;
             }
         } else {
             $config = $provider->getConfig($entity->getClassName());
             if (is_array($value)) {
                 if (!$config->in($key, $value)) {
                     $result = false;
                     break;
                 }
             } elseif ($config->get($key) != $value) {
                 $result = false;
                 break;
             }
         }
     }
     return $result;
 }
コード例 #11
0
 /**
  * @return string
  */
 public function getClassName()
 {
     return $this->configModel->getClassName();
 }