Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Load Event from database? #47

Open
Pablossoo opened this issue May 4, 2016 · 3 comments
Open

Load Event from database? #47

Pablossoo opened this issue May 4, 2016 · 3 comments

Comments

@Pablossoo
Copy link

Hello, I was do all steps like as in guide and what next i have to doing? In database I have one event.
I enter my route with callendar, but events not loaded

CallendarEventListener is AppBundle/CallendarEventListener.php

class CallendarEventListener
{

    private $entityManager;

    public function __construct(EntityManager $entityManager)
    {
        $this->entityManager = $entityManager;
    }

    /**
     * @param CalendarEvent $calendarEvent

     */
    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('AppBundle:Event') // my Entity
            ->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);

        }

    }
@gerardossxd1995
Copy link

Can you post your Entity?
I think you have misconfigured your Entity

@Mistwostem
Copy link

Hi i have the same problem @gerardossxd1995 , could you help me? (the topic is a bit old but i hope you'll have the time to help me)

There is the entity code that i took from a stackoverflow issue :

https://stackoverflow.com/questions/37980272/extending-adesigns-evententity-class

My Entity Code :

<?php

namespace Permisfute\PermisfuteBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use ADesigns\CalendarBundle\Entity\EventEntity;

/**
 * LeconEvent
 *
 * @ORM\Table(name="lecon_event")
 * @ORM\Entity(repositoryClass="Permisfute\PermisfuteBundle\Repository\LeconEventRepository")
 */

class LeconEvent extends 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, nullable=true)
     */
    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, nullable=true)
     */
    protected $cssClass;

    /**
     * @var  bool
     * @ORM\Column(name="allDay", type="boolean")
     */
    protected $allDay;

    /**
     * @var  DateTime
     * @ORM\Column(name="startDatetime", type="datetime")
     */
    protected $startDatetime;

    /**
     * @var  DateTime
     * @ORM\Column(name="endDatetime", type="datetime")
     */
    protected $endDatetime;

    public function __construct($title, \DateTime $startDatetime, \DateTime $endDatetime = null, $allDay = false, $hall) {
        parent::__construct($title, $startDatetime, $endDatetime, $allDay);
        $this->hall = $hall;
    }

    /**
     * Get id
     *
     * @return int
     */
    public function getId() {
        return $this->id;
    }
}

The thing is when im loading the page, the calendar displays itself nicely but i cant click to load events, when i go into the symfony profiler, ive got this error :

[Semantical Error] line 0, col 109 near 'event_datetime': Error: Class Permisfute\PermisfuteBundle\Entity\LeconEvent has no field or association named event_datetime

It appears that the : company_events.event_datetime from the loadEvent function in the CalendarListener is not working.

Do you have any ideas?

Thanks in advance for your help!

@osshelouis
Copy link

I did extend the classes and it doesnt show any problems.

However since my variables are slightly different, I override the "toArray()" function and created a constructor with a parameter.

My suggestion is if you have any errors, you can have a look at your entity class, the calendar listeners, calendar-settings.js and maybe the services.yml

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants