<commit_before><?php
// src/AppBundle/EventListener/CalendarEventListener.php

namespace AppBundle\EventListener;

use ADesigns\CalendarBundle\Event\CalendarEvent;
use ADesigns\CalendarBundle\Entity\EventEntity;
use AppBundle\Entity\Event;
use AppBundle\Repository\EventRepository;
use Doctrine\ORM\EntityManager;
use libphonenumber\PhoneNumberUtil;

class CalendarEventListener
{
    private $entityManager;
    private $phoneNumberUtil;

    public function __construct(EntityManager $entityManager, PhoneNumberUtil $phoneNumberUtil)
    {
        $this->entityManager = $entityManager;
        $this->phoneUtil = $phoneNumberUtil;
    }

    public function loadEvents(CalendarEvent $calendarEvent)
    {

        // The original request so you can get filters from the calendar
        // Use the filter in your query for example
        $request = $calendarEvent->getRequest();
        $isEmploye = $request->get('isEmploye');
        $selectedEmploye = $request->get('employe');

        if ($selectedEmploye != 'all') {
            $selectedEmploye = $this->entityManager->getRepository('AppBundle:Employe')->find($selectedEmploye);
        }

        $isClient = $request->get('isClient');
        if ($isSchedule = $request->get('isSchedule')) {

            if ($request->get('schedule')) {
                // Load edited schedule
                $schedule = $this->entityManager->getRepository('AppBundle:Schedule')->find($request->get('schedule'));
            } else {
                // New schedule
                $isSchedule = false;
            }
        }

        // load events using your custom logic here,
        // for instance, retrieving events from a repository
        //
        // Create EventEntity instances and populate it's properties with data
        // from your own entities/database values.

        // Build array with schedule blocks
        if ($isSchedule) {
            $scheduleBlock = $this->entityManager->getRepository('AppBundle:ScheduleBlock')->findScheduleBlocks($schedule);

            foreach ($scheduleBlock as $block) {
                $blockEvent = new EventEntity("Plage horaire", new \DateTime($block->getDateFrom()->format("Y-m-d H:i:s")), new \DateTime($block->getDateTo()->format("Y-m-d H:i:s")));
                $calendarEvent->addEvent($blockEvent);
            }
        }

        // Build array with empty schedule slots
        if ($isClient) {

            $startDate = $calendarEvent->getStartDatetime();
            $endDate = $calendarEvent->getEndDatetime();

            $interval = $startDate->diff($endDate->modify('+1 days'));
            $dayRange = $interval->format('%a');

            $blockPerDays = 12;

            $dayStartTime = new \DateTime($startDate->format("Y-m-d H:i:s"));
            $dayStartTime->setTime(06, 00, 00);

            for($i = 0; $i < $dayRange; $i++) {

                $eventStart = new \DateTime($dayStartTime->format("Y-m-d H:i:s"));
                $eventEnd = new \DateTime($dayStartTime->format("Y-m-d H:i:s"));

                for($y = 0; $y <= $blockPerDays; $y++) {
                    $blockEvents[] = new EventEntity("Libre " . $i . $y, new \DateTime($eventStart->format("Y-m-d H:i:s")), new \DateTime($eventEnd->modify('+1 hour')->format("Y-m-d H:i:s")));
                    $eventStart->modify('+1 hour');
                }

                $dayStartTime->modify('+1 days');
            }

            foreach ($blockEvents as $blockEvent) {
                unset($companyEvent);
                unset($startTime);
                unset($endTime);

                $eventClass = 'available';

                $startTime = new \DateTime($blockEvent->getStartDatetime()->format("Y-m-d H:i:s"));
                $endTime = new \DateTime($blockEvent->getEndDateTime()->format("Y-m-d H:i:s"));

                $companyEvent = $this->entityManager->getRepository('AppBundle:Event')->findOneByEmployeBetweenDate($selected_employe, $startTime, $endTime);

                if (is_object($companyEvent) && $companyEvent instanceof Event) {
                    $blockEvent->setTitle(utf8_encode('Rserv'));

                    if ($companyEvent->getEmploye()->getId() == 2) {
                        $eventClass = 'unavailable julee-unavailable';
                    } else {
                        $eventClass = 'unavailable simon-unavailable';
                    }
                }

                //optional calendar event settings
                $blockEvent->setAllDay(false); // default is false, set to true if this is an all day event
                $blockEvent->setBgColor($eventClass); //set the background color of the event's label
                $blockEvent->setFgColor('#FFFFFF'); //set the foreground color of the event's label
                #$blockEvent->setUrl('http://www.google.com'); // url to send user to when event label is clicked
                $blockEvent->setCssClass($eventClass); // 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($blockEvent);
            }
        }

        // Build array with empty schedule slots<commit_msg>Change visual of scheduleBlock events<commit_after><?php
// src/AppBundle/EventListener/CalendarEventListener.php

namespace AppBundle\EventListener;

use ADesigns\CalendarBundle\Event\CalendarEvent;
use ADesigns\CalendarBundle\Entity\EventEntity;
use AppBundle\Entity\Event;
use AppBundle\Repository\EventRepository;
use Doctrine\ORM\EntityManager;
use libphonenumber\PhoneNumberUtil;

class CalendarEventListener
{
    private $entityManager;
    private $phoneNumberUtil;

    public function __construct(EntityManager $entityManager, PhoneNumberUtil $phoneNumberUtil)
    {
        $this->entityManager = $entityManager;
        $this->phoneUtil = $phoneNumberUtil;
    }

    public function loadEvents(CalendarEvent $calendarEvent)
    {

        // The original request so you can get filters from the calendar
        // Use the filter in your query for example
        $request = $calendarEvent->getRequest();
        $isEmploye = $request->get('isEmploye');
        $selectedEmploye = $request->get('employe');

        if ($selectedEmploye != 'all') {
            $selectedEmploye = $this->entityManager->getRepository('AppBundle:Employe')->find($selectedEmploye);
        }

        $isClient = $request->get('isClient');
        if ($isSchedule = $request->get('isSchedule')) {

            if ($request->get('schedule')) {
                // Load edited schedule
                $schedule = $this->entityManager->getRepository('AppBundle:Schedule')->find($request->get('schedule'));
            } else {
                // New schedule
                $isSchedule = false;
            }
        }

        // load events using your custom logic here,
        // for instance, retrieving events from a repository
        //
        // Create EventEntity instances and populate it's properties with data
        // from your own entities/database values.

        // Build array with schedule blocks
        if ($isSchedule) {
            $scheduleBlock = $this->entityManager->getRepository('AppBundle:ScheduleBlock')->findScheduleBlocks($schedule);

            foreach ($scheduleBlock as $block) {
                $blockEvent = new EventEntity("Plage horaire", new \DateTime($block->getDateFrom()->format("Y-m-d H:i:s")), new \DateTime($block->getDateTo()->format("Y-m-d H:i:s")));

                //optional calendar event settings
                $blockEvent->setAllDay(false); // default is false, set to true if this is an all day event
                $blockEvent->setBgColor('green'); //set the background color of the event's label
                $blockEvent->setFgColor('#FFFFFF'); //set the foreground color of the event's label
                #$blockEvent->setUrl('http://www.google.com'); // url to send user to when event label is clicked
                $blockEvent->setCssClass(''); // a custom class you may want to apply to event labels

                $calendarEvent->addEvent($blockEvent);
            }
        }

        // Build array with empty schedule slots
        if ($isClient) {

            $startDate = $calendarEvent->getStartDatetime();
            $endDate = $calendarEvent->getEndDatetime();

            $interval = $startDate->diff($endDate->modify('+1 days'));
            $dayRange = $interval->format('%a');

            $blockPerDays = 12;

            $dayStartTime = new \DateTime($startDate->format("Y-m-d H:i:s"));
            $dayStartTime->setTime(06, 00, 00);

            for($i = 0; $i < $dayRange; $i++) {

                $eventStart = new \DateTime($dayStartTime->format("Y-m-d H:i:s"));
                $eventEnd = new \DateTime($dayStartTime->format("Y-m-d H:i:s"));

                for($y = 0; $y <= $blockPerDays; $y++) {
                    $blockEvents[] = new EventEntity("Libre " . $i . $y, new \DateTime($eventStart->format("Y-m-d H:i:s")), new \DateTime($eventEnd->modify('+1 hour')->format("Y-m-d H:i:s")));
                    $eventStart->modify('+1 hour');
                }

                $dayStartTime->modify('+1 days');
            }

            foreach ($blockEvents as $blockEvent) {
                unset($companyEvent);
                unset($startTime);
                unset($endTime);

                $eventClass = 'available';

                $startTime = new \DateTime($blockEvent->getStartDatetime()->format("Y-m-d H:i:s"));
                $endTime = new \DateTime($blockEvent->getEndDateTime()->format("Y-m-d H:i:s"));

                $companyEvent = $this->entityManager->getRepository('AppBundle:Event')->findOneByEmployeBetweenDate($selected_employe, $startTime, $endTime);

                if (is_object($companyEvent) && $companyEvent instanceof Event) {
                    $blockEvent->setTitle(utf8_encode('R�serv�'));

                    if ($companyEvent->getEmploye()->getId() == 2) {
                        $eventClass = 'unavailable julee-unavailable';
                    } else {
                        $eventClass = 'unavailable simon-unavailable';
                    }
                }

                //optional calendar event settings
                $blockEvent->setAllDay(false); // default is false, set to true if this is an all day event
                $blockEvent->setBgColor($eventClass); //set the background color of the event's label
                $blockEvent->setFgColor('#FFFFFF'); //set the foreground color of the event's label
                #$blockEvent->setUrl('http://www.google.com'); // url to send user to when event label is clicked
                $blockEvent->setCssClass($eventClass); // 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($blockEvent);
            }
        }

        // Build array with empty schedule slots
{'fraction_non_alphanumeric': 0.13213865508190786, 'fraction_numerical': 0.002896189700425378, 'mean_word_length': 2.2215743440233235, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 114, 'https://': 0, 'lorem ipsum': 0, 'www.': 3, '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': '5103075', 'n_tokens_mistral': 3009, 'n_tokens_neox': 2816, 'n_words': 682}