Skip to content

Instantly share code, notes, and snippets.

@ksn135
Created August 3, 2015 04:46
Show Gist options
  • Save ksn135/2cb7b55c6414a3ad29c5 to your computer and use it in GitHub Desktop.
Save ksn135/2cb7b55c6414a3ad29c5 to your computer and use it in GitHub Desktop.
s2a_collection_table example
# src/AppBundle/Resources/config/Action-generator.yml
generator: admingenerator.generator.doctrine
params:
model: AppBundle\Entity\Action
concurrency_lock: ~
bundle_name: AppBundle
pk_requirement: \d+
i18n_catalog: messages
embed_types:
- embed-Result-generator.yml
fields:
kind:
label: contract.kind.title
title:
label: global.title
position:
formType: hidden
results:
label: result.title
dbType: collection
formType: s2a_collection_table
addFormOptions:
sortable: true
fieldset_class: col-md-8
type: \AppBundle\Form\Type\Result\EditType
allow_add: true
allow_delete: true
by_reference: false
options:
label: result.title
data_class: AppBundle\Entity\Result
translations:
label: global.translations
formType: a2lix_translations_gedmo
addFormOptions:
fields:
title:
label: global.title
createdAt:
label: global.createdAt
dbType: datetime
updatedAt:
label: global.updatedAt
dbType: datetime
createdBy:
label: global.createdBy
sortOn: createdBy.familyName
updatedBy:
label: global.updatedBy
sortOn: upatedBy.familyName
actions:
new:
credentials: 'hasRole("ROLE_PROGRAM")'
edit:
credentials: 'hasRole("ROLE_PROGRAM")'
show:
credentials: 'hasRole("ROLE_PROGRAM")'
excel:
credentials: 'hasRole("ROLE_PROGRAM")'
save:
credentials: 'hasRole("ROLE_PROGRAM")'
list:
credentials: 'hasRole("ROLE_PROGRAM")'
delete:
credentials: 'hasRole("ROLE_PROGRAM")'
object_actions:
show:
credentials: 'hasRole("ROLE_PROGRAM")'
excel:
credentials: 'hasRole("ROLE_PROGRAM")'
new:
credentials: 'hasRole("ROLE_PROGRAM")'
edit:
credentials: 'hasRole("ROLE_PROGRAM")'
list:
credentials: 'hasRole("ROLE_PROGRAM")'
save:
credentials: 'hasRole("ROLE_PROGRAM")'
delete:
credentials: 'hasRole("ROLE_PROGRAM")'
batch_actions:
delete:
credentials: 'hasRole("ROLE_PROGRAM")'
builders:
actions:
params:
object_actions:
delete:
credentials: 'hasRole("ROLE_PROGRAM")'
batch_actions:
delete:
credentials: 'hasRole("ROLE_PROGRAM")'
list:
params:
credentials: 'hasRole("ROLE_PROGRAM")'
title: actions.title
display: [kind, title, results]
actions:
new: ~
object_actions:
show: ~
edit: ~
excel:
params:
credentials: 'hasRole("ROLE_PROGRAM")'
filename: ~
filetype: ~
new:
params:
credentials: 'hasRole("ROLE_PROGRAM")'
title: actions.new.title
display: { "NONE": { "col-md-12": [kind, title, results] }}
actions:
save: ~
list: ~
edit:
params:
credentials: 'hasRole("ROLE_PROGRAM")'
title: actions.edit.title
display: { "NONE": { "col-md-12": [kind, translations, results] }}
actions:
save: ~
show: ~
list: ~
delete: ~
show:
params:
credentials: 'hasRole("ROLE_PROGRAM")'
title: actions.show.title
display: { "NONE": { "col-md-12": [kind, title, results, createdAt, createdBy, updatedAt, updatedBy] }}
actions:
list: ~
edit: ~
<?php // src/AppBundle/Entity/Action.php
/*
* This file is part of the XXXXXXXXXXXXXXXX informational system package.
*
* (c) Serg N. Kalachev <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use AppBundle\Entity\Translation\ActionTranslation;
use AppBundle\Traits\BlameableEntity;
use AppBundle\Traits\TimestampableEntity;
use AppBundle\Traits\SoftDeleteableEntity;
/**
* Action.
*
* @ORM\Entity
* @ORM\Table(name="action",options={"type"="InnoDB","charset"="utf8","collate"="utf8_general_ci"})
* @Gedmo\TranslationEntity(class="AppBundle\Entity\Translation\ActionTranslation")
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
*/
class Action
{
/*
* Hook blameable behavior
* updates createdBy, updatedBy fields
*/
use BlameableEntity;
/*
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/*
* Hook softdeletable behavior
* updates deletedBy, deletedAt fields
*/
use SoftDeleteableEntity;
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var ContractKind
*
* @Gedmo\SortableGroup
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\ContractKind", inversedBy="actions", cascade={"persist"})
* @ORM\JoinColumn(name="kind_id", referencedColumnName="id")
* @Assert\NotNull
*/
private $kind;
/**
* @Gedmo\SortablePosition
* @ORM\Column(name="position", type="integer")
*/
protected $position;
/**
* @var string
*
* @Assert\NotBlank
* @ORM\Column(name="title", type="string", length=255)
* @Gedmo\Translatable
*/
private $title;
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Translation\ActionTranslation", mappedBy="object", cascade={"persist", "remove"})
*/
protected $translations;
/**
* @Gedmo\Locale
* Used locale to override Translation listener`s locale
* this is not a mapped field of entity metadata, just a simple property
*/
private $locale;
/**
* @var ArrayCollection
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Result", mappedBy="action", cascade={"all"}, orphanRemoval=true)
* @ORM\OrderBy({"position" = "ASC"})
*/
private $results;
public function __construct()
{
$this->translations = new ArrayCollection();
$this->results = new ArrayCollection();
}
public function getLocale()
{
return $this->locale;
}
public function setLocale($locale)
{
$this->locale = $locale;
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
public function getTranslations()
{
return $this->translations;
}
public function addTranslation(ActionTranslation $t)
{
$this->translations->add($t);
$t->setObject($this);
}
public function removeTranslation(ActionTranslation $t)
{
$this->translations->removeElement($t);
}
public function setTranslations($translations)
{
foreach ($translations as $translation) {
$translation->setObject($this);
}
$this->translations = $translations;
return $this;
}
public function __toString()
{
return $this->getTitle();
}
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set title.
*
* @param string $title
*
* @return NewsCategory
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title.
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set position.
*
* @param int $position
*
* @return Action
*/
public function setPosition($position)
{
$this->position = $position;
return $this;
}
/**
* Get position.
*
* @return int
*/
public function getPosition()
{
return $this->position;
}
/**
* Set kind.
*
* @param \AppBundle\Entity\ContractKind $kind
*
* @return Action
*/
public function setKind(\AppBundle\Entity\ContractKind $kind = null)
{
$this->kind = $kind;
return $this;
}
/**
* Get kind.
*
* @return \AppBundle\Entity\ContractKind
*/
public function getKind()
{
return $this->kind;
}
/**
* Get results.
*
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function getResults()
{
return $this->results;
}
/**
* Add result.
*
* @param \AppBundle\Entity\Result $result
*
* @return Action
*/
public function addResult(\AppBundle\Entity\Result $result)
{
$result->setAction($this);
$this->results[] = $result;
return $this;
}
/**
* Remove result.
*
* @param \AppBundle\Entity\Result $result
*
* @return Action
*/
public function removeResult(\AppBundle\Entity\Result $result)
{
$result->setAction(null);
$this->results->removeElement($result);
return $this;
}
}
# src/AppBundle/Resources/config/embed-Result-generator.yml
generator: admingenerator.generator.doctrine
params:
model: AppBundle\Entity\Result
concurrency_lock: ~
bundle_name: AppBundle
pk_requirement: \d+
i18n_catalog: messages
fields:
action:
label: action.title
formType: hidden
title:
label: global.title
position:
formType: hidden
translations:
label: global.translations
formType: a2lix_translations_gedmo
addFormOptions:
fields:
title:
label: global.title
createdAt:
label: global.createdAt
dbType: datetime
updatedAt:
label: global.updatedAt
dbType: datetime
createdBy:
label: global.createdBy
sortOn: createdBy.familyName
updatedBy:
label: global.updatedBy
sortOn: upatedBy.familyName
actions:
new:
credentials: 'hasRole("ROLE_PROGRAM")'
edit:
credentials: 'hasRole("ROLE_PROGRAM")'
show:
credentials: 'hasRole("ROLE_PROGRAM")'
excel:
credentials: 'hasRole("ROLE_PROGRAM")'
save:
credentials: 'hasRole("ROLE_PROGRAM")'
list:
credentials: 'hasRole("ROLE_PROGRAM")'
delete:
credentials: 'hasRole("ROLE_PROGRAM")'
object_actions:
show:
credentials: 'hasRole("ROLE_PROGRAM")'
excel:
credentials: 'hasRole("ROLE_PROGRAM")'
new:
credentials: 'hasRole("ROLE_PROGRAM")'
edit:
credentials: 'hasRole("ROLE_PROGRAM")'
list:
credentials: 'hasRole("ROLE_PROGRAM")'
save:
credentials: 'hasRole("ROLE_PROGRAM")'
delete:
credentials: 'hasRole("ROLE_PROGRAM")'
batch_actions:
delete:
credentials: 'hasRole("ROLE_PROGRAM")'
builders:
actions:
params:
object_actions:
delete:
credentials: 'hasRole("ROLE_PROGRAM")'
batch_actions:
delete:
credentials: 'hasRole("ROLE_PROGRAM")'
list:
params:
credentials: 'hasRole("ROLE_PROGRAM")'
title: result.title
display: [action, title]
actions:
new: ~
object_actions:
show: ~
edit: ~
excel:
params:
credentials: 'hasRole("ROLE_PROGRAM")'
filename: ~
filetype: ~
new:
params:
credentials: 'hasRole("ROLE_PROGRAM")'
title: result.new.title
display: [title, position]
actions:
save: ~
list: ~
edit:
params:
credentials: 'hasRole("ROLE_PROGRAM")'
title: result.edit.title
display: [title, position]
actions:
save: ~
show: ~
list: ~
delete: ~
show:
params:
credentials: 'hasRole("ROLE_PROGRAM")'
title: result.show.title
display: { "NONE": { "col-md-12": [action, title, createdAt, createdBy, updatedAt, updatedBy] }}
actions:
list: ~
edit: ~
<?php // src/AppBundle/Entity/Result.php
/*
* This file is part of the XXXXXXXXXXX informational system package.
*
* (c) Serg N. Kalachev <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use AppBundle\Traits\BlameableEntity;
use AppBundle\Traits\TimestampableEntity;
use AppBundle\Traits\SoftDeleteableEntity;
/**
* Result.
*
* @ORM\Entity
* @ORM\Table(name="result",options={"type"="InnoDB","charset"="utf8","collate"="utf8_general_ci"})
* @Gedmo\TranslationEntity(class="AppBundle\Entity\Translation\ResultTranslation")
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
*/
class Result
{
/*
* Hook blameable behavior
* updates createdBy, updatedBy fields
*/
use BlameableEntity;
/*
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/*
* Hook softdeletable behavior
* updates deletedBy, deletedAt fields
*/
use SoftDeleteableEntity;
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var Action
*
* @Gedmo\SortableGroup
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Action", inversedBy="results", cascade={"persist"})
* @ORM\JoinColumn(name="action_id", referencedColumnName="id")
* @Assert\NotNull
*/
private $action;
/**
* @Gedmo\SortablePosition
* @ORM\Column(name="position", type="integer")
*/
protected $position;
/**
* @var string
*
* @Assert\NotBlank
* @ORM\Column(name="title", type="string", length=255)
* @Gedmo\Translatable
*/
private $title;
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Translation\ResultTranslation", mappedBy="object", cascade={"persist", "remove"})
*/
protected $translations;
/**
* @Gedmo\Locale
* Used locale to override Translation listener`s locale
* this is not a mapped field of entity metadata, just a simple property
*/
private $locale;
public function __construct()
{
$this->translations = new ArrayCollection();
}
public function getLocale()
{
return $this->locale;
}
public function setLocale($locale)
{
$this->locale = $locale;
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
public function getTranslations()
{
return $this->translations;
}
public function addTranslation(ResultTranslation $t)
{
$this->translations->add($t);
$t->setObject($this);
}
public function removeTranslation(ResultTranslation $t)
{
$this->translations->removeElement($t);
}
public function setTranslations($translations)
{
foreach ($translations as $translation) {
$translation->setObject($this);
}
$this->translations = $translations;
return $this;
}
public function __toString()
{
return $this->getTitle();
}
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set title.
*
* @param string $title
*
* @return NewsCategory
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title.
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set position.
*
* @param int $position
*
* @return Action
*/
public function setPosition($position)
{
$this->position = $position;
return $this;
}
/**
* Get position.
*
* @return int
*/
public function getPosition()
{
return $this->position;
}
/**
* Set action.
*
* @param \AppBundle\Entity\Action $action
*
* @return Action
*/
public function setAction(\AppBundle\Entity\Action $action = null)
{
$this->action = $action;
return $this;
}
/**
* Get action.
*
* @return \AppBundle\Entity\Action
*/
public function getAction()
{
return $this->action;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment