Last active
August 29, 2015 14:25
-
-
Save fesor/db2dd19e71a40ed2297b to your computer and use it in GitHub Desktop.
This file contains 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 | |
class Photo | |
{ | |
/** | |
* @ORM\Id | |
* @ORM\GeneratedValue | |
* @ORM\Column(type="integer") | |
*/ | |
private $id; | |
/** | |
* @var File | |
* @ORM\Embedded(class="File") | |
*/ | |
private $image; | |
/** | |
* @var User | |
* @ORM\ManyToOne(targetEntity="User") | |
*/ | |
private $author; | |
/** | |
* @var Complaint[]|ArrayCollection | |
* @ORM\OneToMany(targetEntity="Complaint", mappedBy="photo", cascade={"persist", "remove"}) | |
*/ | |
private $complaints; | |
/** | |
* @var \DateTime | |
* @ORM\Column(type="datetime") | |
*/ | |
private $createdAt; | |
public function __construct(File $image, User $author) | |
{ | |
$this->image = $image; | |
$this->author = $author; | |
$this->compltaints = new ArrayCollection(); | |
$this->createdAt = new \DateTime(); | |
} | |
public function complain(User $user) { | |
// тут еще можно проверить не жаловался ли уже чувак но мне лень | |
$this->compltaints->add(new Complaint($this, $user)); | |
} | |
} |
This file contains 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 | |
class PhotoController extends Controller { | |
public function createAction(Request $request) { | |
// ... какие-то штуки для загрузки файлов и прочая чушь | |
$photo = new Photo($file, $this->getUser()); | |
$this->get('app.repository.photo')->add($photo); | |
return $photo // или что-то в этом духе | |
} | |
// парам конвертеры все за нас достанут по id-шке | |
public function compltainAction(Photo $photo) { | |
$photo->compltain($this->getUser()); | |
return $photo; | |
} | |
} |
This file contains 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 | |
class PhotoRepository | |
{ | |
private $em; | |
public function __construct(EntityManagerInterface $em) { | |
$this->em = $em; | |
} | |
public function add(Photo $photo) { | |
$this->em->persist($photo); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment