├── Resources ├── config │ ├── routing.yml │ └── services.yml ├── views │ ├── Setting │ │ ├── edit.html.twig │ │ ├── new.html.twig │ │ ├── show.html.twig │ │ └── index.html.twig │ └── Layout │ │ └── base.html.twig ├── translations │ └── FgConfigBundle.tr.yml └── meta │ └── LICENSE ├── FgConfigBundle.php ├── composer.json ├── DependencyInjection ├── FgConfigExtension.php └── Configuration.php ├── Repository └── SettingRepository.php ├── Service └── SettingService.php ├── Twig └── Extension │ └── ConfigTemplateExtension.php ├── Tests └── Controller │ └── SettingControllerTest.php ├── README.md ├── Form └── SettingType.php ├── Command └── SettingCommand.php ├── Entity └── Setting.php └── Controller └── SettingController.php /Resources/config/routing.yml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /FgConfigBundle.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | class FgConfigBundle extends Bundle 13 | { 14 | public function boot() 15 | { 16 | parent::boot(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Resources/views/Setting/edit.html.twig: -------------------------------------------------------------------------------- 1 | {% extends 'FgConfigBundle:Layout:base.html.twig' %} 2 | 3 | {% block body %} 4 |

{{ 'layout.setting_edit'|trans({}, 'FgConfigBundle') }}

5 | 6 | {{ form(edit_form) }} 7 | 8 | 16 | {% endblock %} 17 | -------------------------------------------------------------------------------- /Resources/views/Setting/new.html.twig: -------------------------------------------------------------------------------- 1 | {% extends 'FgConfigBundle:Layout:base.html.twig' %} 2 | 3 | {% block body %} 4 |

{{ 'layout.setting_creation' |trans({}, 'FgConfigBundle') }}

5 | 6 | {{ form_widget(form) }} 7 | 8 | 15 | {% endblock %} 16 | -------------------------------------------------------------------------------- /Resources/translations/FgConfigBundle.tr.yml: -------------------------------------------------------------------------------- 1 | layout: 2 | setting_id: "#Ayar No" 3 | setting_edit: "Ayar ver" 4 | setting_scope_group_type: "Grup kapsamı" 5 | setting_scope_by_id: "Grup belirleyici id" 6 | setting_section: "Bölüm" 7 | setting_name: "Ad" 8 | setting_value: "Değer" 9 | setting_created_at: "Oluşturulma tarihi" 10 | setting_updated_at: "Güncelleme tarihi" 11 | setting_creation: "Ayar Oluştur" 12 | setting_detail: "Ayar Detay" 13 | setting_list: "Ayar Listesi" 14 | actions: "İşlemler" 15 | edit: "Düzenle" 16 | show: "Detay" 17 | back_to_list: "Listeye geri dön" 18 | create_a_new_setting: "Yeni bir ayar ver" -------------------------------------------------------------------------------- /Resources/config/services.yml: -------------------------------------------------------------------------------- 1 | parameters: 2 | fg_config.service.setting_service.class: Fg\Bundle\ConfigBundle\Service\SettingService 3 | fg_config.twig.extension.config_template_extension.class: Fg\Bundle\ConfigBundle\Twig\Extension\ConfigTemplateExtension 4 | 5 | services: 6 | fg_config.service.setting_service: 7 | class: %fg_config.service.setting_service.class% 8 | arguments: 9 | - @doctrine.orm.entity_manager 10 | - 'FgConfigBundle:Setting' 11 | 12 | fg_config.twig.extension.config_template_extension: 13 | class: %fg_config.twig.extension.config_template_extension.class% 14 | arguments: 15 | - @fg_config.service.setting_service 16 | tags: 17 | - { name: twig.extension } -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fg/config-bundle", 3 | "type": "symfony-bundle", 4 | "description": "Settings from db", 5 | "keywords": ["symfony2", "setting", "config"], 6 | "license": "MIT License", 7 | "authors": [ 8 | { 9 | "name": "Fatih GÜRSOY", 10 | "email": "fatihgursoy@ymail.com" 11 | }, 12 | { 13 | "name": "Open Source Lovers", 14 | "homepage": "https://github.com/fg/FgConfigBundle/contributors" 15 | } 16 | ], 17 | "minimum-stability": "dev", 18 | "require": { 19 | "php": ">=5.3.2", 20 | "symfony/framework-bundle": "~2.3" 21 | }, 22 | "require-dev": { 23 | 24 | }, 25 | "autoload": { 26 | "psr-0": { 27 | "Fg\\ConfigBundle\\": "" 28 | } 29 | }, 30 | "target-dir": "Fg/ConfigBundle" 31 | } 32 | -------------------------------------------------------------------------------- /DependencyInjection/FgConfigExtension.php: -------------------------------------------------------------------------------- 1 | load('services.yml'); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /DependencyInjection/Configuration.php: -------------------------------------------------------------------------------- 1 | root('fg_config'); 22 | 23 | // Here you should define the parameters that are allowed to 24 | // configure your bundle. See the documentation linked above for 25 | // more information on that topic. 26 | 27 | return $treeBuilder; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Resources/meta/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2004-2015 Fatih GÜRSOY 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /Repository/SettingRepository.php: -------------------------------------------------------------------------------- 1 | _em->createQuery(" 16 | SELECT 17 | s 18 | FROM FgConfigBundle:Setting s 19 | WHERE s.name = :NAME AND s.scopeGroupType = :SCOPE_GROUP_TYPE AND s.section = :SECTION_NAME AND( 20 | (s.scopeById IS NOT NULL OR s.scopeById > 0) OR s.scopeById = :SCOPE_BY_ID 21 | ) 22 | "); 23 | 24 | $query 25 | ->setParameter(':NAME', $name) 26 | ->setParameter(':SCOPE_GROUP_TYPE', $scopeGroupType) 27 | ->setParameter(':SECTION_NAME', $section) 28 | ->setParameter(':SCOPE_BY_ID', $scopeById) 29 | ; 30 | 31 | return $query->getOneOrNullResult(); 32 | } 33 | } -------------------------------------------------------------------------------- /Service/SettingService.php: -------------------------------------------------------------------------------- 1 | entityManager = $entityManager; 29 | $this->repository = $this->entityManager->getRepository($entityName); 30 | } 31 | 32 | /** 33 | * Return setting collection from db 34 | * 35 | * @param $name 36 | * @param bool $scopeGroupType 37 | * @param bool $section 38 | * @param bool $scopeById 39 | * @return mixed 40 | */ 41 | public function getSettingByScope($name, $scopeGroupType = false, $section = false, $scopeById = false) 42 | { 43 | return $this->repository->getSettingByScope($name, $scopeGroupType, $section, $scopeById); 44 | } 45 | 46 | /** 47 | * @param $name 48 | * @param $value 49 | * @param $scopeGroupType 50 | * @param $section 51 | * @param int $scopeById 52 | * 53 | * @return Setting 54 | */ 55 | public function create($name, $value, $scopeGroupType, $section, $scopeById = 0) 56 | { 57 | $setting = new Setting(); 58 | $setting->setName($name); 59 | $setting->setValue($value); 60 | $setting->setSection($section); 61 | $setting->setScopeGroupType($scopeGroupType); 62 | $setting->setScopeById($scopeById); 63 | 64 | $this->entityManager->persist($setting); 65 | $this->entityManager->flush($setting); 66 | 67 | return $setting; 68 | } 69 | } -------------------------------------------------------------------------------- /Twig/Extension/ConfigTemplateExtension.php: -------------------------------------------------------------------------------- 1 | settingService = $settingService; 23 | } 24 | 25 | /** 26 | * @inheritdoc 27 | * 28 | * @return array 29 | */ 30 | public function getFunctions() { 31 | return array( 32 | 'get_setting' => new \Twig_Function_Method($this, 'getSetting'), 33 | 'get_setting_value' => new \Twig_Function_Method($this, 'getSettingValue') 34 | ); 35 | } 36 | 37 | /** 38 | * @param $name 39 | * @param bool $scopeGroupType 40 | * @param bool $section 41 | * @param bool $scopeById 42 | * @return mixed 43 | */ 44 | public function getSetting($name, $scopeGroupType = false, $section = false, $scopeById = false) 45 | { 46 | /** @var Setting $setting */ 47 | $setting = $this->settingService->getSettingByScope($name, $scopeGroupType, $section, $scopeById); 48 | 49 | return is_object($setting) ? $setting : null; 50 | } 51 | 52 | public function getSettingValue($name, $scopeGroupType = false, $section = false, $scopeById = false) 53 | { 54 | /** @var Setting $setting */ 55 | $setting = $this->settingService->getSettingByScope($name, $scopeGroupType, $section, $scopeById); 56 | 57 | return is_object($setting) ? $setting->getValue() : null; 58 | } 59 | 60 | 61 | /** 62 | * @inheritdoc 63 | * 64 | * @return string 65 | */ 66 | public function getName() 67 | { 68 | return 'fg_config_extension'; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Tests/Controller/SettingControllerTest.php: -------------------------------------------------------------------------------- 1 | request('GET', '/management/setting/'); 17 | $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Unexpected HTTP status code for GET /management/setting/"); 18 | $crawler = $client->click($crawler->selectLink('Create a new entry')->link()); 19 | 20 | // Fill in the form and submit it 21 | $form = $crawler->selectButton('Create')->form(array( 22 | 'fg_bundle_configbundle_setting[field_name]' => 'Test', 23 | // ... other fields to fill 24 | )); 25 | 26 | $client->submit($form); 27 | $crawler = $client->followRedirect(); 28 | 29 | // Check data in the show view 30 | $this->assertGreaterThan(0, $crawler->filter('td:contains("Test")')->count(), 'Missing element td:contains("Test")'); 31 | 32 | // Edit the entity 33 | $crawler = $client->click($crawler->selectLink('Edit')->link()); 34 | 35 | $form = $crawler->selectButton('Update')->form(array( 36 | 'fg_bundle_configbundle_setting[field_name]' => 'Foo', 37 | // ... other fields to fill 38 | )); 39 | 40 | $client->submit($form); 41 | $crawler = $client->followRedirect(); 42 | 43 | // Check the element contains an attribute with value equals "Foo" 44 | $this->assertGreaterThan(0, $crawler->filter('[value="Foo"]')->count(), 'Missing element [value="Foo"]'); 45 | 46 | // Delete the entity 47 | $client->submit($crawler->selectButton('Delete')->form()); 48 | $crawler = $client->followRedirect(); 49 | 50 | // Check the entity has been delete on the list 51 | $this->assertNotRegExp('/Foo/', $client->getResponse()->getContent()); 52 | } 53 | 54 | */ 55 | } 56 | -------------------------------------------------------------------------------- /Resources/views/Setting/show.html.twig: -------------------------------------------------------------------------------- 1 | {% extends 'FgConfigBundle:Layout:base.html.twig' %} 2 | 3 | {% block body %} 4 | 5 |
6 | 7 |

{{ 'layout.setting_detail'|trans({}, 'FgConfigBundle') }}

8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |
{{ 'layout.setting_id'|trans({}, 'FgConfigBundle') }}{{ entity.id }}
{{ 'layout.setting_scope_group_type'|trans({}, 'FgConfigBundle') }}{{ entity.scopeGroupType }}
{{ 'layout.setting_scope_by_id'|trans({}, 'FgConfigBundle') }}{{ entity.scopeById }}
{{ 'layout.setting_section'|trans({}, 'FgConfigBundle') }}{{ entity.section }}
{{ 'layout.setting_name'|trans({}, 'FgConfigBundle') }}{{ entity.name }}
{{ 'layout.setting_value'|trans({}, 'FgConfigBundle') }}{{ entity.value }}
{{ 'layout.setting_created_at'|trans({}, 'FgConfigBundle') }}{{ entity.createdAt|date('Y-m-d H:i:s') }}
{{ 'layout.setting_updated_at'|trans({}, 'FgConfigBundle') }}{{ entity.updatedAt|date('Y-m-d H:i:s') }}
45 | 46 | 59 |
60 | {% endblock %} 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | FgConfigBundle 2 | -------- 3 | 4 | This bundle helps you to store your settings for application layer. This settings are stored based on scope such as general, user groups, user and can be accessedfrom any layer later. 5 | 6 | An example: 7 | 8 | Let say we have 30 quota available for Math class: 9 | 10 | ```json 11 | { 12 | "id": 1, 13 | "scope_group_type": "labs", 14 | "scope_by_id": 2, 15 | "section": "registration", 16 | "name": "quota", 17 | "value": 30, 18 | "created_at" : "2015-08-13 00:00:00", 19 | "updated_at" : "2015-08-13 00:00:00" 20 | } 21 | ``` 22 | 23 | 1. Installation 24 | ------------ 25 | #### 1.1 Install Repository 26 | You can install via [composer](http://getcomposer.org/download/). 27 | 28 | ```sh 29 | composer require fg/config-bundle 30 | ``` 31 | 32 | or add to require section of `composer.json:` 33 | 34 | ```json 35 | "fg/config-bundle": "dev-master" 36 | ``` 37 | 38 | #### 1.2 Enable Bundle in app/AppKernel.php 39 | 40 | ```php 41 | public function registerBundles() { 42 | $bundles = array( 43 | // ... 44 | new Fg\Bundle\ConfigBundle\FgConfigBundle() 45 | ); 46 | // ... 47 | } 48 | ``` 49 | 50 | #### 1.3 Run migration 51 | 52 | ```sh 53 | php app/console doctrine:schema:update --force 54 | ``` 55 | 56 | 2. Usage 57 | ------------ 58 | ### 2.1 Creating a ne setting 59 | There are three different ways to create a new setting. 60 | 61 | #### 2.1.1 By using Command Line Interface (CLI) 62 | You can create a new setting by runnig `php app/console fg:config:create` command from cli. 63 | 64 | #### 2.1.2 By calling create method of SettingService 65 | You can create a new setting by calling the create method of `SettingService` which previously passed to service container. 66 | 67 | ```php 68 | $settingService = $this->get('fg_config.service.setting_service'); 69 | #create($name, $value, $scopeGroupType, $section, $scopeById = 0) 70 | $setting = $settingService->create('test', 'test', 'general', 'general') 71 | ``` 72 | 73 | #### 2.1.3 By using web user interface 74 | `http://localhost/path/to/management/setting` 75 | 76 | 77 | ### 2.2 Accessing 78 | 79 | #### 2.2.1 Accessing from controller layer 80 | 81 | ```php 82 | ... 83 | $settingService = $this->get('fg_config.service.setting_service'); 84 | $settingObject = $settingService->getAllSettingByScope('quota', 'labs', 'registration', 2); 85 | ... 86 | ``` 87 | 88 | #### 2.2.2 Accessing from Twig 89 | 90 | ```twig 91 | ... 92 | {{ get_setting('phone') }} //get setting object of name phone 93 | {{ get_setting_value('phone') }} //get value of name phone 94 | ... 95 | ``` 96 | -------------------------------------------------------------------------------- /Form/SettingType.php: -------------------------------------------------------------------------------- 1 | add('scopeGroupType', null, 19 | array( 20 | 'label' => 'layout.setting_scope_group_type', 21 | 'translation_domain' => 'FgConfigBundle' 22 | ) 23 | ) 24 | ->add('scopeById', null, 25 | array( 26 | 'label' => 'layout.setting_scope_by_id', 27 | 'translation_domain' => 'FgConfigBundle' 28 | ) 29 | ) 30 | ->add('section', null, 31 | array( 32 | 'label' => 'layout.setting_section', 33 | 'translation_domain' => 'FgConfigBundle' 34 | ) 35 | ) 36 | ->add('name', null, 37 | array( 38 | 'label' => 'layout.setting_name', 39 | 'translation_domain' => 'FgConfigBundle' 40 | ) 41 | ) 42 | ->add('value', null, 43 | array( 44 | 'label' => 'layout.setting_value', 45 | 'translation_domain' => 'FgConfigBundle' 46 | ) 47 | ) 48 | ->add('createdAt', null, 49 | array( 50 | 'label' => 'layout.setting_created_at', 51 | 'translation_domain' => 'FgConfigBundle' 52 | ) 53 | ) 54 | ->add('updatedAt', null, 55 | array( 56 | 'label' => 'layout.setting_updated_at', 57 | 'translation_domain' => 'FgConfigBundle' 58 | ) 59 | ) 60 | ; 61 | } 62 | 63 | /** 64 | * @param OptionsResolverInterface $resolver 65 | */ 66 | public function setDefaultOptions(OptionsResolverInterface $resolver) 67 | { 68 | $resolver->setDefaults(array( 69 | 'data_class' => 'Fg\Bundle\ConfigBundle\Entity\Setting' 70 | )); 71 | } 72 | 73 | /** 74 | * @return string 75 | */ 76 | public function getName() 77 | { 78 | return 'fg_bundle_configbundle_setting'; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Resources/views/Setting/index.html.twig: -------------------------------------------------------------------------------- 1 | {% extends 'FgConfigBundle:Layout:base.html.twig' %} 2 | 3 | {% block body %} 4 |
5 |

{{ 'layout.setting_list'|trans({}, 'FgConfigBundle') }}

6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | {% for entity in entities %} 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 42 | 43 | {% endfor %} 44 | 45 |
{{ 'layout.setting_id'|trans({}, 'FgConfigBundle') }}{{ 'layout.setting_scope_group_type'|trans({}, 'FgConfigBundle') }}{{ 'layout.setting_scope_by_id'|trans({}, 'FgConfigBundle') }}{{ 'layout.setting_section'|trans({}, 'FgConfigBundle') }}{{ 'layout.setting_name'|trans({}, 'FgConfigBundle') }}{{ 'layout.setting_value'|trans({}, 'FgConfigBundle') }}{{ 'layout.setting_created_at'|trans({}, 'FgConfigBundle') }}{{ 'layout.setting_updated_at'|trans({}, 'FgConfigBundle') }}{{ 'layout.actions'|trans({}, 'FgConfigBundle') }}
{{ entity.id }}{{ entity.scopeGroupType }}{{ entity.scopeById }}{{ entity.section }}{{ entity.name }}{{ entity.value }}{% if entity.createdAt %}{{ entity.createdAt|date('Y-m-d H:i:s') }}{% endif %}{% if entity.updatedAt %}{{ entity.updatedAt|date('Y-m-d H:i:s') }}{% endif %} 33 | 41 |
46 | 47 | 54 |
55 | {% endblock %} 56 | -------------------------------------------------------------------------------- /Resources/views/Layout/base.html.twig: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {% block title %}Welcome!{% endblock %} 6 | {% block stylesheets %}{% endblock %} 7 | 8 | 9 | 10 | 11 | 12 | 40 | 41 | 42 |
43 |
44 | {% block body %} 45 | 46 | {% endblock %} 47 |
48 |
49 | 50 | {% block javascripts %} 51 | 52 | 53 | 54 | Fork me on GitHub 55 | {% endblock %} 56 | 57 | 58 | -------------------------------------------------------------------------------- /Command/SettingCommand.php: -------------------------------------------------------------------------------- 1 | setName('fg:config:create') 15 | ->setDescription('Create a setting.') 16 | ->setDefinition( 17 | array( 18 | new InputArgument('scope_group_type', InputArgument::REQUIRED, 'Scope Group Type'), 19 | new InputArgument('section', InputArgument::REQUIRED, 'Scope By Id'), 20 | new InputArgument('name', InputArgument::REQUIRED, 'Name'), 21 | new InputArgument('value', InputArgument::REQUIRED, 'Value'), 22 | new InputArgument('scope_by_id', InputArgument::OPTIONAL, 'Scope By Id'), 23 | ) 24 | ); 25 | } 26 | 27 | protected function execute(InputInterface $input, OutputInterface $output) 28 | { 29 | $scope_group_type = $input->getArgument('scope_group_type'); 30 | $scope_by_id = intval($input->getArgument('scope_by_id')); 31 | $section = $input->getArgument('section'); 32 | $name = $input->getArgument('name'); 33 | $value = $input->getArgument('value'); 34 | 35 | /** @var SettingService $settingService */ 36 | $settingService = $this->getContainer()->get('fg_config.service.setting_service'); 37 | $settingService->create($name, $value, $scope_group_type, $section, $scope_by_id); 38 | 39 | $output->writeln(sprintf('Created setting %s', $name)); 40 | } 41 | 42 | 43 | protected function interact(InputInterface $input, OutputInterface $output) 44 | { 45 | if (!$input->getArgument('scope_group_type')) { 46 | $scope_group_type = $this->getHelper('dialog')->askAndValidate( 47 | $output, 48 | 'Please choose scope group type: ', 49 | function($scope_group_type) { 50 | if (empty($scope_group_type)) { 51 | throw new \Exception('Scope group type can not be empty, please use "general"'); 52 | } 53 | return $scope_group_type; 54 | } 55 | ); 56 | $input->setArgument('scope_group_type', $scope_group_type); 57 | } 58 | 59 | if (!$input->getArgument('scope_by_id')) { 60 | $scope_by_id = $this->getHelper('dialog')->askAndValidate( 61 | $output, 62 | 'Scope group id (default:0): ', 63 | function($scope_by_id) { 64 | return $scope_by_id; 65 | } 66 | ); 67 | $input->setArgument('scope_by_id', $scope_by_id); 68 | } 69 | 70 | if (!$input->getArgument('section')) { 71 | $section = $this->getHelper('dialog')->askAndValidate( 72 | $output, 73 | 'Please choose setting of section: ', 74 | function($section) { 75 | if (empty($section)) { 76 | throw new \Exception('Section can not be empty, please use "general"'); 77 | } 78 | return $section; 79 | } 80 | ); 81 | $input->setArgument('section', $section); 82 | } 83 | 84 | if (!$input->getArgument('name')) { 85 | $name = $this->getHelper('dialog')->askAndValidate( 86 | $output, 87 | 'Please choose setting of name: ', 88 | function($name) { 89 | if (empty($name)) { 90 | throw new \Exception('Name can not be empty!'); 91 | } 92 | return $name; 93 | } 94 | ); 95 | $input->setArgument('name', $name); 96 | } 97 | 98 | if (!$input->getArgument('value')) { 99 | $value = $this->getHelper('dialog')->askAndValidate( 100 | $output, 101 | 'Please choose setting of value: ', 102 | function($value) { 103 | if (empty($value)) { 104 | throw new \Exception('Value can not be empty!'); 105 | } 106 | return $value; 107 | } 108 | ); 109 | $input->setArgument('value', $value); 110 | } 111 | 112 | } 113 | } -------------------------------------------------------------------------------- /Entity/Setting.php: -------------------------------------------------------------------------------- 1 | createdAt = new \DateTime(); 87 | $this->updatedAt = new \DateTime(); 88 | } 89 | 90 | /** 91 | * @ORM\PreUpdate() 92 | */ 93 | public function preUpdate() { 94 | $this->updatedAt= new \DateTime(); 95 | } 96 | 97 | /** 98 | * @return int 99 | */ 100 | public function getId() 101 | { 102 | return $this->id; 103 | } 104 | 105 | /** 106 | * @return string 107 | */ 108 | public function getScopeGroupType() 109 | { 110 | return $this->scopeGroupType; 111 | } 112 | 113 | /** 114 | * @param string $scopeGroupType 115 | */ 116 | public function setScopeGroupType($scopeGroupType) 117 | { 118 | $this->scopeGroupType = $scopeGroupType; 119 | } 120 | 121 | /** 122 | * @return string 123 | */ 124 | public function getScopeById() 125 | { 126 | return $this->scopeById; 127 | } 128 | 129 | /** 130 | * @param string $scopeById 131 | */ 132 | public function setScopeById($scopeById) 133 | { 134 | $this->scopeById = $scopeById; 135 | } 136 | 137 | /** 138 | * @return string 139 | */ 140 | public function getSection() 141 | { 142 | return $this->section; 143 | } 144 | 145 | /** 146 | * @param string $section 147 | */ 148 | public function setSection($section) 149 | { 150 | $this->section = $section; 151 | } 152 | 153 | /** 154 | * @return string 155 | */ 156 | public function getName() 157 | { 158 | return $this->name; 159 | } 160 | 161 | /** 162 | * @param string $name 163 | */ 164 | public function setName($name) 165 | { 166 | $this->name = $name; 167 | } 168 | 169 | /** 170 | * @return string 171 | */ 172 | public function getValue() 173 | { 174 | return $this->value; 175 | } 176 | 177 | /** 178 | * @param string $value 179 | */ 180 | public function setValue($value) 181 | { 182 | $this->value = $value; 183 | } 184 | 185 | /** 186 | * @return \DateTime 187 | */ 188 | public function getCreatedAt() 189 | { 190 | return $this->createdAt; 191 | } 192 | 193 | /** 194 | * @param \DateTime $createdAt 195 | */ 196 | public function setCreatedAt($createdAt) 197 | { 198 | $this->createdAt = $createdAt; 199 | } 200 | 201 | /** 202 | * @return \DateTime 203 | */ 204 | public function getUpdatedAt() 205 | { 206 | return $this->updatedAt; 207 | } 208 | 209 | /** 210 | * @param \DateTime $updatedAt 211 | */ 212 | public function setUpdatedAt($updatedAt) 213 | { 214 | $this->updatedAt = $updatedAt; 215 | } 216 | } 217 | -------------------------------------------------------------------------------- /Controller/SettingController.php: -------------------------------------------------------------------------------- 1 | getDoctrine()->getManager(); 31 | 32 | $entities = $em->getRepository('FgConfigBundle:Setting')->findAll(); 33 | 34 | return array( 35 | 'entities' => $entities, 36 | ); 37 | } 38 | /** 39 | * Creates a new Setting entity. 40 | * 41 | * @Route("/", name="management_setting_create") 42 | * @Method("POST") 43 | * @Template("FgConfigBundle:Setting:new.html.twig") 44 | */ 45 | public function createAction(Request $request) 46 | { 47 | $entity = new Setting(); 48 | $form = $this->createCreateForm($entity); 49 | $form->handleRequest($request); 50 | 51 | if ($form->isValid()) { 52 | $em = $this->getDoctrine()->getManager(); 53 | $em->persist($entity); 54 | $em->flush(); 55 | 56 | return $this->redirect($this->generateUrl('management_setting_show', array('id' => $entity->getId()))); 57 | } 58 | 59 | return array( 60 | 'entity' => $entity, 61 | 'form' => $form->createView(), 62 | ); 63 | } 64 | 65 | /** 66 | * Creates a form to create a Setting entity. 67 | * 68 | * @param Setting $entity The entity 69 | * 70 | * @return \Symfony\Component\Form\Form The form 71 | */ 72 | private function createCreateForm(Setting $entity) 73 | { 74 | $form = $this->createForm(new SettingType(), $entity, array( 75 | 'action' => $this->generateUrl('management_setting_create'), 76 | 'method' => 'POST', 77 | )); 78 | 79 | $form->add('submit', 'submit', array('label' => 'Create')); 80 | 81 | return $form; 82 | } 83 | 84 | /** 85 | * Displays a form to create a new Setting entity. 86 | * 87 | * @Route("/new", name="management_setting_new") 88 | * @Method("GET") 89 | * @Template() 90 | */ 91 | public function newAction() 92 | { 93 | $entity = new Setting(); 94 | $form = $this->createCreateForm($entity); 95 | 96 | return array( 97 | 'entity' => $entity, 98 | 'form' => $form->createView(), 99 | ); 100 | } 101 | 102 | /** 103 | * Finds and displays a Setting entity. 104 | * 105 | * @Route("/{id}", name="management_setting_show") 106 | * @Method("GET") 107 | * @Template() 108 | */ 109 | public function showAction($id) 110 | { 111 | $em = $this->getDoctrine()->getManager(); 112 | 113 | $entity = $em->getRepository('FgConfigBundle:Setting')->find($id); 114 | 115 | if (!$entity) { 116 | throw $this->createNotFoundException('Unable to find Setting entity.'); 117 | } 118 | 119 | $deleteForm = $this->createDeleteForm($id); 120 | 121 | return array( 122 | 'entity' => $entity, 123 | 'delete_form' => $deleteForm->createView(), 124 | ); 125 | } 126 | 127 | /** 128 | * Displays a form to edit an existing Setting entity. 129 | * 130 | * @Route("/{id}/edit", name="management_setting_edit") 131 | * @Method("GET") 132 | * @Template() 133 | */ 134 | public function editAction($id) 135 | { 136 | $em = $this->getDoctrine()->getManager(); 137 | 138 | $entity = $em->getRepository('FgConfigBundle:Setting')->find($id); 139 | 140 | if (!$entity) { 141 | throw $this->createNotFoundException('Unable to find Setting entity.'); 142 | } 143 | 144 | $editForm = $this->createEditForm($entity); 145 | $deleteForm = $this->createDeleteForm($id); 146 | 147 | return array( 148 | 'entity' => $entity, 149 | 'edit_form' => $editForm->createView(), 150 | 'delete_form' => $deleteForm->createView(), 151 | ); 152 | } 153 | 154 | /** 155 | * Creates a form to edit a Setting entity. 156 | * 157 | * @param Setting $entity The entity 158 | * 159 | * @return \Symfony\Component\Form\Form The form 160 | */ 161 | private function createEditForm(Setting $entity) 162 | { 163 | $form = $this->createForm(new SettingType(), $entity, array( 164 | 'action' => $this->generateUrl('management_setting_update', array('id' => $entity->getId())), 165 | 'method' => 'PUT', 166 | )); 167 | 168 | $form->add('submit', 'submit', array('label' => 'Update')); 169 | 170 | return $form; 171 | } 172 | /** 173 | * Edits an existing Setting entity. 174 | * 175 | * @Route("/{id}", name="management_setting_update") 176 | * @Method("PUT") 177 | * @Template("FgConfigBundle:Setting:edit.html.twig") 178 | */ 179 | public function updateAction(Request $request, $id) 180 | { 181 | $em = $this->getDoctrine()->getManager(); 182 | 183 | $entity = $em->getRepository('FgConfigBundle:Setting')->find($id); 184 | 185 | if (!$entity) { 186 | throw $this->createNotFoundException('Unable to find Setting entity.'); 187 | } 188 | 189 | $deleteForm = $this->createDeleteForm($id); 190 | $editForm = $this->createEditForm($entity); 191 | $editForm->handleRequest($request); 192 | 193 | if ($editForm->isValid()) { 194 | $em->flush(); 195 | 196 | return $this->redirect($this->generateUrl('management_setting_edit', array('id' => $id))); 197 | } 198 | 199 | return array( 200 | 'entity' => $entity, 201 | 'edit_form' => $editForm->createView(), 202 | 'delete_form' => $deleteForm->createView(), 203 | ); 204 | } 205 | /** 206 | * Deletes a Setting entity. 207 | * 208 | * @Route("/{id}", name="management_setting_delete") 209 | * @Method("DELETE") 210 | */ 211 | public function deleteAction(Request $request, $id) 212 | { 213 | $form = $this->createDeleteForm($id); 214 | $form->handleRequest($request); 215 | 216 | if ($form->isValid()) { 217 | $em = $this->getDoctrine()->getManager(); 218 | $entity = $em->getRepository('FgConfigBundle:Setting')->find($id); 219 | 220 | if (!$entity) { 221 | throw $this->createNotFoundException('Unable to find Setting entity.'); 222 | } 223 | 224 | $em->remove($entity); 225 | $em->flush(); 226 | } 227 | 228 | return $this->redirect($this->generateUrl('management_setting')); 229 | } 230 | 231 | /** 232 | * Creates a form to delete a Setting entity by id. 233 | * 234 | * @param mixed $id The entity id 235 | * 236 | * @return \Symfony\Component\Form\Form The form 237 | */ 238 | private function createDeleteForm($id) 239 | { 240 | return $this->createFormBuilder() 241 | ->setAction($this->generateUrl('management_setting_delete', array('id' => $id))) 242 | ->setMethod('DELETE') 243 | ->add('submit', 'submit', array('label' => 'Delete')) 244 | ->getForm() 245 | ; 246 | } 247 | } 248 | --------------------------------------------------------------------------------