Created
July 5, 2016 10:27
-
-
Save Albert221/7d3cdb298b8a89b27a185c9359e685ae 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 | |
namespace Albert221\LennyMemes\Entity; | |
use Doctrine\Common\Collections\ArrayCollection; | |
/** @Entity(repositoryClass="Albert221\LennyMemes\Repository\Database\MemeRepository") @Table(name="memes") */ | |
class Meme | |
{ | |
/** @Id @Column(type="integer") @GeneratedValue */ | |
private $id; | |
/** @Column */ | |
private $title; | |
/** @Column */ | |
private $imageUrl; | |
/** @Column(type="boolean", options={"default":true}) */ | |
private $pending; | |
/** @Column(type="datetime") */ | |
private $postedAt; | |
/** @OneToMany(targetEntity="Vote", mappedBy="meme", cascade={"persist"}) */ | |
private $votes; | |
public function __construct() | |
{ | |
$this->votes = new ArrayCollection; | |
} | |
public function accept() | |
{ | |
$this->pending = false; | |
} | |
public function getId() | |
{ | |
return $this->id; | |
} | |
public function getTitle() | |
{ | |
return $this->title; | |
} | |
public function setTitle($title) | |
{ | |
$this->title = $title; | |
} | |
public function getImageUrl() | |
{ | |
return $this->imageUrl; | |
} | |
public function setImageUrl($imageUrl) | |
{ | |
$this->imageUrl = $imageUrl; | |
} | |
public function isPending() | |
{ | |
return $this->pending; | |
} | |
public function setPending($pending) | |
{ | |
$this->pending = boolval($pending); | |
} | |
public function getPostedAt() | |
{ | |
return $this->postedAt; | |
} | |
public function setPostedAt(\DateTime $postedAt) | |
{ | |
$this->postedAt = $postedAt; | |
} | |
public function getVotes() | |
{ | |
return $this->votes; | |
} | |
public function addVote(Vote $vote) | |
{ | |
$this->votes[] = $vote; | |
} | |
public function getVotesResult() | |
{ | |
$result = 0; | |
foreach ($this->votes as $vote) { | |
if ($vote->getType()) { | |
$result++; | |
continue; | |
} | |
$result--; | |
} | |
return $result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment