Created
August 14, 2015 14:07
-
-
Save ericktedeschi/ad3f8735eceb3a792193 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 Riskforge\Entities; | |
use Doctrine\ORM\Mapping as ORM; | |
use JMS\Serializer\Annotation as Serializer; | |
use Hateoas\Configuration\Annotation as Hateoas; | |
/** | |
* @Serializer\XmlRoot("asset") | |
* @Hateoas\Relation("self", href = "expr('/assets/' ~ object.getId())") | |
* | |
* @ORM\Entity(repositoryClass="AssetsRepository") | |
* @ORM\Table(name="assets") | |
* @ORM\HasLifecycleCallbacks | |
*/ | |
class Asset { | |
/** | |
* @Serializer\XmlAttribute | |
* @ORM\Id @ORM\Column(type="guid") | |
* @ORM\GeneratedValue(strategy="UUID") | |
* @var string | |
*/ | |
protected $id; | |
/** | |
* @ORM\Column(type="string"); | |
* @var string | |
*/ | |
protected $name; | |
/** | |
* @ORM\Column(type="string"); | |
* @var string | |
*/ | |
protected $description; | |
/** | |
* @ORM\Column(type="datetime") | |
* @return DateTime | |
*/ | |
protected $created; | |
/** | |
* @ORM\Column(type="datetime",nullable=true) | |
* @return DateTime | |
*/ | |
protected $updated; | |
function getId() { | |
return $this->id; | |
} | |
function getName() { | |
return $this->name; | |
} | |
function getDescription() { | |
return $this->description; | |
} | |
function getCreated() { | |
return $this->created; | |
} | |
function getUpdated() { | |
return $this->updated; | |
} | |
function setName($name) { | |
$this->name = $name; | |
} | |
function setDescription($description) { | |
$this->description = $description; | |
} | |
/** | |
* Gets triggered only on insert | |
* @ORM\PrePersist | |
*/ | |
function onPrePersist() { | |
$this->created = new \DateTime("now"); | |
} | |
/** | |
* Gets triggered every time on update | |
* @ORM\PreUpdate | |
*/ | |
function onPreUpdate() { | |
$this->updated = new \DateTime("now"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment