Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Commit

Permalink
Documentation + minor bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hugo082 committed May 17, 2017
1 parent 9f23818 commit cb01ada
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 170 deletions.
6 changes: 0 additions & 6 deletions Controller/ManageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public function indexAction(Request $request)
}

public function processAction(Request $request, $actionID, $name, $id) {

/** @var $viewManager ViewManager */
$viewManager = $this->get('fqt.db.manager.view.manager');
$execution = $viewManager->processAction($request, $actionID, $name, $id);
Expand All @@ -49,11 +48,6 @@ public function processAction(Request $request, $actionID, $name, $id) {
if ($execution->getRedirection() != null)
return $this->redirectToRoute($execution->getRedirection()["route_name"], $execution->getRedirection()["data"]);


/** @var View $v */
foreach ($execution->views as $v)
echo $v->getAction()->id . " - " . $v->getViewMeta()->getView() . " <br> ";

return $this->render($viewManager->getTemplate(false), array(
'name' => $name,
'views' => $execution->views,
Expand Down
195 changes: 33 additions & 162 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@

# Database Manager Web Interface

DBManager (DBM) is a web interface generator that help you to implement a database manager on your website.
DBManager (DBM) is a web interface generator that help you to implement a database manager on your website.
It's an implementation of FQTDBCoreManager with web interface.

Features include:
* Action control on entity
* Add
* Edit
* Remove
* Personalize interface
For more information about FQTDBCoreManager, see her [documentation](https://github.com/hugo082/FQTDBCoreManagerBundle)

`v1.5` `25 FEV 17`
`v2.0` `17 MAI 17`

## Installation

### Step 1: Composer requirement
### Step 1: Install FQTDBCoreManager

For more information about FQTDBCoreManager, see her [documentation](https://github.com/hugo082/FQTDBCoreManagerBundle)

### Step 2: Composer requirement

Add repositories to your `composer.json`

"repositories" : [
{
"type" : "vcs",
"url" : "https://github.com/.../....git",
"url" : "https://github.com/hugo082/DBManagerBundle.git",
"no-api": true
}
]

Add requirement :

"require": {
"hello/worldbundle": "*",
"db/managerbundle": "2.*",
//...
},

Update your requirements with `composer update` command.

### Step 2: Bundle configuration
### Step 3: Bundle configuration

Enable the bundle in the kernel :

Expand All @@ -59,9 +59,6 @@ Update your `routing.yml` :
Set up your `config.yml` :

db_manager:
entities:
DisplayName:
fullName: YourBundle:RealName

## About

Expand All @@ -74,160 +71,34 @@ This bundle is under the MIT license. See the complete license [in the bundle](L

## Documentation

### Add an entity

DBM load your entities with your configuration file. You can specify an entity to follow by adding it in your config.yml

db_manager:
entities:
DisplayName:
fullName: YourBundle:RealName

You can configure different actions on each entity :

DisplayName:
fullName: YourBundle:RealName
listView: myFile_1.html.twig # Optional
formView: myFile_2.html.twig # Optional
mainView: myFile_3.html.twig # Optional
fullPath: YourBundle\Entity\Airport # Optional
formType: AirportEditType # Optional
fullFormType: AnotherBundle\Form\AirportEditType # Optional
ppermissions: [ "edit" ] # Optional - add | edit | remove | list

By default, DBM load your entity in `YourBundle\Entity\RealName`, name the form with `RealNameType` and load your form type in
`YourBundle\Form\formType` (so `YourBundle\Form\RealNameType`)
- `DisplayName` is used by DBM for display on template and in url, you can enter the same name of RealName.
- `permissions` is by default full authorized. This parameter is optional but recommended.
- You can call your custom views :
- `listView` is the view that list the entity.
- `formView` is the view that display the form
- `mainView` is the view that call `listview` and `formview`.

<span style="color:#FFC107">**WARNING** :</span> if you do not override views, your entity must be compatible with default views.
To do that, you can extends your entity with `DB\ManagerBundle\Model\BaseManager` class. This abstract class implement necessary methods.<br>
If your entity is already extended, you can also implements all necessary interface :
- DB\ManagerBundle\Model\ListingInterface

### Configure views

You can configure your views by adding the `views` keyword in your configuration file.

db_manager:
views: ~

By default, DBM insert the add form in listing view and list in edit view. But if you want to separate all views, you can
set the options to `false`.

db_manager:
views:
indexView: index.html.twig
list:
form: false
edit:
list: false

If you do not specify an argument, the argument takes its default value (`true`)
You can also specify your custom index view with the option `indexView`.

### Entity access

#### Role access

You can setup for each entity roles that are necessary to execute specific action or access to a specific information.<br>
For example, if you want that the entity is accessible only to admin users, you can specify the `access` config

DisplayName:
access: ROLE_ADMIN
#...

You can also defined multi-roles :
### Override templates

DisplayName:
access: [ ROLE_ADMIN, ROLE_REDACTOR ]
#...
DBM use 2 templates (`index` and `main`). Index view is the view that list all your entity and index view execute action on your entity.
You can override this template with `templates` argument in your configuration file.

If you want that users can list and so access to entity information but admins can execute actions on this entity, you
you can defined the parameter `access_details`. This parameter **must** defined roles for all actions :
templates:
index_view: MyBundle:PathTo:MyView.html.twig

Flight:
access_details:
add: ROLE_SUPER_ADMIN
edit: [ ROLE_ADMIN, ROLE_REDACTOR ]
remove: ROLE_SUPER_ADMIN
list: ROLE_USER
### Views configuration

<span style="color:#FFC107">**WARNING** :</span> if you defined the access_details property, this parameter override access
and so access is no longer taken into consideration.<br>
<span style="color:#FFC107">**WARNING** :</span> if list action isn't accessible for a user, this user don't have access to
`.../DisplayName` url, so it can't access to add path/form. Moreover, if it can't list entity, it can't click on links
to remove or edit, but, the link is accessible.<br>
<span style="color:#FFC107">**WARNING** :</span> if FOSUserBundle does not installed or enabled, `access` and `access_details`
parameters will be ignored.
Each action can have a specific view. To do this, you can define `views` property in your configuration file.

views:
- { action: myAction1, default_view: list, container: [] }
— { action: myAction2, custom_view: MyBundle:PathTo:MyView.html.twig, container: [ add ]}

#### Custom constraints
For each view, you can define :
- template : the template is load with `default_view` or `custom_view` argument. `default_view` can be `form` or `list`
and load default template.
- container : `container` is an array that contains all actions that the main action `action` contain in her view.

You can implement an actionMethod to process a custom constraint. Your method will call for each entity and must return
a boolean (`true` to allow access and `false` to prevent).
### Links configuration

access_details:
add: ROLE_USER
addMethod: AppBundle\Entity\Flight::checkAdd
#...
Each action can have links that will be inserted into its view. To do this, you can define `links` property in your configuration file.
The approach to the links is very similar to the views

Your method must a static method and take in parameters user and entity object. For the addMethod, entity object is NULL.

public static function checkAdd(User $user, Flight $obj = NULL) {
return $user->isUnabled();
}

When DBM list your entity, you can also choose your method repository. By default, DBManager use `findAll()` but you can
override this easily :

Flight:
fullName: AppBundle:Flight
listingMethod: myRepositoryMethod


#### Events

For add, edit and remove actions, events are called. You can listen them and execute a custom process :

namespace AppBundle\EventListener;

use AppBundle\Entity\Flight;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Doctrine\ORM\EntityManager;
use DB\ManagerBundle\DBManagerEvents;
use DB\ManagerBundle\Event\ActionEvent;

class ActionSubscriber implements EventSubscriberInterface {
private $em;

public function __construct(EntityManager $em) {
$this->em = $em;
}

public static function getSubscribedEvents() {
return array(
DBManagerEvents::ACTION_REMOVE_BEFORE => 'beforeRemove',
//..
);
}

public function beforeRemove(ActionEvent $event) {
$e = $event->getEntityObject();
if ($e instanceof Flight) {
if ($e->getId() == 13) {
$event->setExecuted(true); // DBM default action ignored
$event->setFlash('ERROR', 'You want remove VIP Flight');
} else
$event->setFlash('SUCCESS', 'Your Flight have been removed');
}
}
}
links:
- { action: myAction1, container: [] }
— { action: myAction2, container: [ add ]}

At the end of your process, if `executed` property of event are set to true, DBM will ignore the default action. By default,
the `executed` property is set to false.<br>
Of course you must register your subscriber in your services.
An action can be linked only if it's a `global` action. See [FQTDBCoreManagerBundle](https://github.com/hugo082/FQTDBCoreManagerBundle)
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
"Database manager", "Web interface manager"
],
"require" : {
"php" : ">=5.6.0",
"php" : ">=7.0.0",
"symfony/framework-bundle" : ">=3.0",
"twig/twig" : "*",
"doctrine/doctrine-bundle" : "*"
"doctrine/doctrine-bundle" : "*",
"fqt/db-core-managerbundle" : "1.*"
},
"autoload" : {
"psr-0" : {
Expand Down

0 comments on commit cb01ada

Please sign in to comment.