<commit_before><?php
/*
 * This file is part of the Artscore Studio Framework package.
 *
 * (c) 2012-2015 <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace ASF\SchedulerBundle\Event;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use ASF\CoreBundle\Model\Manager\ASFEntityManagerInterface;

/**
 * Calendar Subscriber
 * 
 * @author <NAME> <<EMAIL>>
 *
 */
class CalendarSubscriber implements EventSubscriberInterface
{
	/**
	 * @var ASFEntityManagerInterface
	 */
	protected $companyEventManager;
	
	/**
	 * @param ASFEntityManagerInterface $company_event_manager
	 */
	public function __construct(ASFEntityManagerInterface $company_event_manager)
	{
		$this->companyEventManager = $company_event_manager;
	}
	
	/**
	 * Subscribed Events
	 */
	public static function getSubscribedEvents()
	{
		return array(
			CalendarEvents::LOAD_EVENTS => array('onCalendarLoadEvents', 0),
			CalendarEvents::TOOLBAR => array('onCalendarToolbarEvent', 0)
		);
	}
	
	/**
	 * @param CalendarEvent $event
	 */
	public function onCalendarLoadEvents(CalendarEvent $calendar_event)
	{
		$start_date = $calendar_event->getStartDatetime();
		$end_date = $calendar_event->getEndDatetime();
		$request = $calendar_event->getRequest();
		$filter = $request->get('filter');
		
		// Get DVI Events
		$company_events = $this->companyEventManager->getRepository()
			->createQueryBuilder('e')
			->where('e.startedAt BETWEEN :startDate AND :endDate')
			->setParameter('startDate', $start_date->format('Y-m-d H:i:s'))
			->setParameter('endDate', $end_date->format('Y-m-d H:i:s'))
			->getQuery()->getResult();
		
		// Create Calendar Events
		foreach($company_events as $company_event){
			if ( $company_event->getIsAllDay() === false ) {
				$eventEntity = new EventEntity($company_event->getTitle(), $company_event->getStartedAt(), $dvi_event->getFinishedAt());
			} else {
				$eventEntity = new EventEntity($company_event->getTitle(), $company_event->getStartedAt(), null, true);
			}
			
			if ( !is_null($company_event->getCategory()) ) {
				$eventEntity->setBgColor($company_event->getCategory()->getBgColor());
				$eventEntity->setFgColor($company_event->getCategory()->getFgColor());
				$eventEntity->setCssClass($company_event->getCategory()->getCssClassName());
			}
			
			$calendar_event->addEvent($eventEntity);
		}
	}
	
	/**
	 * @param CalendarToolbarEvent $event
	 */
	public function onCalendarToolbarEvent(CalendarToolbarEvent $event)
	{
		$event->addButton('asf_scheduler_calendar_event_add', 'Add New Event');
	}
}<commit_msg>Update subscriber according to the CalendarEvent Entity<commit_after><?php
/*
 * This file is part of the Artscore Studio Framework package.
 *
 * (c) 2012-2015 <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace ASF\SchedulerBundle\Event;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use ASF\CoreBundle\Model\Manager\ASFEntityManagerInterface;

/**
 * Calendar Subscriber
 * 
 * @author <NAME> <<EMAIL>>
 *
 */
class CalendarSubscriber implements EventSubscriberInterface
{
	/**
	 * @var ASFEntityManagerInterface
	 */
	protected $eventEntityManager;
	
	/**
	 * @param ASFEntityManagerInterface $eventEntityManager
	 */
	public function __construct(ASFEntityManagerInterface $eventEntityManager)
	{
		$this->eventEntityManager = $eventEntityManager;
	}
	
	/**
	 * Subscribed Events
	 */
	public static function getSubscribedEvents()
	{
		return array(
			CalendarEvents::LOAD_EVENTS => array('onCalendarLoadEvents', 0),
			CalendarEvents::TOOLBAR => array('onCalendarToolbarEvent', 0)
		);
	}
	
	/**
	 * @param CalendarEvent $event
	 */
	public function onCalendarLoadEvents(CalendarEvent $calendar_event)
	{
		$start_date = $calendar_event->getStartDatetime();
		$end_date = $calendar_event->getEndDatetime();
		$request = $calendar_event->getRequest();
		$filter = $request->get('filter');
		
		// Get DVI Events
		$company_events = $this->eventEntityManager->getRepository()
			->createQueryBuilder('e')
			->where('e.startedAt BETWEEN :startDate AND :endDate')
			->setParameter('startDate', $start_date->format('Y-m-d H:i:s'))
			->setParameter('endDate', $end_date->format('Y-m-d H:i:s'))
			->getQuery()->getResult();
		
		// Create Calendar Events
		foreach($company_events as $company_event){
			$calendar_event->addEvent($company_event);
		}
	}
	
	/**
	 * @param CalendarToolbarEvent $event
	 */
	public function onCalendarToolbarEvent(CalendarToolbarEvent $event)
	{
		$event->addButton('asf_scheduler_calendar_event_add', 'Add New Event');
	}
}
{'fraction_non_alphanumeric': 0.13908822287885184, 'fraction_numerical': 0.004221190375685944, 'mean_word_length': 4.991150442477876, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5973838', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1422, 'n_words': 280}