Skip to content

Instantly share code, notes, and snippets.

/Company.php Secret

Created February 27, 2018 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/666b758bfbeb95c076ae02c94931c4eb to your computer and use it in GitHub Desktop.
Save anonymous/666b758bfbeb95c076ae02c94931c4eb to your computer and use it in GitHub Desktop.
<?php
//....
/**
* Many Companies has Many Countries
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Country", inversedBy="companies")
* @ORM\JoinTable(name="companies_countries")
*/
private $countries;
<?php
//...
->add('countries', CollectionType::class, [
'entry_type' => CountryType::class,
'allow_add' => true,
'by_reference' => false,
'allow_delete' => true,
'required' => true,
])
<?php
namespace AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* Country
*
* @ORM\Table(name="country")
* @ORM\Entity(repositoryClass="AppBundle\Repository\CountryRepository")
*/
class Country
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=50)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="symbol", type="string", length=2)
*/
private $symbol;
/**
* @var string
*
* @ORM\Column(name="slug", type="string", length=50)
*/
private $slug;
/**
* @var string
*
* @ORM\Column(name="enabled", type="boolean")
*/
private $enabled;
/**
* Many Countries have Many Companies.
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Company", mappedBy="countries")
*/
private $companies;
/**
* One Country has Many Voivodeships.
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Voivodeship", mappedBy="country")
*/
private $voivodeships;
public function __construct() {
$this->companies = new ArrayCollection();
$this->voivodeships = new ArrayCollection();
}
public function __toString()
{
return $this->name;
}
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*
* @return Country
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @return string
*/
public function getSymbol()
{
return $this->symbol;
}
/**
* @param string $symbol
*/
public function setSymbol($symbol)
{
$this->symbol = $symbol;
}
/**
* @return string
*/
public function getSlug()
{
return $this->slug;
}
/**
* @param string $slug
*/
public function setSlug($slug)
{
$this->slug = $slug;
}
/**
* @return string
*/
public function getEnabled()
{
return $this->enabled;
}
/**
* @param string $enabled
*/
public function setEnabled($enabled)
{
$this->enabled = $enabled;
}
}
<?php
namespace AppBundle\Form;
use AppBundle\Entity\Country;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class CountryType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', EntityType::class, [
'class' => Country::class,
'multiple' => true,
'expanded' => true,
])
;
}/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\Country'
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'appbundle_country';
}
}
<?php
namespace AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* County
*
* @ORM\Table(name="county")
* @ORM\Entity(repositoryClass="AppBundle\Repository\CountyRepository")
*/
class County
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=50)
*/
private $name;
/**
* @var int
*
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Voivodeship", inversedBy="counties")
* @ORM\JoinColumn(name="voivodeship", referencedColumnName="id")
*/
private $voivodeship;
/**
* Many Groups have Many Users.
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\County", mappedBy="counties")
*/
private $companies;
public function __construct() {
$this->companies = new ArrayCollection();
}
public function __toString()
{
return $this->name;
}
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*
* @return County
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @return int
*/
public function getVoivodeship()
{
return $this->voivodeship;
}
/**
* @param int $voivodeship
*/
public function setVoivodeship($voivodeship)
{
$this->voivodeship = $voivodeship;
}
}
<?php
namespace AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* Voivodeship
*
* @ORM\Table(name="voivodeship")
* @ORM\Entity(repositoryClass="AppBundle\Repository\VoivodeshipRepository")
*/
class Voivodeship
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=50)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="slug", type="string", length=50)
*/
private $slug;
/**
* Many Features have One Product.
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Country", inversedBy="voivodeships")
* @ORM\JoinColumn(name="country", referencedColumnName="id")
*/
private $country;
/**
* One Voivodeship has Many Counties.
* @ORM\OneToMany(targetEntity="AppBundle\Entity\County", mappedBy="voivodeship", fetch="EAGER")
*/
private $counties;
public function __construct() {
$this->counties = new ArrayCollection();
}
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*
* @return Voivodeship
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @return string
*/
public function getSlug()
{
return $this->slug;
}
/**
* @param string $slug
*/
public function setSlug($slug)
{
$this->slug = $slug;
}
/**
* Set country
*
* @param integer $country
*
* @return Voivodeship
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
/**
* Get country
*
* @return int
*/
public function getCountry()
{
return $this->country;
}
public function __toString()
{
return $this->name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment