Introduced a BaseEntity for more easy access to all the properties.

This commit is contained in:
Tim Schumacher 2014-07-19 09:25:09 +02:00
parent e3ca015608
commit 12e7dafe0d
5 changed files with 97 additions and 372 deletions

View file

@ -0,0 +1,58 @@
<?php
/**
* Created by PhpStorm.
* User: tim
* Date: 13.07.14
* Time: 13:55
*/
namespace Hackspace\Bundle\CalciferBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\PersistentCollection;
/**
* @ORM\MappedSuperclass
*/
abstract class BaseEntity {
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="slug", type="string", length=255,options={"default" = ""})
*/
protected $slug = '';
public function __isset($name) {
if (property_exists($this,$name)) {
return true;
} else {
return false;
}
}
public function __get($name) {
if (property_exists($this,$name)) {
return $this->$name;
} else {
throw new \Exception("Property {$name} does not Exists");
}
}
public function __set($name,$value) {
if (property_exists($this,$name)) {
$this->$name = $value;
return $this;
} else {
throw new \Exception("Property {$name} does not Exists");
}
}
}

View file

@ -11,51 +11,42 @@ use Doctrine\ORM\PersistentCollection;
* @ORM\Table(name="events")
* @ORM\Entity
*/
class Event
class Event extends BaseEntity
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var \DateTime
*
* @ORM\Column(name="startdate", type="datetimetz")
*/
private $startdate;
protected $startdate;
/**
* @var \DateTime
*
* @ORM\Column(name="enddate", type="datetimetz", nullable=true)
*/
private $enddate;
protected $enddate;
/**
* @var string
*
* @ORM\Column(name="summary", type="string", length=255)
*/
private $summary;
protected $summary;
/**
* @var string
*
* @ORM\Column(name="description", type="text", nullable=true)
*/
private $description;
protected $description;
/**
* @var string
*
* @ORM\Column(name="locations_id", type="integer", nullable=true)
*/
private $locations_id;
protected $locations_id;
/**
* @var Location
@ -63,14 +54,14 @@ class Event
* @ORM\ManyToOne(targetEntity="Location")
* @ORM\JoinColumn(name="locations_id", referencedColumnName="id")
*/
private $location;
protected $location;
/**
* @var string
*
* @ORM\Column(name="url", type="string", length=255, nullable=true)
*/
private $url;
protected $url;
/**
* @var array
@ -81,179 +72,7 @@ class Event
* inverseJoinColumns={@ORM\JoinColumn(name="tags_id", referencedColumnName="id")}
* )
*/
private $tags = [];
/**
* @var string
*
* @ORM\Column(name="slug", type="string", length=255,options={"default" = ""})
*/
private $slug = '';
/**
* @param string $slug
*/
public function setSlug($slug)
{
$this->slug = $slug;
}
/**
* @return string
*/
public function getSlug()
{
return $this->slug;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set startdate
*
* @param \DateTime $startdate
* @return Event
*/
public function setStartdate($startdate)
{
$this->startdate = $startdate;
return $this;
}
/**
* Get startdate
*
* @return \DateTime
*/
public function getStartdate()
{
return $this->startdate;
}
/**
* Set enddate
*
* @param \DateTime $enddate
* @return Event
*/
public function setEnddate($enddate)
{
$this->enddate = $enddate;
return $this;
}
/**
* Get enddate
*
* @return \DateTime
*/
public function getEnddate()
{
return $this->enddate;
}
/**
* Set summary
*
* @param string $summary
* @return Event
*/
public function setSummary($summary)
{
$this->summary = $summary;
return $this;
}
/**
* Get summary
*
* @return string
*/
public function getSummary()
{
return $this->summary;
}
/**
* Set description
*
* @param string $description
* @return Event
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Set location
*
* @param string $locations_id
* @return Event
*/
public function setLocationsID($locations_id)
{
$this->locations_id = $locations_id;
return $this;
}
/**
* Get location
*
* @return string
*/
public function getLocationsID()
{
return $this->locations_id;
}
/**
* Set url
*
* @param string $url
* @return Event
*/
public function setUrl($url)
{
$this->url = $url;
return $this;
}
/**
* Get url
*
* @return string
*/
public function getUrl()
{
return $this->url;
}
protected $tags = [];
/**
* @param \Hackspace\Bundle\CalciferBundle\Entity\Location $location
@ -303,7 +122,7 @@ class Event
if (count($this->tags) > 0) {
$tags = [];
foreach ($this->tags as $tag) {
$tags[] = $tag->getName();
$tags[] = $tag->name;
}
return implode(',',$tags);
} else {

View file

@ -10,138 +10,28 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Table(name="locations")
* @ORM\Entity
*/
class Location
class Location extends BaseEntity
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
protected $name;
/**
* @var float
*
* @ORM\Column(name="lon", type="float", nullable=true)
*/
private $lon;
protected $lon;
/**
* @var float
*
* @ORM\Column(name="lat", type="float", nullable=true)
*/
private $lat;
/**
* @var string
*
* @ORM\Column(name="slug", type="string", length=255,options={"default" = ""})
*/
private $slug = '';
/**
* @param string $slug
*/
public function setSlug($slug)
{
$this->slug = $slug;
}
/**
* @return string
*/
public function getSlug()
{
return $this->slug;
}
protected $lat;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Location
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set lon
*
* @param float $lon
* @return Location
*/
public function setLon($lon)
{
$this->lon = $lon;
return $this;
}
/**
* Get lon
*
* @return float
*/
public function getLon()
{
return $this->lon;
}
/**
* Set lat
*
* @param float $lat
* @return Location
*/
public function setLat($lat)
{
$this->lat = $lat;
return $this;
}
/**
* Get lat
*
* @return float
*/
public function getLat()
{
return $this->lat;
}
}

View file

@ -0,0 +1,23 @@
<?php
namespace Hackspace\Bundle\CalciferBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\PersistentCollection;
/**
* RepeatEvent
*
* @ORM\Table(name="repeat_events")
* @ORM\Entity
*/
class RepeatEvent extends Event
{
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $repeat_pattern = '';
}

View file

@ -10,77 +10,12 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Table(name="tags")
* @ORM\Entity
*/
class Tag
class Tag extends BaseEntity
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="slug", type="string", length=255,options={"default" = ""})
*/
private $slug = '';
/**
* @param string $slug
*/
public function setSlug($slug)
{
$this->slug = $slug;
}
/**
* @return string
*/
public function getSlug()
{
return $this->slug;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Tag
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
protected $name;
}