From 7d9f02f542a83c284f37e2e2ce5b50349bc05221 Mon Sep 17 00:00:00 2001 From: Polonkai Gergely Date: Tue, 31 Jul 2012 11:09:52 +0200 Subject: [PATCH] Added Event listing and Event box Signed-off-by: Gergely Polonkai --- app/Resources/views/Box/Events.html.twig | 75 ++++ app/Resources/views/main_template.html.twig | 11 + .../Controller/EventController.php | 75 ++++ src/KekRozsak/FrontBundle/Entity/Event.php | 402 ++++++++++++++++++ .../FrontBundle/Resources/config/services.xml | 5 + .../Resources/views/Event/list.html.twig | 16 + .../Resources/views/Event/view.html.twig | 21 + .../FrontBundle/Twig/EventsExtension.php | 67 +++ web/css/kekrozsak_front.css | 46 ++ 9 files changed, 718 insertions(+) create mode 100644 app/Resources/views/Box/Events.html.twig create mode 100644 src/KekRozsak/FrontBundle/Controller/EventController.php create mode 100644 src/KekRozsak/FrontBundle/Entity/Event.php create mode 100644 src/KekRozsak/FrontBundle/Resources/views/Event/list.html.twig create mode 100644 src/KekRozsak/FrontBundle/Resources/views/Event/view.html.twig create mode 100644 src/KekRozsak/FrontBundle/Twig/EventsExtension.php diff --git a/app/Resources/views/Box/Events.html.twig b/app/Resources/views/Box/Events.html.twig new file mode 100644 index 0000000..80b3adc --- /dev/null +++ b/app/Resources/views/Box/Events.html.twig @@ -0,0 +1,75 @@ +{# vim: ft=htmljinja +#} +
+ [események gomb] +
+
+

{{ firstDay|date('Y-m') }}

+ + + + + + + + + + + + + + + + +{% set curDow = 0 %} +{% if firstDayWeekday != 1 %} +{% for i in 1..(firstDayWeekday - 1) %} +{% set curDow = curDow + 1 %}{% if curDow == 8 %}{% set curDow = 1 %}{% endif %} + +{% endfor %} +{% endif %} +{% set cur = firstDayWeekday - 1 %} +{% for i in 1..numDays %} +{% set cur = cur + 1 %} +{% set curDow = curDow + 1 %}{% if curDow == 8 %}{% set curDow = 1 %}{% endif %} +{% set eventCount = 0 %} +{# TODO Check if an event occurs on this date: +(event.startDate = this day AND event.endDate is NULL) +OR (event.startDate <= this day AND evend.endDate >= this day) +#} + +{% if cur is divisibleby(7) %} + +{% if cur != numDays %} + + +{% endif %} +{% endif %} +{% endfor %} +{% if curDow != 7 %} +{% for i in (curDow + 1)..7 %} + +{% endfor %} +{% endif %} + + +
HKSzeCsPSzoV
{{ firstDay|date('W') }} 0 %} class="program"{% endif %}> + {{ eventList[i].date|date('d') }} +{% if eventList[i].events|length > 0 %} + +{% endif %} +
{{ eventList[i + 1].date|date('W') }}
+ További események +
+
+
diff --git a/app/Resources/views/main_template.html.twig b/app/Resources/views/main_template.html.twig index 8b61aac..592635b 100644 --- a/app/Resources/views/main_template.html.twig +++ b/app/Resources/views/main_template.html.twig @@ -19,6 +19,7 @@
{% if app.user %} {% include ':Box:UserProfile.html.twig' %} +{% include ':Box:Events.html.twig' %} {% else %} {% include ':Box:Login.html.twig' %} {% endif %} @@ -91,6 +92,16 @@ delay: 0, fade: 250 }); + $('#esemeny-mutato').click(function() { + if ($('#esemeny-box').is(':visible')) + { + $('#esemeny-box').hide(); + } + else + { + $('#esemeny-box').show(); + } + }); {% else %} $('#login-mutato').click(function() { if ($('#login-box').is(':visible')) diff --git a/src/KekRozsak/FrontBundle/Controller/EventController.php b/src/KekRozsak/FrontBundle/Controller/EventController.php new file mode 100644 index 0000000..af99e15 --- /dev/null +++ b/src/KekRozsak/FrontBundle/Controller/EventController.php @@ -0,0 +1,75 @@ +getGroup() !== null) + { + if (!$event->getGroup()->isMember($this->get('security.context')->getToken()->getUser())) + throw new AccessDeniedException('Ehhez az eseményhez nem csatlakozhatsz, mivel a csoportjának nem vagy tagja.'); + } + + return array( + 'event' => $event, + ); + } + + /** + * @Route("/esemeny/{startDate}/{eventSlug}/csatlakozas", name="KekRozsakFrontBundle_eventJoin") + * @Template() + * @ParamConverter("event", class="KekRozsakFrontBundle:Event", options={"mapping"={"eventSlug"="slug", "startDate"="startDate"}}) + * @ParamConverter("startDate", class="DateTime", options={"format"="Y-m-d"}) + */ + public function joinAction(\DateTime $startDate, Event $event) + { + if ($event->getGroup() !== null) + { + if (!$event->getGroup()->isMember($this->get('security.context')->getToken()->getUser())) + throw new AccessDeniedException('Ehhez az eseményhez nem csatlakozhatsz, mivel a csoportjának nem vagy tagja.'); + } + + $event->addAttendee($this->get('security.context')->getToken()->getUser()); + + $em = $this->getDoctrine()->getEntityManager(); + $em->persist($event); + $em->flush(); + + return $this->redirect($this->generateUrl('KekRozsakFrontBundle_eventView', array( + 'eventDate' => $eventDate, + 'eventSlug' => $eventSlug, + ))); + } + + /** + * @Route("/esemenyek/{date}", name="KekRozsakFrontBundle_eventList") + * @Template() + * @ParamConverter("date", class="DateTime", options={"format": "Y-m-d"}) + */ + public function listAction(\DateTime $date) + { + $query = $this->getDoctrine()->getEntityManager()->createQuery('SELECT e FROM KekRozsakFrontBundle:Event e WHERE e.cancelled = FALSE AND ((e.startDate < :day AND e.endDate >= :day) OR e.startDate = :day)'); + $query->setParameter('day', $date, \Doctrine\DBAL\Types\Type::DATE); + $events = $query->getResult(); + + return array( + 'day' => $date, + 'events' => $events, + ); + } +} diff --git a/src/KekRozsak/FrontBundle/Entity/Event.php b/src/KekRozsak/FrontBundle/Entity/Event.php new file mode 100644 index 0000000..7a0580b --- /dev/null +++ b/src/KekRozsak/FrontBundle/Entity/Event.php @@ -0,0 +1,402 @@ +id; + } + + /** + * @var KekRozsak\SecurityBundle\Entity\User $createdBy + * + * @ORM\ManyToOne(targetEntity="KekRozsak\SecurityBundle\Entity\User") + * @ORM\JoinColumn(name="created_by_id") + */ + protected $createdBy; + + /** + * Set createdBy + * + * @param KekRozsak\SecurityBundle\Entity\User $createdBy + * @return Event + */ + public function setCreatedBy(\KekRozsak\SecurityBundle\Entity\User $createdBy) + { + $this->createdBy = $createdBy; + return $this; + } + + /** + * Get createdBy + * + * @return KekRozsak\SecurityBundle\Entity\User + */ + public function getCreatedBy() + { + return $this->createdBy; + } + + /** + * @var DateTime $startDate + * + * @ORM\Column(type="date", nullable=true, name="start_date", nullable=false) + */ + protected $startDate; + + /** + * Set startDate + * + * @param DateTime $startDate + * @return Event + */ + public function setStartDate(\DateTime $startDate = null) + { + $this->startDate = $startDate; + return $this; + } + + /** + * Get startDate + * + * @return DateTime + */ + public function getStartDate() + { + return $this->startDate; + } + + /** + * @var DateTime $endDate + * + * @ORM\Column(type="date", nullable=true, name="end_date") + */ + protected $endDate; + + /** + * Set endDate + * + * @param DateTime $endDate + * @return Event + */ + public function setEndDate(\DateTime $endDate) + { + $this->endDate = $endDate; + return $this; + } + + /** + * Get endDate + * + * @return DateTime + */ + public function getEndDate() + { + return $this->endDate; + } + + /** + * @var Doctrine\Common\Collections\ArrayCollection $attendees + * + * @ORM\ManyToMany(targetEntity="KekRozsak\SecurityBundle\Entity\User") + * @ORM\JoinTable(name="event_attendees") + */ + protected $attendees; + + /** + * Add attendee + * + * @param KekRozsak\SecurityBundle\Entity\User $attendee + * @return Event + */ + public function addAttendee(\KekRozsak\SecurityBundle\Entity\User $attendee) + { + $this->attendees[] = $attendee; + return $this; + } + + /** + * Get all attendees + * + * @return Doctrine\Common\Collections\ArrayCollection + */ + public function getAttendees() + { + return $this->attendees; + } + + /** + * Check if a user is attending + * + * @param KekRozsak\SecurityBundle\Entity\User $user + * @return boolean + */ + public function isAttending(\KekRozsak\SecurityBundle\Entity\User $user) + { + $users = $this->attendees->filter(function ($attendee) use ($user) { + if ($attendee == $user) + return true; + }); + + return ($users->count() != 0); + } + + /** + * @var string $title + * + * @ORM\Column(type="string", length=150) + * + * @Assert\NotBlank() + */ + protected $title; + + /** + * Set title + * + * @param string $title + * @return Event + */ + public function setTitle($title) + { + $this->title = $title; + return $this; + } + + /** + * Get title + * + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @var string $slug + * + * @ORM\Column(type="string", length=150) + * + * @Assert\NotBlank() + */ + protected $slug; + + /** + * Set slug + * + * @param string $slug + * @return Event + */ + public function setSlug($slug) + { + $this->slug = $slug; + return $this; + } + + /** + * Get slug + * + * @return string + */ + public function getSlug() + { + return $this->slug; + } + + /** + * @var string $description + * + * @ORM\Column(type="text") + * + * @Assert\NotBlank() + */ + protected $description; + + /** + * Set description + * + * @param string $description + * @return Event + */ + public function setDescription($description) + { + $this->description = $description; + return $this; + } + + /** + * Get description + * + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @var KekRozsak\FrontBundle\Entity\Group $group + * + * @ORM\ManyToOne(targetEntity="KekRozsak\FrontBundle\Entity\Group") + */ + protected $group; + + /** + * Set group + * + * @param KekRozsak\FrontBundle\Entity\Group $group + * @return Event + */ + public function setGroup(\KekRozsak\FrontBundle\Entity\Group $group = null) + { + $this->group = $group; + return $this; + } + + /** + * Get group + * + * @return KekRozsak\FrontBundle\Entity\Group + */ + public function getGroup() + { + return $this->group; + } + + /** + * @var boolean $cancelled + * + * @ORM\Column(type="boolean", nullable=false) + */ + protected $cancelled; + + /** + * Set cancelled + * + * @param boolean $cancelled + * @return Event + */ + public function setCancelled($cancelled = false) + { + $this->cancelled = $cancelled; + return $this; + } + + /** + * Get cancelled + * + * @return boolean + */ + public function getCancelled() + { + return $this->cancelled; + } + + /** + * @var DateTime $startTime + * + * @ORM\Column(type="time", nullable=false, name="start_time") + */ + protected $startTime; + + /** + * Set startTime + * + * @param DateTime $startTime + * @return Event + */ + public function setStartTime(\DateTime $startTime) + { + $this->startTime = $startTime; + return $this; + } + + /** + * Get startTime + * + * @return DateTime + */ + public function getStartTime() + { + return $this->startTime; + } + + /** + * @var DateTime $endTime + * + * @ORM\Column(type="time", nullable=true, name="end_time") + */ + protected $endTime; + + /** + * Set endTime + * + * @param DateTime $endTime + * @return Event + */ + public function setEndTime(\DateTime $endTime) + { + $this->endTime = $endTime; + return $this; + } + + /** + * Get endTime + * + * @return DateTime + */ + public function getEndTime() + { + return $this->endTime; + } + + /** + * Check if an event will go on a specific date + * + * @param DateTime $date + * @return boolean + */ + public function isOnDate(\DateTime $date) + { + $date->setTime(0, 0, 0); + + return ( + ( + ($this->startDate == $date) + && ($this->endDate === null) + ) + || ( + ($this->startDate <= $date) + && ($this->endDate >= $date) + ) + ); + } +} diff --git a/src/KekRozsak/FrontBundle/Resources/config/services.xml b/src/KekRozsak/FrontBundle/Resources/config/services.xml index e6e6826..8658366 100644 --- a/src/KekRozsak/FrontBundle/Resources/config/services.xml +++ b/src/KekRozsak/FrontBundle/Resources/config/services.xml @@ -7,6 +7,11 @@ + + + + + diff --git a/src/KekRozsak/FrontBundle/Resources/views/Event/list.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Event/list.html.twig new file mode 100644 index 0000000..c77e5be --- /dev/null +++ b/src/KekRozsak/FrontBundle/Resources/views/Event/list.html.twig @@ -0,0 +1,16 @@ +{# vim: ft=htmljinja +#} +{% extends '::main_template.html.twig' %} +{% block title %} - Események - {{ day|date('Y-m-d') }}{% endblock %} +{% block content %} +

Események - {{ day|date('Y-m-d') }}

+{% if events %} + +{% else %} +

Erre a napra nincsenek kiírva események.

+{% endif %} +{% endblock content %} diff --git a/src/KekRozsak/FrontBundle/Resources/views/Event/view.html.twig b/src/KekRozsak/FrontBundle/Resources/views/Event/view.html.twig new file mode 100644 index 0000000..18e8992 --- /dev/null +++ b/src/KekRozsak/FrontBundle/Resources/views/Event/view.html.twig @@ -0,0 +1,21 @@ +{# vim: ft=htmljinja +#} +{% extends '::main_template.html.twig' %} +{% block title %} - Esemény - {{ event.title }}{% endblock %} +{% block content %} +

Esemény - {{ event.title }}

+

{{ event.startDate|date('Y-m-d') }} {{ event.startTime|date('H:i') }}{% if event.endDate or event.endTime %} - {% endif %}{% if event.endDate is not null %} {{ event.endDate|date('Y-m-d') }}{% endif %}{% if event.endTime is not null %} {{ event.endTime|date('H:i') }}{% endif %}

+

Az eseményt szervezi: {{ event.createdBy.displayName }}

+

+ {{ event.description }} +

+

Eddigi résztvevők

+
    +{% for attendee in event.attendees %} +
  • {{ attendee.displayName }}
  • +{% endfor %} +
+{% if not event.isAttending(app.user) %} +Megyek +{% endif %} +{% endblock content %} diff --git a/src/KekRozsak/FrontBundle/Twig/EventsExtension.php b/src/KekRozsak/FrontBundle/Twig/EventsExtension.php new file mode 100644 index 0000000..b7e61c0 --- /dev/null +++ b/src/KekRozsak/FrontBundle/Twig/EventsExtension.php @@ -0,0 +1,67 @@ +_doctrine = $doctrine; + $this->_securityContext = $securityContext; + } + + public function getGlobals() + { + $today = new \DateTime('now'); + $firstDay = \DateTime::createFromFormat('Y-m-d', $today->format('Y-m-01')); + $firstDayWeekday = $firstDay->format('N'); + $numDays = $firstDay->format('t'); + $lastDay = \DateTime::createFromFormat('Y-m-d', $today->format('Y-m-' . sprintf("%02d", $numDays))); + + /* + * Get all events in today's month. Iterate through this + * collection, adding each element to $monthEvents array's + * 'day'th element array. + */ + $query = $this->_doctrine->getEntityManager()->createQuery('SELECT e FROM KekRozsakFrontBundle:Event e WHERE e.cancelled = FALSE AND ((e.startDate < :firstDay AND e.endDate >= :firstDay) OR e.startDate BETWEEN :firstDay AND :lastDay)'); + $query->setParameter('firstDay', $firstDay, \Doctrine\DBAL\Types\Type::DATE); + $query->setParameter('lastDay', $lastDay, \Doctrine\DBAL\Types\Type::DATE); + $events = $query->getResult(); + + $eventList = array(); + for ($i = 1; $i <= $numDays; $i++) + { + $date = \DateTime::createFromFormat('Y-m-d', $today->format('Y-m-' . sprintf('%02d', $i))); + $eventList[$i]['date'] = $date; + $eventList[$i]['events'] = array(); + foreach ($events as $event) + { + if ($event->isOnDate($date)) + { + $eventList[$i]['events'][] = $event; + } + } + } + + return array( + 'events' => $events, + 'eventList' => $eventList, + 'today' => $today, + 'firstDay' => $firstDay, + 'lastDay' => $lastDay, + 'firstDayWeekday' => $firstDayWeekday, + 'numDays' => $numDays, + ); + } + + public function getName() + { + return 'Events'; + } +} diff --git a/web/css/kekrozsak_front.css b/web/css/kekrozsak_front.css index 4f35bc0..b089307 100644 --- a/web/css/kekrozsak_front.css +++ b/web/css/kekrozsak_front.css @@ -86,11 +86,57 @@ body { display: none; } +#esemeny-box { + position: fixed; + left: 5px; + top: 32px; + width: 250px; + height: 200px; + background-color: #c4d3ff; + border: 2px solid #152967; + color: #152967; + display: none; +} + +#esemeny-box td { + text-align: center; + vertical-align: middle; +} + +#esemeny-box td.woy { + font-size: 60%; +} + +#esemeny-box td.program { + background-color: green; +} + +#esemeny-belso p.honap { + text-align: center; + margin: 0 5px; + font-weight: bold; +} + +#esemeny-belso table { + margin-left: auto; + margin-right: auto; +} + #login-belso { position: relative; padding: 5px; } +#esemeny-belso { + position: relative; + padding: 5px; +} + +#esemenyek-gomb { + float: left; + padding: 5px; +} + #bottom-line { position: fixed; left: 0;