Hello,
Thank you for this amazing bundle.
I Can't get events from the DB when i access fc-load-events, This is my EventEntity :
<?php
namespace CMRBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* RDV
*
* @ORM\Table(name="e_v_e_n_t")
* @ORM\Entity(repositoryClass="CMRBundle\Repository\EventRepository")
*/
class EventEntity
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255)
*/
protected $title;
/**
* @var string
*
* @ORM\Column(name="url", type="string", length=255)
*/
protected $url;
/**
* @var string
*
* @ORM\Column(name="bgcolor", type="string", length=255)
*/
protected $bgColor;
/**
* @var string
*
* @ORM\Column(name="fgcolor", type="string", length=255)
*/
protected $fgColor;
/**
* @var string
*
* @ORM\Column(name="cssclass", type="string", length=255)
*/
protected $cssClass;
/**
* @var \DateTime
*
* @ORM\Column(name="startdatetime", type="datetime")
*/
protected $startDatetime;
/**
* @var \DateTime
*
* @ORM\Column(name="enddatetime", type="datetime")
*/
protected $endDatetime;
/**
* @ORM\Column(name="allday", type="boolean")
*/
protected $allDay = false;
/**
* @var array
*
* @ORM\Column(name="otherfields", type="array")
*/
protected $otherFields = array();
public function __construct($title, \DateTime $startDatetime, \DateTime $endDatetime = null, $allDay = false)
{
$this->title = $title;
$this->startDatetime = $startDatetime;
$this->setAllDay($allDay);
if ($endDatetime === null && $this->allDay === false) {
throw new \InvalidArgumentException("Must specify an event End DateTime if not an all day event.");
}
$this->endDatetime = $endDatetime;
}
/**
* Convert calendar event details to an array
*
* @return array $event
*/
public function toArray()
{
$event = array();
if ($this->id !== null) {
$event['id'] = $this->id;
}
$event['title'] = $this->title;
$event['start'] = $this->startDatetime->format("Y-m-d\TH:i:sP");
if ($this->url !== null) {
$event['url'] = $this->url;
}
if ($this->bgColor !== null) {
$event['backgroundColor'] = $this->bgColor;
$event['borderColor'] = $this->bgColor;
}
if ($this->fgColor !== null) {
$event['textColor'] = $this->fgColor;
}
if ($this->cssClass !== null) {
$event['className'] = $this->cssClass;
}
if ($this->endDatetime !== null) {
$event['end'] = $this->endDatetime->format("Y-m-d\TH:i:sP");
}
$event['allDay'] = $this->allDay;
foreach ($this->otherFields as $field => $value) {
$event[$field] = $value;
}
return $event;
}
public function setId($id)
{
$this->id = $id;
}
public function getId()
{
return $this->id;
}
public function setTitle($title)
{
$this->title = $title;
}
public function getTitle()
{
return $this->title;
}
public function setUrl($url)
{
$this->url = $url;
}
public function getUrl()
{
return $this->url;
}
public function setBgColor($color)
{
$this->bgColor = $color;
}
public function getBgColor()
{
return $this->bgColor;
}
public function setFgColor($color)
{
$this->fgColor = $color;
}
public function getFgColor()
{
return $this->fgColor;
}
public function setCssClass($class)
{
$this->cssClass = $class;
}
public function getCssClass()
{
return $this->cssClass;
}
public function setStartDatetime(\DateTime $start)
{
$this->startDatetime = $start;
}
public function getStartDatetime()
{
return $this->startDatetime;
}
public function setEndDatetime(\DateTime $end)
{
$this->endDatetime = $end;
}
public function getEndDatetime()
{
return $this->endDatetime;
}
public function setAllDay($allDay = false)
{
$this->allDay = (boolean) $allDay;
}
public function getAllDay()
{
return $this->allDay;
}
/**
* @param string $name
* @param string $value
*/
public function addField($name, $value)
{
$this->otherFields[$name] = $value;
}
/**
* @param string $name
*/
public function removeField($name)
{
if (!array_key_exists($name, $this->otherFields)) {
return;
}
unset($this->otherFields[$name]);
}
/**
* Set otherFields
*
* @param array $otherFields
*
* @return EventEntity
*/
public function setOtherFields($otherFields)
{
$this->otherFields = $otherFields;
return $this;
}
/**
* Get otherFields
*
* @return array
*/
public function getOtherFields()
{
return $this->otherFields;
}
}
And this is my event listener :
<?php
namespace CMRBundle\EventListener;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\EntityManager;
use CMRBundle\Entity\EventEntity;
use ADesigns\CalendarBundle\Event\CalendarEvent;
class CalendarEventListener
{
private $entityManager;
public function __construct(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
}
public function loadEvents(CalendarEvent $calendarEvent)
{
$startDate = $calendarEvent->getStartDatetime();
$endDate = $calendarEvent->getEndDatetime();
// The original request so you can get filters from the calendar
// Use the filter in your query for example
$request = $calendarEvent->getRequest();
$filter = $request->get('filter');
// load events using your custom logic here,
// for instance, retrieving events from a repository
$companyEvents = $this->entityManager->getRepository('CMRBundle:EventEntity')
->createQueryBuilder('company_events')
->where('company_events.event_datetime BETWEEN :startDate and :endDate')
->setParameter('startDate', $startDate->format('Y-m-d H:i:s'))
->setParameter('endDate', $endDate->format('Y-m-d H:i:s'))
->getQuery()->getResult();
// $companyEvents and $companyEvent in this example
// represent entities from your database, NOT instances of EventEntity
// within this bundle.
//
// Create EventEntity instances and populate it's properties with data
// from your own entities/database values.
foreach($companyEvents as $companyEvent) {
// create an event with a start/end time, or an all day event
if ($companyEvent->getAllDayEvent() === false) {
$eventEntity = new EventEntity($companyEvent->getTitle(), $companyEvent->getStartDatetime(), $companyEvent->getEndDatetime());
} else {
$eventEntity = new EventEntity($companyEvent->getTitle(), $companyEvent->getStartDatetime(), null, true);
}
//optional calendar event settings
$eventEntity->setAllDay(true); // default is false, set to true if this is an all day event
$eventEntity->setBgColor('#FF0000'); //set the background color of the event's label
$eventEntity->setFgColor('#FFFFFF'); //set the foreground color of the event's label
$eventEntity->setUrl('http://www.google.com'); // url to send user to when event label is clicked
$eventEntity->setCssClass('my-custom-class'); // a custom class you may want to apply to event labels
//finally, add the event to the CalendarEvent for displaying on the calendar
$calendarEvent->addEvent($eventEntity);
}
}
}
AJAX Request works well.
Method Type Status URL Time Profile
POST xhr 200 fc-load-events 1191ms c16a22
This is the error i get :
if ($companyEvent->getAllDayEvent() === false) {
$eventEntity = new EventEntity($companyEvent->getTitle(), $companyEvent->getStartDatetime(), $companyEvent->getEndDatetime());
} else {
$eventEntity = new EventEntity($companyEvent->getTitle(), $companyEvent->getStartDatetime(), null, true);
}
All the methods in evententity are not found : getAllDayEvent(), getTitle(), getStartDatetime()
Hello, Thank you for this amazing bundle. I Can't get events from the DB when i access fc-load-events, This is my EventEntity :
And this is my event listener :
AJAX Request works well.
Method Type Status URL Time Profile POST xhr 200 fc-load-events 1191ms c16a22
This is the error i get :
All the methods in evententity are not found : getAllDayEvent(), getTitle(), getStartDatetime()
Thanks for your help.