Skip to content

Instantly share code, notes, and snippets.

@micheleorselli
Created October 31, 2012 12:01
Show Gist options
  • Save micheleorselli/3986681 to your computer and use it in GitHub Desktop.
Save micheleorselli/3986681 to your computer and use it in GitHub Desktop.
one line getter setter2
<?php
namespace Ideato\OfferBundle\Entity;
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\ExecutionContext;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Ideato\OfferBundle\Serializer\JsonSerializer;
/**
* @ORM\Entity(repositoryClass="Ideato\OfferBundle\Repository\CompanyRepository")
* @ORM\Table(name="company")
*/
class Company
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function getId() { return $this->id; }
public function setId($id) { $this->id = $id; }
/**
* @ORM\Column(name="name", type="string", length=255)
* @Assert\NotBlank()
*/
private $name;
public function getName() { return $this->name; }
public function setName($name) { $this->name = $name; }
/**
* @Assert\File(
* maxSize="2M",
* mimeTypes={"image/png", "image/jpeg", "image/pjpeg"}
* )
* @Vich\UploadableField(mapping="company", fileNameProperty="picture_name")
*
* @var File $picture
*/
protected $picture;
/**
* @ORM\Column(name="picture_name", type="string", length=255, nullable=true)
*/
protected $picture_name;
/**
* @ORM\Column(name="address", type="string", length=255)
* @Assert\NotBlank()
*/
private $address;
public function getAddress() { return $this->address; }
public function setAddress($address) {$this->address = $address; }
/**
* @ORM\Column(name="phone", type="string", length=30)
* @Assert\NotBlank()
*/
private $phone;
public function getPhone() { return $this->address; }
public function setPhone($phone) { $this->phone = $phone; }
/**
* @ORM\Column(name="web", type="string", length=255)
* @Assert\NotBlank()
*/
private $web;
public function getWeb() { return $this->web; }
public function setWeb($web) { $this->web = $web; }
/**
* @ORM\Column(name="email", type="string", length=255)
* @Assert\NotBlank()
*/
private $email;
/**
* @ORM\Column(type="string", length=255)
*/
protected $latitude;
public function getLatitude() { return $this->latitude; }
public function setLatitude($latitude) { $this->latitude = $latitude; }
/**
* @ORM\Column(type="string", length=255)
*/
protected $longitude;
public function getLongitude() { return $this->longitude; }
public function setLongitude($longitude) { $this->longitude = $longitude; }
/**
* @ORM\OneToMany(targetEntity="Ideato\OfferBundle\Entity\Offer", mappedBy="company")
**/
private $offers;
/**
* @ORM\Column(name="created_at", type="datetime", nullable=true)
*/
protected $created_at;
/**
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
*/
protected $updated_at;
public function __construct()
{
$this->offers = new ArrayCollection();
}
public function serialize(JsonSerializer $serializer)
{
$path = $serializer->imgPath($this, 'picture');
$thumb_path = $serializer->imgAliasPath($path, 'offer_homepage');
return array(
'id' => $this->id,
'name' => $this->name,
'imgSrc' => $path,
'imgThumbSrc' => $thumb_path,
'lat' => $this->latitude,
'lng' => $this->longitude,
'permalink' => $serializer->entityPath($this, 'company'),
);
}
public function __toString() { return $this->getName(); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment