Created
November 20, 2013 19:25
-
-
Save gpfiel/7569382 to your computer and use it in GitHub Desktop.
Create a doctrine function to get Photos from Album
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 Admin\Entity; | |
use Doctrine\ORM\Mapping as ORM, | |
Doctrine\Common\Collections\ArrayCollection; | |
use Zend\InputFilter\Factory as InputFactory; | |
use Zend\InputFilter\InputFilter; | |
use Zend\InputFilter\InputFilterAwareInterface; | |
use Zend\InputFilter\InputFilterInterface; | |
/** | |
* Album | |
* | |
* @ORM\Table(name="bnc_album") | |
* @ORM\Entity | |
* @ORM\HasLifecycleCallbacks | |
*/ | |
class Album implements InputFilterAwareInterface | |
{ | |
/** | |
* @var integer | |
* | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="IDENTITY") | |
*/ | |
private $id; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="title", type="string", nullable=false) | |
*/ | |
private $title; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="description", type="text", nullable=true) | |
*/ | |
private $description; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="mainPhoto", type="string", nullable=true) | |
*/ | |
private $mainPhoto; | |
/** | |
* @var \DateTime | |
* | |
* @ORM\Column(name="date", type="datetime", nullable=true) | |
*/ | |
private $date; | |
/** | |
* @param integer | |
* | |
* @ORM\Column(name="status", type="integer") | |
*/ | |
private $status; | |
/** | |
* @ORM\OneToMany(targetEntity="Photo", mappedBy="album") | |
* @var Photo[] | |
*/ | |
protected $assignedPhotos = null; | |
protected $inputFilter; | |
public function __construct() | |
{ | |
$this->assignedPhotos = new ArrayCollection(); | |
} | |
################### | |
# GET AND SETTERS # | |
################### | |
public function getId() | |
{ | |
return $this->id; | |
} | |
public function getTitle() | |
{ | |
return $this->title; | |
} | |
public function setTitle($title) | |
{ | |
$this->title = $title; | |
return $this; | |
} | |
public function getDescription() | |
{ | |
return $this->description; | |
} | |
public function setDescription($description) | |
{ | |
$this->description = $description; | |
return $this; | |
} | |
public function getMainPhoto() | |
{ | |
return $this->mainPhoto; | |
} | |
public function setMainPhoto($mainPhoto) | |
{ | |
$this->mainPhoto = $mainPhoto; | |
return $this; | |
} | |
public function getDate() | |
{ | |
return $this->date; | |
} | |
public function setDate($date) | |
{ | |
$this->date = $date; | |
return $this; | |
} | |
public function getStatus() | |
{ | |
return $this->status; | |
} | |
public function setStatus($status) | |
{ | |
$this->status = $status; | |
return $this; | |
} | |
public function assignedToPhoto($photo) | |
{ | |
$this->assignedPhotos[] = $photo; | |
} | |
/** | |
* Set input method | |
* | |
* @param InputFilterInterface $inputFilter | |
*/ | |
public function setInputFilter(InputFilterInterface $inputFilter) | |
{ | |
throw new \Exception("Not used"); | |
} | |
/** | |
* Get input filter | |
* | |
* @return InputFilterInterface | |
*/ | |
public function getInputFilter() | |
{ | |
if (!$this->inputFilter) { | |
$inputFilter = new InputFilter(); | |
$factory = new InputFactory(); | |
$inputFilter->add($factory->createInput(array( | |
'name' => 'id', | |
'required' => false, | |
'filters' => array( | |
array('name' => 'Int'), | |
), | |
))); | |
$inputFilter->add($factory->createInput(array( | |
'name' => 'status', | |
'required' => false, | |
'filters' => array( | |
array('name' => 'Int'), | |
), | |
))); | |
$inputFilter->add($factory->createInput(array( | |
'name' => 'description', | |
'required' => false, | |
'filters' => array( | |
array('name' => 'StringTrim'), | |
), | |
'validators' => array( | |
array( | |
'name' => 'StringLength', | |
'options' => array( | |
'encoding' => 'UTF-8', | |
'min' => 1, | |
), | |
), | |
), | |
))); | |
$inputFilter->add($factory->createInput(array( | |
'name' => 'title', | |
'required' => true, | |
'filters' => array( | |
array('name' => 'StripTags'), | |
array('name' => 'StringTrim'), | |
), | |
'validators' => array( | |
array( | |
'name' => 'StringLength', | |
'options' => array( | |
'encoding' => 'UTF-8', | |
'min' => 1, | |
'max' => 255, | |
), | |
), | |
), | |
))); | |
$inputFilter->add($factory->createInput(array( | |
'name' => 'date', | |
'required' => true, | |
'filters' => array( | |
array('name' => 'StripTags'), | |
array('name' => 'StringTrim'), | |
), | |
'validators' => array( | |
array( | |
'name' => 'StringLength', | |
'options' => array( | |
'encoding' => 'UTF-8', | |
'min' => 1, | |
'max' => 255, | |
), | |
), | |
), | |
))); | |
$inputFilter->add($factory->createInput(array( | |
'name' => 'mainPhoto', | |
'required' => false, | |
'filters' => array( | |
array('name' => 'StripTags'), | |
array('name' => 'StringTrim'), | |
), | |
'validators' => array( | |
array( | |
'name' => 'StringLength', | |
'options' => array( | |
'encoding' => 'UTF-8', | |
'min' => 1, | |
'max' => 255, | |
), | |
), | |
), | |
))); | |
$this->inputFilter = $inputFilter; | |
} | |
return $this->inputFilter; | |
} | |
} |
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 Admin\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
// Doctrine\Common\Collections\ArrayCollection; | |
use Zend\InputFilter\Factory as InputFactory; | |
use Zend\InputFilter\InputFilter; | |
use Zend\InputFilter\InputFilterAwareInterface; | |
use Zend\InputFilter\InputFilterInterface; | |
/** | |
* Photo | |
* | |
* @ORM\Table(name="bnc_photo") | |
* @ORM\Entity | |
* @ORM\HasLifecycleCallbacks | |
*/ | |
class Photo implements InputFilterAwareInterface | |
{ | |
/** | |
* @var integer | |
* | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="IDENTITY") | |
*/ | |
private $id; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="description", type="text", nullable=true) | |
*/ | |
private $description; | |
/** | |
* @var string | |
* | |
* @ORM\Column(name="mainPhoto", type="string", nullable=false) | |
*/ | |
private $mainPhoto; | |
/** | |
* @var \DateTime | |
* | |
* @ORM\Column(name="date", type="datetime", nullable=false) | |
*/ | |
private $date; | |
/** | |
* Bidirectional - Many Photos are upload by one album (OWNING SIDE) | |
* | |
* @ORM\ManyToOne(targetEntity="Album", inversedBy="assignedPhotos") | |
*/ | |
private $album; | |
public function __get($property) | |
{ | |
return $this -> $property; | |
} | |
public function __set($property, $value) | |
{ | |
$this -> $property = $value; | |
} | |
//GET AND SETTERS | |
public function getId() | |
{ | |
return $this->id; | |
} | |
public function getDescription() | |
{ | |
return $this->description; | |
} | |
public function setDescription($description) | |
{ | |
$this->description = $description; | |
} | |
public function getMainPhoto() | |
{ | |
return $this->mainPhoto; | |
} | |
public function setMainPhoto($mainPhoto) | |
{ | |
$this->mainPhoto = $mainPhoto; | |
} | |
public function getDate() | |
{ | |
return $this->date; | |
} | |
public function setDate($date) | |
{ | |
$this->date = $date; | |
} | |
public function setAlbum($album) | |
{ | |
$album->assignedToPhoto($this); | |
$this->album = $album; | |
} | |
public function getAlbum() | |
{ | |
return $this->album; | |
} | |
/** | |
* Exchange array - used in ZF2 form | |
* | |
* @param array $data An array of data | |
*/ | |
public function exchangeArray($data) | |
{ | |
$this->id = (isset($data['id']))? $data['id'] : null; | |
$this->description = (isset($data['description']))? $data['description'] : null; | |
$this->tittle = (isset($data['tittle']))? $data['tittle'] : null; | |
$this->mainPhoto = (isset($data['mainPhoto']))? $data['mainPhoto'] : null; | |
$this->date = (isset($data['date']))? $data['date'] : null; | |
$this->album_id = (isset($data['album_id']))? $data['album_id'] : null; | |
} | |
/** | |
* Get an array copy of object | |
* | |
* @return array | |
*/ | |
public function getArrayCopy() | |
{ | |
return get_object_vars($this); | |
} | |
/** | |
* Set input method | |
* | |
* @param InputFilterInterface $inputFilter | |
*/ | |
public function setInputFilter(InputFilterInterface $inputFilter) | |
{ | |
throw new \Exception("Not used"); | |
} | |
/** | |
* Get input filter | |
* | |
* @return InputFilterInterface | |
*/ | |
public function getInputFilter() | |
{ | |
if (!$this->inputFilter) { | |
$inputFilter = new InputFilter(); | |
$factory = new InputFactory(); | |
$inputFilter->add($factory->createInput(array( | |
'name' => 'id', | |
'required' => false, | |
'filters' => array( | |
array('name' => 'Int'), | |
), | |
))); | |
$inputFilter->add($factory->createInput(array( | |
'name' => 'description', | |
'required' => true, | |
'filters' => array( | |
array('name' => 'StringTrim'), | |
), | |
'validators' => array( | |
array( | |
'name' => 'StringLength', | |
'options' => array( | |
'encoding' => 'UTF-8', | |
'min' => 1, | |
), | |
), | |
), | |
))); | |
$this->inputFilter = $inputFilter; | |
} | |
return $this->inputFilter; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment