日历Symfony3不显示事件

时间:2016-05-04 13:58:11

标签: javascript php symfony

我使用Custom Adapter for List View

我将service.xml添加到AppBundle / Resources / service.xml

<services>
    <service id="appbundle.calendar_listener" class="AppBundle\CallendarEventListener">
        <argument type="service" id="doctrine.orm.entity_manager" />
        <tag name="kernel.event_listener" event="calendar.load_events" method="loadEvents" />
    </service>

</services>

然后创建一个新的实体

 use Doctrine\ORM\Mapping as ORM;
 use ADesigns\CalendarBundle\Entity\EventEntity as BaseEntity;
 /**
* Event
*
* @ORM\Table(name="event")
* @ORM\Entity(repositoryClass="AppBundle\Repository\EventRepository")
 */
 class Event extends BaseEntity
 {
/**
 * @var int
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;


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

}

 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')
        ->createQueryBuilder('company_events')
        ->where('company_events.event_datetime BETWEEN :startDateTime and :endDateTime')
        ->setParameter('startDateTime', $startDate->format('Y-m-d H:i:s'))
        ->setParameter('endDateTime', $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);

    }

}

}

我用日历输入我的路线,没有任何事件没有加载..什么是错的?

0 个答案:

没有答案