sf4 deprecated: migrate Doctrine ORM mapping to annotation

This commit is contained in:
Tchama 2020-07-24 17:45:32 +02:00
parent a38208f5cf
commit 3a03d44e9a
8 changed files with 187 additions and 174 deletions

View File

@ -21,60 +21,88 @@
namespace Chill\CustomFieldsBundle\Entity; namespace Chill\CustomFieldsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/** /**
* CustomField * CustomField
*
* @ORM\Entity()
* @ORM\Table(null)
* @ORM\HasLifecycleCallbacks()
*/ */
class CustomField class CustomField
{ {
/** /**
* @var integer * @var integer
*
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/ */
private $id; private $id;
/**
* @var string
*
* @ORM\Column(type="string", length=255)
*/
private $slug; private $slug;
/** /**
* @var string * @var string
*
* @ORM\Column(type="string", length=255)
*/ */
private $type; private $type;
/** /**
* @var boolean * @var boolean
*
* @ORM\Column(type="boolean")
*/ */
private $active = true; private $active = true;
/** /**
*
* @var array * @var array
*
* @ORM\Column(type="json_array")
*/ */
private $options = array(); private $options = array();
/** /**
* @var array * @var array
*
* @ORM\Column(type="json_array")
*/ */
private $name; private $name;
/** /**
* @var float * @var float
*
* @ORM\Column(type="float")
*/ */
private $ordering; private $ordering;
/** /**
* @var boolean
* *
* @var bolean * @ORM\Column(type="boolean")
*/ */
private $required = FALSE; private $required = FALSE;
const ONE_TO_ONE = 1; const ONE_TO_ONE = 1;
const ONE_TO_MANY = 2; const ONE_TO_MANY = 2;
/** /**
* @var CustomFieldsGroup * @var CustomFieldsGroup
*
* @ORM\ManyToOne(
* targetEntity="Chill\CustomFieldsBundle\Entity\CustomFieldsGroup",
* inversedBy="customFields")
*/ */
private $customFieldGroup; private $customFieldGroup;
/** /**
* Get id * Get id
* *
@ -85,22 +113,26 @@ class CustomField
return $this->id; return $this->id;
} }
/**
* @return string
*/
function getSlug() function getSlug()
{ {
return $this->slug; return $this->slug;
} }
/**
* @return array
*/
function getOptions() function getOptions()
{ {
return $this->options; return $this->options;
} }
/** /**
* Set type * Set type
* *
* @param string $type * @param string $type
*
* @return CustomField * @return CustomField
*/ */
public function setType($type) public function setType($type)
@ -125,7 +157,6 @@ class CustomField
* Set active * Set active
* *
* @param boolean $active * @param boolean $active
*
* @return CustomField * @return CustomField
*/ */
public function setActive($active) public function setActive($active)
@ -158,11 +189,10 @@ class CustomField
/** /**
* Set customFieldGroup * Set customFieldGroup
* *
* @param \Chill\CustomFieldsBundle\Entity\CustomFieldsGroup $customFieldGroup * @param CustomFieldsGroup $customFieldGroup
*
* @return CustomField * @return CustomField
*/ */
public function setCustomFieldsGroup(\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup $customFieldGroup = null) public function setCustomFieldsGroup(CustomFieldsGroup $customFieldGroup = null)
{ {
$this->customFieldGroup = $customFieldGroup; $this->customFieldGroup = $customFieldGroup;
@ -173,7 +203,6 @@ class CustomField
* Set name * Set name
* *
* @param array $name * @param array $name
*
* @return CustomField * @return CustomField
*/ */
public function setName($name) public function setName($name)
@ -212,7 +241,6 @@ class CustomField
* Set order * Set order
* *
* @param float $order * @param float $order
*
* @return CustomField * @return CustomField
*/ */
public function setOrdering($order) public function setOrdering($order)
@ -236,7 +264,6 @@ class CustomField
* Set options * Set options
* *
* @param array $options * @param array $options
*
* @return CustomField * @return CustomField
*/ */
public function setOptions(array $options) public function setOptions(array $options)
@ -245,8 +272,11 @@ class CustomField
return $this; return $this;
} }
/**
* @param $slug
* @return $this
*/
public function setSlug($slug) public function setSlug($slug)
{ {
$this->slug = $slug; $this->slug = $slug;
@ -278,8 +308,5 @@ class CustomField
$this->required = $required; $this->required = $required;
return $this; return $this;
} }
} }

View File

@ -19,93 +19,134 @@
namespace Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice; namespace Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/** /**
* * @ORM\Entity(
* repositoryClass="Chill\CustomFieldsBundle\EntityRepository\CustomFieldLongChoice\OptionRepository")
* @ORM\Table(name="custom_field_long_choice_options")
* *
* @author Julien Fastré <julien.fastre@champs-libres.coop> * @author Julien Fastré <julien.fastre@champs-libres.coop>
*/ */
class Option class Option
{ {
/** /**
* @var integer
* *
* @var int * @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/ */
private $id; private $id;
/** /**
*
* @var string * @var string
* @ORM\Column(type="string", length=15)
*/ */
private $key; private $key;
/** /**
* a json representation of text (multilingual) * A json representation of text (multilingual)
* *
* @var array * @var array
* @ORM\Column(type="text")
*/ */
private $text; private $text;
/** /**
* * @var Collection
* @var \Doctrine\Common\Collections\Collection * @ORM\OneToMany(
* targetEntity="Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option",
* mappedBy="parent")
*/ */
private $children; private $children;
/** /**
*
* @var Option * @var Option
* @ORM\ManyToOne(
* targetEntity="Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option",
* inversedBy="children")
* @ORM\JoinColumn(nullable=true)
*/ */
private $parent; private $parent;
/** /**
*
* @var string * @var string
* @ORM\Column(type="string", length=50, name="internal_key")
*/ */
private $internalKey = ''; private $internalKey = '';
/** /**
*
* @var boolean * @var boolean
* @ORM\Column(type="boolean")
*/ */
private $active = true; private $active = true;
/**
* @return int
*/
public function getId() public function getId()
{ {
return $this->id; return $this->id;
} }
/**
* @return string
*/
public function getKey() public function getKey()
{ {
return $this->key; return $this->key;
} }
/**
* @return array
*/
public function getText() public function getText()
{ {
return $this->text; return $this->text;
} }
/**
* @return Collection
*/
public function getChildren() public function getChildren()
{ {
return $this->children; return $this->children;
} }
/**
* @return Option
*/
public function getParent() public function getParent()
{ {
return $this->parent; return $this->parent;
} }
/**
* @param $key
* @return $this
*/
public function setKey($key) public function setKey($key)
{ {
$this->key = $key; $this->key = $key;
return $this; return $this;
} }
/**
* @param array $text
* @return $this
*/
public function setText(array $text) public function setText(array $text)
{ {
$this->text = $text; $this->text = $text;
return $this; return $this;
} }
/**
* @param Option|null $parent
* @return $this
*/
public function setParent(Option $parent = null) public function setParent(Option $parent = null)
{ {
$this->parent = $parent; $this->parent = $parent;
@ -122,32 +163,48 @@ class Option
return $this->parent === NULL ? false : true; return $this->parent === NULL ? false : true;
} }
/**
* @return string
*/
public function getInternalKey() public function getInternalKey()
{ {
return $this->internalKey; return $this->internalKey;
} }
/**
* @return bool
*/
public function isActive() public function isActive()
{ {
return $this->active; return $this->active;
} }
/**
* @return bool
*/
public function getActive() public function getActive()
{ {
return $this->isActive(); return $this->isActive();
} }
/**
* @param $internal_key
* @return $this
*/
public function setInternalKey($internal_key) public function setInternalKey($internal_key)
{ {
$this->internalKey = $internal_key; $this->internalKey = $internal_key;
return $this; return $this;
} }
/**
* @param $active
* @return $this
*/
public function setActive($active) public function setActive($active)
{ {
$this->active = $active; $this->active = $active;
return $this; return $this;
} }
} }

View File

@ -21,23 +21,44 @@
namespace Chill\CustomFieldsBundle\Entity; namespace Chill\CustomFieldsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/** /**
* CustomFieldsDefaultGroup * CustomFieldsDefaultGroup
*
* @ORM\Entity()
* @ORM\Table(
* null,
* uniqueConstraints={@ORM\UniqueConstraint(
* name="unique_entity",
* columns={"entity"}
* )})
*/ */
class CustomFieldsDefaultGroup class CustomFieldsDefaultGroup
{ {
/** /**
* @var integer * @var integer
*
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/ */
private $id; private $id;
/** /**
* @var string * @var string
*
* @ORM\Column(type="string", length=255)
*/ */
private $entity; private $entity;
/** /**
* @var CustomFieldsGroup * @var CustomFieldsGroup
*
* @ORM\ManyToOne(
* targetEntity="Chill\CustomFieldsBundle\Entity\CustomFieldsGroup")
*
* sf4 check: option inversedBy="customFields" return inconsistent error mapping !!
*/ */
private $customFieldsGroup; private $customFieldsGroup;
@ -55,7 +76,6 @@ class CustomFieldsDefaultGroup
* Set entity * Set entity
* *
* @param string $entity * @param string $entity
*
* @return CustomFieldsDefaultGroup * @return CustomFieldsDefaultGroup
*/ */
public function setEntity($entity) public function setEntity($entity)
@ -78,8 +98,7 @@ class CustomFieldsDefaultGroup
/** /**
* Set customFieldsGroup * Set customFieldsGroup
* *
* @param CustomFieldsGroup $customFieldsGroup * @param CustomFieldsGroup $customFieldsGroup *
*
* @return CustomFieldsDefaultGroup * @return CustomFieldsDefaultGroup
*/ */
public function setCustomFieldsGroup($customFieldsGroup) public function setCustomFieldsGroup($customFieldsGroup)

View File

@ -21,64 +21,85 @@
namespace Chill\CustomFieldsBundle\Entity; namespace Chill\CustomFieldsBundle\Entity;
use \Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
/** /**
* CustomFieldGroup * CustomFieldGroup
*
* @ORM\Entity()
* @ORM\Table(null)
*/ */
class CustomFieldsGroup class CustomFieldsGroup
{ {
/** /**
* @var integer * @var integer
*
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/ */
private $id; private $id;
/** /**
* @var array * @var array
*
* @ORM\Column(type="json_array")
*/ */
private $name; private $name;
/** /**
* @var string * @var string
*
* @ORM\Column(type="string", length=255)
*/ */
private $entity; private $entity;
/** /**
* @var \Doctrine\Common\Collections\Collection $customFields: The custom * The custom fields of the group.
* fields of the group. The custom fields are asc-ordered regarding to their * The custom fields are asc-ordered regarding to their property "ordering".
* property "ordering". *
* @var Collection $customFields
*
* @ORM\OneToMany(
* targetEntity="Chill\CustomFieldsBundle\Entity\CustomField",
* mappedBy="customFieldGroup")
* @ORM\OrderBy({"ordering" = "ASC"})
*/ */
private $customFields; private $customFields;
/** /**
* @var array(customField) | null $activeCustomFields: The custom fields * The custom fields of the group that are active.
* of the group that are active. This variable if null, if this * This variable if null, if this informations has not been computed.
* informations has not been computed. *
* @var array|null
*/ */
private $activeCustomFields = null; private $activeCustomFields = null;
/** /**
*
* @var array * @var array
*
* @ORM\Column(type="json_array")
*/ */
private $options = array(); private $options = array();
/** /**
* Constructor * CustomFieldsGroup constructor.
*/ */
public function __construct() public function __construct()
{ {
$this->customFields = new \Doctrine\Common\Collections\ArrayCollection(); $this->customFields = new ArrayCollection();
} }
/** /**
* Add customField * Add customField
* *
* @param \Chill\CustomFieldsBundle\Entity\CustomField $customField * @param CustomField $customField
*
* @return CustomFieldsGroup * @return CustomFieldsGroup
*/ */
public function addCustomField(\Chill\CustomFieldsBundle\Entity\CustomField $customField) public function addCustomField(CustomField $customField)
{ {
$this->customFields[] = $customField; $this->customFields[] = $customField;
@ -88,16 +109,15 @@ class CustomFieldsGroup
/** /**
* Remove customField * Remove customField
* *
* @param \Chill\CustomFieldsBundle\Entity\CustomField $customField * @param CustomField $customField
*/ */
public function removeCustomField(\Chill\CustomFieldsBundle\Entity\CustomField $customField) public function removeCustomField(CustomField $customField)
{ {
$this->customFields->removeElement($customField); $this->customFields->removeElement($customField);
} }
/** /**
* * @return Collection
* @return \Doctrine\Common\Collections\Collection
*/ */
public function getCustomFields() public function getCustomFields()
{ {
@ -107,7 +127,7 @@ class CustomFieldsGroup
/** /**
* Get all the custom * Get all the custom
* *
* @return \Doctrine\Common\Collections\Collection * @return Collection
*/ */
public function getActiveCustomFields() public function getActiveCustomFields()
{ {
@ -122,7 +142,6 @@ class CustomFieldsGroup
return $this->activeCustomFields; return $this->activeCustomFields;
} }
/** /**
* Get id * Get id
@ -138,7 +157,6 @@ class CustomFieldsGroup
* Set name * Set name
* *
* @param array $name * @param array $name
*
* @return CustomFieldsGroup * @return CustomFieldsGroup
*/ */
public function setName($name) public function setName($name)
@ -178,7 +196,6 @@ class CustomFieldsGroup
* Set entity * Set entity
* *
* @param string $entity * @param string $entity
*
* @return CustomFieldsGroup * @return CustomFieldsGroup
*/ */
public function setEntity($entity) public function setEntity($entity)
@ -212,7 +229,7 @@ class CustomFieldsGroup
* set options array * set options array
* *
* @param array $options * @param array $options
* @return \Chill\CustomFieldsBundle\Entity\CustomFieldsGroup * @return CustomFieldsGroup
*/ */
public function setOptions(array $options) public function setOptions(array $options)
{ {

View File

@ -1,32 +0,0 @@
Chill\CustomFieldsBundle\Entity\CustomField:
type: entity
table: null
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
name:
type: json_array
slug:
type: string
length: 255
type:
type: string
length: 255
active:
type: boolean
ordering:
type: float
options:
type: json_array
required:
type: boolean
lifecycleCallbacks: { }
manyToOne:
customFieldGroup:
targetEntity: Chill\CustomFieldsBundle\Entity\CustomFieldsGroup
inversedBy: customFields
#TODO: add an unique constraint slug+customFieldsGroup

View File

@ -1,33 +0,0 @@
Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option:
type: entity
table: custom_field_long_choice_options
repositoryClass: Chill\CustomFieldsBundle\EntityRepository\CustomFieldLongChoice\OptionRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
key:
type: string
length: 15
text:
type: json_array
internalKey:
type: string
length: 50
column: internal_key
active:
type: boolean
default: true
oneToMany:
children:
targetEntity: Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option
mappedBy: parent
manyToOne:
parent:
targetEntity: Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option
inversedBy: children
nullable: true

View File

@ -1,20 +0,0 @@
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 ]

View File

@ -1,22 +0,0 @@
Chill\CustomFieldsBundle\Entity\CustomFieldsGroup:
type: entity
table: null
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
name:
type: json_array
entity:
type: string
length: 255
options:
type: json_array
oneToMany:
customFields:
orderBy: { 'ordering': 'ASC' }
targetEntity: Chill\CustomFieldsBundle\Entity\CustomField
mappedBy: customFieldGroup