Created
March 23, 2016 14:41
-
-
Save Raistlfiren/818cab076a6471579d75 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Test\Job\CompanyBundle\Entity\Listener; | |
use Test\CoreBundle\Entity\Address; | |
use Doctrine\ORM\Event\LifecycleEventArgs; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
class CompanyAddressListener | |
{ | |
/** @var ContainerInterface $container */ | |
protected $container; | |
public function __construct(ContainerInterface $container) | |
{ | |
$this->container = $container; | |
} | |
public function postUpdate(LifecycleEventArgs $event) | |
{ | |
$entity = $event->getEntity(); | |
if ($entity instanceof Address) { | |
//Check if Address is a part of Company.... | |
} | |
} | |
} | |
<?php | |
namespace Test\CoreBundle\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
use Symfony\Component\Validator\Constraints as Assert; | |
/** | |
* Class Address | |
* @package CoreBundle\Entity | |
* | |
* Address | |
* | |
* @ORM\Table() | |
* @ORM\Entity() | |
*/ | |
class Address | |
{ | |
/** | |
* @var integer | |
* | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
private $id; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="phone", type="string", length=10, nullable=true) | |
*/ | |
private $phone; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="address", type="string", length=255, nullable=true) | |
* @Assert\NotBlank(groups={"createJob"}) | |
*/ | |
private $address; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="city", type="string", length=100, nullable=true) | |
*/ | |
private $city; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="state", type="string", length=2, nullable=true) | |
*/ | |
private $state; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="zipCode", type="string", length=10, nullable=true) | |
*/ | |
private $zipCode; | |
/** | |
* @return int | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* @param int $id | |
* @return Address | |
*/ | |
public function setId($id) | |
{ | |
$this->id = $id; | |
return $this; | |
} | |
/** | |
* @return string | |
*/ | |
public function getPhone() | |
{ | |
return $this->phone; | |
} | |
/** | |
* @param string $phone | |
* @return Address | |
*/ | |
public function setPhone($phone) | |
{ | |
$this->phone = $phone; | |
return $this; | |
} | |
/** | |
* @return string | |
*/ | |
public function getAddress() | |
{ | |
return $this->address; | |
} | |
/** | |
* @param string $address | |
* @return Address | |
*/ | |
public function setAddress($address) | |
{ | |
$this->address = $address; | |
return $this; | |
} | |
/** | |
* @return string | |
*/ | |
public function getCity() | |
{ | |
return $this->city; | |
} | |
/** | |
* @param string $city | |
* @return Address | |
*/ | |
public function setCity($city) | |
{ | |
$this->city = $city; | |
return $this; | |
} | |
/** | |
* @return string | |
*/ | |
public function getState() | |
{ | |
return $this->state; | |
} | |
/** | |
* @param string $state | |
* @return Address | |
*/ | |
public function setState($state) | |
{ | |
$this->state = $state; | |
return $this; | |
} | |
/** | |
* @return string | |
*/ | |
public function getZipCode() | |
{ | |
return $this->zipCode; | |
} | |
/** | |
* @param string $zipCode | |
* @return Address | |
*/ | |
public function setZipCode($zipCode) | |
{ | |
$this->zipCode = $zipCode; | |
return $this; | |
} | |
} | |
<?php | |
namespace Test\Job\CompanyBundle\Entity; | |
use Test\CoreBundle\Entity\Address; | |
use Test\CoreBundle\Model\RepositoryMethod; | |
use Doctrine\Common\Collections\ArrayCollection; | |
use Doctrine\ORM\Mapping as ORM; | |
use Gedmo\Timestampable\Traits\TimestampableEntity; | |
use Test\Job\JobBundle\Entity\Job; | |
use JMS\Serializer\Annotation\SerializedName; | |
use JMS\Serializer\Annotation\VirtualProperty; | |
/** | |
* Company | |
* | |
* @ORM\Table() | |
* @ORM\Entity(repositoryClass="Test\Job\CompanyBundle\Entity\CompanyRepository") | |
* @ORM\EntityListeners({"Test\Job\CompanyBundle\Entity\Listener\CompanyListener"}) | |
*/ | |
class Company | |
{ | |
use TimestampableEntity; | |
use RepositoryMethod; | |
/** | |
* @var integer | |
* | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
private $id; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="name", type="string", length=155) | |
*/ | |
private $name; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="contact", type="string", length=255, nullable=true) | |
*/ | |
private $contact; | |
/** | |
* @ORM\ManyToOne(targetEntity="Test\CoreBundle\Entity\Address", cascade={"persist"}) | |
*/ | |
private $address; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="customer_po", type="string", length=255, nullable=true) | |
*/ | |
private $customerPo; | |
/** | |
* @ORM\OneToMany(targetEntity="Test\Job\JobBundle\Entity\Job", mappedBy="company", cascade={"persist"}) | |
*/ | |
private $jobs; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="quickbooksID", type="string", length=100, nullable=true) | |
*/ | |
private $quickbooksID; | |
public function __construct() | |
{ | |
$this->jobs = new ArrayCollection(); | |
$this->setCreatedAt(new \DateTime()); | |
$this->setUpdatedAt(new \DateTime()); | |
} | |
/** | |
* Get id | |
* | |
* @return integer | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* @param $id | |
* @return Company | |
*/ | |
public function setId($id) | |
{ | |
$this->id = $id; | |
return $this; | |
} | |
/** | |
* Set name | |
* | |
* @param string $name | |
* | |
* @return Company | |
*/ | |
public function setName($name) | |
{ | |
$this->name = $name; | |
return $this; | |
} | |
/** | |
* Get name | |
* | |
* @return string | |
*/ | |
public function getName() | |
{ | |
return $this->name; | |
} | |
/** | |
* Set contact | |
* | |
* @param string $contact | |
* | |
* @return Company | |
*/ | |
public function setContact($contact) | |
{ | |
$this->contact = $contact; | |
return $this; | |
} | |
/** | |
* Get contact | |
* | |
* @return string | |
*/ | |
public function getContact() | |
{ | |
return $this->contact; | |
} | |
/** | |
* Set address | |
* | |
* @param Address $address | |
* | |
* @return Company | |
*/ | |
public function setAddress($address) | |
{ | |
$this->address = $address; | |
return $this; | |
} | |
/** | |
* Get address | |
* | |
* @return Address | |
*/ | |
public function getAddress() | |
{ | |
return $this->address; | |
} | |
/** | |
* @return string | |
*/ | |
public function getCustomerPo() | |
{ | |
return $this->customerPo; | |
} | |
/** | |
* @param string $customerPo | |
* @return Company | |
*/ | |
public function setCustomerPo($customerPo) | |
{ | |
$this->customerPo = $customerPo; | |
return $this; | |
} | |
/** | |
* @return Job[] | |
*/ | |
public function getJobs() | |
{ | |
return $this->jobs; | |
} | |
public function addJobs(Job $job) | |
{ | |
$this->jobs->add($job); | |
return $this; | |
} | |
public function removeJobs(Job $job) | |
{ | |
$this->jobs->removeElement($job); | |
return $this; | |
} | |
/** | |
* @return string | |
*/ | |
public function getQuickbooksID() | |
{ | |
return $this->quickbooksID; | |
} | |
/** | |
* @param string $quickbooksID | |
* @return Company | |
*/ | |
public function setQuickbooksID($quickbooksID) | |
{ | |
$this->quickbooksID = $quickbooksID; | |
return $this; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment