I have some entities created by Doctrine. One of them is Timeslot, here is a table definition
TABLE: Timeslot
id integer primary key
start integer
end integer
I want to extend the Timeslot entity class with some helper methods such as
public class TimeslotHelper extends Timeslot
{
public function getStartDay(){
return $this->$start_time / (24*60);
}
public function getStartHour(){
return $this->$end_time % (24*60);
}
public function getStartMinutes(){
return $this->$start_time % 60;
}
...
}
I get all instances of Timeslot using
$timeslots = $this->getDoctrine()->getRepository('AppBundle:Timeslot')->find...
But I do not want to modify the autonomous-generated doctrine file , and I would like to use it as:
$timeslots = $this->getDoctrine()->getRepository('AppBundle:TimeslotHelper')->find...
Only extending the Timeslot class, I have this error (because the object is not displayed correctly):
No mapping file found named '/home/otacon/PhpstormProjects/Web/src/AppBundle/Resources/config/doctrine/TimeslotHelper.orm.xml' for class 'AppBundle\Entity\TimeslotHelper'.
Any clues?
DECISION
Superslot TimeslotHelper
abstract class TimeslotHelper {
abstract protected function getStart();
abstract protected function getEnd();
public function getStartDay(){
return floor($this->getStart() / (24*60));
}
public function getEndDay(){
return floor($this->getEnd() / (24*60));
}
public function getStartHour(){
return floor(($this->getStart() % (24*60)) / 60);
}
public function getEndHour(){
return floor(($this->getEnd() % (24*60)) / 60);
}
public function getStartMinute(){
return $this->getStart() % 60;
}
public function getEndMinute(){
return $this->getEnd() % 60;
}
}
Temporary subclass
class Timeslot extends TimeslotHelper
{
private $start;
private $end;
private $id;
public function setStart($start)
{
$this->start = $start;
return $this;
}
public function getStart()
{
return $this->start;
}
public function setEnd($end)
{
$this->end = $end;
return $this;
}
public function getEnd()
{
return $this->end;
}
public function getId()
{
return $this->id;
}
}
source
share