mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-14 06:14:23 +00:00
Adding CustomFieldsDefaultGroup Entity for specifying that a group is a default group ref #307
This commit is contained in:
parent
ce0db40129
commit
f702d76e68
77
Controller/CustomFieldsDefaultGroupController.php
Normal file
77
Controller/CustomFieldsDefaultGroupController.php
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\CustomFieldsBundle\Controller;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
|
|
||||||
|
use Chill\CustomFieldsBundle\Entity\CustomFieldsDefaultGroup;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CustomFieldsDefaultGroup controller.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class CustomFieldsDefaultGroupController extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists all CustomFieldsDefaultGroup entities.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function listAction()
|
||||||
|
{
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
|
$defaultGroups = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsDefaultGroup')->findAll();
|
||||||
|
|
||||||
|
$form = $this->get('form.factory')
|
||||||
|
->createNamedBuilder(null, 'form', null, array(
|
||||||
|
'method' => 'GET',
|
||||||
|
'action' => $this->generateUrl('customfieldsdefaultgroup_set'),
|
||||||
|
'csrf_protection' => false
|
||||||
|
))
|
||||||
|
->add('cFGroup', 'entity', array(
|
||||||
|
'class' => 'ChillCustomFieldsBundle:CustomFieldsGroup',
|
||||||
|
'property' => 'name[fr]'
|
||||||
|
))
|
||||||
|
->getForm();
|
||||||
|
|
||||||
|
return $this->render('ChillCustomFieldsBundle:CustomFieldsDefaultGroup:list.html.twig', array(
|
||||||
|
'defaultGroups' => $defaultGroups,
|
||||||
|
'form' => $form->createView()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the CustomField Group with id $cFGroupId as default
|
||||||
|
*/
|
||||||
|
public function setAGroupAsDefaultAction(Request $request)
|
||||||
|
{
|
||||||
|
$cFGroupId = $request->query->get('cFGroup');
|
||||||
|
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
|
$cFGroup = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')->findOneById($cFGroupId);
|
||||||
|
|
||||||
|
if(!$cFGroup) {
|
||||||
|
throw new Exception("No CF GROUP with ID".$cFGroupId, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$cFDefaultGroup = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsDefaultGroup')
|
||||||
|
->findOneByEntity($cFGroup->getEntity());
|
||||||
|
|
||||||
|
if($cFDefaultGroup) {
|
||||||
|
$em->remove($cFDefaultGroup);
|
||||||
|
$em->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
$newCFDefaultGroup = new CustomFieldsDefaultGroup();
|
||||||
|
$newCFDefaultGroup->setCustomFieldsGroup($cFGroup);
|
||||||
|
$newCFDefaultGroup->setEntity($cFGroup->getEntity());
|
||||||
|
|
||||||
|
$em->persist($newCFDefaultGroup);
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
return $this->redirect($this->generateUrl('customfieldsdefaultgroup'));
|
||||||
|
}
|
||||||
|
}
|
101
Entity/CustomFieldsDefaultGroup.php
Normal file
101
Entity/CustomFieldsDefaultGroup.php
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Chill\CustomFieldsBundle\Entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CustomFieldsDefaultGroup
|
||||||
|
*/
|
||||||
|
class CustomFieldsDefaultGroup
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var integer
|
||||||
|
*/
|
||||||
|
private $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var CustomFieldsGroup
|
||||||
|
*/
|
||||||
|
private $customFieldsGroup;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get id
|
||||||
|
*
|
||||||
|
* @return integer
|
||||||
|
*/
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set entity
|
||||||
|
*
|
||||||
|
* @param string $entity
|
||||||
|
*
|
||||||
|
* @return CustomFieldsDefaultGroup
|
||||||
|
*/
|
||||||
|
public function setEntity($entity)
|
||||||
|
{
|
||||||
|
$this->entity = $entity;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get entity
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getEntity()
|
||||||
|
{
|
||||||
|
return $this->entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set customFieldsGroup
|
||||||
|
*
|
||||||
|
* @param CustomFieldsGroup $customFieldsGroup
|
||||||
|
*
|
||||||
|
* @return CustomFieldsDefaultGroup
|
||||||
|
*/
|
||||||
|
public function setCustomFieldsGroup($customFieldsGroup)
|
||||||
|
{
|
||||||
|
$this->customFieldsGroup = $customFieldsGroup;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get customFieldsGroup
|
||||||
|
*
|
||||||
|
* @return CustomFieldsGroup
|
||||||
|
*/
|
||||||
|
public function getCustomFieldsGroup()
|
||||||
|
{
|
||||||
|
return $this->customFieldsGroup;
|
||||||
|
}
|
||||||
|
}
|
20
Resources/config/doctrine/CustomFieldsDefaultGroup.orm.yml
Normal file
20
Resources/config/doctrine/CustomFieldsDefaultGroup.orm.yml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
Chill\CustomFieldsBundle\Entity\CustomFieldsDefaultGroup:
|
||||||
|
type: entity
|
||||||
|
table: null
|
||||||
|
id:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
id: true
|
||||||
|
generator:
|
||||||
|
strategy: AUTO
|
||||||
|
fields:
|
||||||
|
entity:
|
||||||
|
type: string
|
||||||
|
length: 255
|
||||||
|
manyToOne:
|
||||||
|
customFieldsGroup:
|
||||||
|
targetEntity: Chill\CustomFieldsBundle\Entity\CustomFieldsGroup
|
||||||
|
inversedBy: customFields
|
||||||
|
uniqueConstraints:
|
||||||
|
unique_entity:
|
||||||
|
columns: [ entity ]
|
@ -1,20 +1,23 @@
|
|||||||
cl_custom_fields_customfieldsgroup:
|
chill_customfields_customfieldsgroup:
|
||||||
resource: "@ChillCustomFieldsBundle/Resources/config/routing/customfieldsgroup.yml"
|
resource: "@ChillCustomFieldsBundle/Resources/config/routing/customfieldsgroup.yml"
|
||||||
prefix: /
|
prefix: /
|
||||||
|
|
||||||
cl_custom_fields_blopentity2:
|
chill_customfields_blopentity2:
|
||||||
resource: "@ChillCustomFieldsBundle/Resources/config/routing/blopentity2.yml"
|
resource: "@ChillCustomFieldsBundle/Resources/config/routing/blopentity2.yml"
|
||||||
prefix: /blopentity2
|
prefix: /blopentity2
|
||||||
|
|
||||||
cl_custom_fields_adress:
|
chill_customfields_adress:
|
||||||
resource: "@ChillCustomFieldsBundle/Resources/config/routing/adress.yml"
|
resource: "@ChillCustomFieldsBundle/Resources/config/routing/adress.yml"
|
||||||
prefix: /adress
|
prefix: /adress
|
||||||
|
|
||||||
cl_custom_fields_customfield:
|
chill_customfields_customfield:
|
||||||
resource: "@ChillCustomFieldsBundle/Resources/config/routing/customfield.yml"
|
resource: "@ChillCustomFieldsBundle/Resources/config/routing/customfield.yml"
|
||||||
prefix: /
|
prefix: /
|
||||||
|
|
||||||
cl_custom_fields_blopentity:
|
chill_customfields_blopentity:
|
||||||
resource: "@ChillCustomFieldsBundle/Resources/config/routing/blopentity.yml"
|
resource: "@ChillCustomFieldsBundle/Resources/config/routing/blopentity.yml"
|
||||||
prefix: /
|
prefix: /
|
||||||
|
|
||||||
|
chill_customfields_customfieldsdefaultgroup:
|
||||||
|
resource: "@ChillCustomFieldsBundle/Resources/config/routing/customfieldsdefaultgroup.yml"
|
||||||
|
prefix: /
|
7
Resources/config/routing/customfieldsdefaultgroup.yml
Normal file
7
Resources/config/routing/customfieldsdefaultgroup.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
customfieldsdefaultgroup:
|
||||||
|
path: /{_locale}/admin/customfieldsdefaultgroup/
|
||||||
|
defaults: { _controller: "ChillCustomFieldsBundle:CustomFieldsDefaultGroup:list" }
|
||||||
|
|
||||||
|
customfieldsdefaultgroup_set:
|
||||||
|
path: /{_locale}/admin/customfieldsdefaultgroup/set/group/as/default/
|
||||||
|
defaults: { _controller: "ChillCustomFieldsBundle:CustomFieldsDefaultGroup:setAGroupAsDefault" }
|
30
Resources/views/CustomFieldsDefaultGroup/list.html.twig
Normal file
30
Resources/views/CustomFieldsDefaultGroup/list.html.twig
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
{% extends '::base.html.twig' %}
|
||||||
|
|
||||||
|
{% block body -%}
|
||||||
|
<h1>CustomFieldsDefaultGroup list</h1>
|
||||||
|
|
||||||
|
<table class="records_list">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Entity</th>
|
||||||
|
<th>CustomFieldGroup</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for defaultGroup in defaultGroups %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ defaultGroup.entity }}</td>
|
||||||
|
<td>{{ defaultGroup.customFieldsGroup.name['fr'] }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
{{ form_start(form) }}
|
||||||
|
{{ form_row(form.cFGroup) }}
|
||||||
|
|
||||||
|
<button type="submit">
|
||||||
|
set as Default
|
||||||
|
</button>
|
||||||
|
{{ form_end(form) }}
|
||||||
|
{% endblock %}
|
Loading…
x
Reference in New Issue
Block a user