diff --git a/app/Resources/views/audition/diary.html.twig b/app/Resources/views/audition/diary.html.twig
index efe85061c..9bb5d55b2 100644
--- a/app/Resources/views/audition/diary.html.twig
+++ b/app/Resources/views/audition/diary.html.twig
@@ -7,8 +7,9 @@
- {{ render(url('get_society_events', {identifier: society.slug})) }}
+
+ {{ render(url('get_society_diary', {identifier: society.slug})) }}
{% endblock %}
diff --git a/app/Resources/views/venue/show.html.twig b/app/Resources/views/venue/show.html.twig
index edd49f5bd..0645f4409 100644
--- a/app/Resources/views/venue/show.html.twig
+++ b/app/Resources/views/venue/show.html.twig
@@ -78,7 +78,17 @@
- {{ render(url('get_venue_events', {identifier: venue.slug})) }}
+
+ {{ render(url('get_venue_diary', {identifier: venue.slug})) }}
{% endblock %}
diff --git a/src/Acts/CamdramApiBundle/Configuration/AnnotationReader.php b/src/Acts/CamdramApiBundle/Configuration/AnnotationReader.php
index 2110ebdfe..99bfd1c33 100644
--- a/src/Acts/CamdramApiBundle/Configuration/AnnotationReader.php
+++ b/src/Acts/CamdramApiBundle/Configuration/AnnotationReader.php
@@ -13,6 +13,9 @@ class AnnotationReader
{
private $reader;
+ /**
+ * @var EntityManagerInterface
+ */
private $em;
public function __construct(Reader $reader, EntityManagerInterface $em)
@@ -49,7 +52,9 @@ public function read($object)
$data->setSelfLink($link);
}
- $doctrineMetadata = $this->em->getClassMetadata($reflection->getName());
+ //Be careful not to throw exceptions when visiting non-entity classes
+ $doctrineMetadata = $this->em->getMetadataFactory()->isTransient($reflection->getName())
+ ? null : $this->em->getClassMetadata($reflection->getName());
foreach ($reflection->getProperties() as $property) {
$annotation = $this->reader->getPropertyAnnotation($property, 'Acts\\CamdramApiBundle\\Configuration\\Annotation\\Link');
@@ -60,7 +65,7 @@ public function read($object)
if (!$link->getName()) {
$link->setName($property->getName());
}
- if (!$link->getEntity()) {
+ if (!$link->getEntity() && $doctrineMetadata) {
$mapping = $doctrineMetadata->getAssociationMapping($property->getName());
$targetType = strtolower((new \ReflectionClass($mapping['targetEntity']))->getShortName());
diff --git a/src/Acts/CamdramApiBundle/Serializer/XmlEventSubscriber.php b/src/Acts/CamdramApiBundle/Serializer/XmlEventSubscriber.php
index 1f0a21eb6..3e0b15cde 100644
--- a/src/Acts/CamdramApiBundle/Serializer/XmlEventSubscriber.php
+++ b/src/Acts/CamdramApiBundle/Serializer/XmlEventSubscriber.php
@@ -100,6 +100,9 @@ public function onPostSerialize(ObjectEvent $event)
if ($metadata->getSelfLink()) {
$visitor->getCurrentNode()->appendChild($this->createLinkNode($metadata->getSelfLink(), $visitor, $object));
}
+
+ $class = new \ReflectionClass($object);
+ $visitor->getCurrentNode()->setAttribute('rel', strtolower($class->getShortName()));
}
private function createLinkNode(LinkMetadata $link, XmlSerializationVisitor $visitor, $object)
diff --git a/src/Acts/CamdramApiBundle/Service/EntityUrlGenerator.php b/src/Acts/CamdramApiBundle/Service/EntityUrlGenerator.php
index 8b040e749..90673b694 100644
--- a/src/Acts/CamdramApiBundle/Service/EntityUrlGenerator.php
+++ b/src/Acts/CamdramApiBundle/Service/EntityUrlGenerator.php
@@ -6,11 +6,15 @@
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException;
use Doctrine\Common\Inflector\Inflector;
+use Twig\Extension\AbstractExtension;
+use Twig\TwigFunction;
-class EntityUrlGenerator
+class EntityUrlGenerator extends AbstractExtension
{
private $router;
+ private $accessor;
+
private static $class_map = array(
'TechieAdvert' => 'techie'
);
@@ -18,6 +22,15 @@ class EntityUrlGenerator
public function __construct(RouterInterface $router)
{
$this->router = $router;
+ $this->accessor = PropertyAccess::createPropertyAccessor();
+ }
+
+ public function getFunctions()
+ {
+ return array(
+ new TwigFunction('entity_url', array($this, 'generateUrl')),
+ new TwigFunction('has_entity_url', array($this, 'hasUrl')),
+ );
}
private function getRouteResourceName($class)
@@ -35,29 +48,36 @@ public function getCollectionRoute($class)
{
$route = 'get_' . Inflector::pluralize($this->getRouteResourceName($class));
if ($this->router->getRouteCollection()->get($route) === null) {
- throw new \InvalidArgumentException('That entity does not have a corresponding collection route');
+ throw new \InvalidArgumentException('That entity does not have a corresponding collection route: ' . $route);
}
return $route;
}
- public function getRoute($entity)
+ public function getRouteAndEntity($entity)
{
$route = 'get_' . $this->getRouteResourceName($entity);
- if ($this->router->getRouteCollection()->get($route) === null) {
- throw new \InvalidArgumentException('That entity does not have a corresponding route');
+ if ($this->router->getRouteCollection()->get($route) !== null) {
+ return [$route, $entity];
+ }
+ else if ($show = $this->accessor->getValue($entity, 'show')) {
+ return ['get_show', $show];
}
+ }
- return $route;
+ public function hasUrl($entity)
+ {
+ $route = 'get_' . $this->getRouteResourceName($entity);
+ return $this->router->getRouteCollection()->get($route) !== null
+ || $this->accessor->isReadable($entity, 'show');
}
public function getIdentifier($entity)
{
- $accessor = PropertyAccess::createPropertyAccessor();
try {
- $id = $accessor->getValue($entity, 'slug');
+ $id = $this->accessor->getValue($entity, 'slug');
} catch (NoSuchPropertyException $e) {
- $id = $accessor->getValue($entity, 'id');
+ $id = $this->accessor->getValue($entity, 'id');
}
return $id;
@@ -65,8 +85,10 @@ public function getIdentifier($entity)
public function generateUrl($entity, $format = null)
{
- return $this->router->generate($this->getRoute($entity), array(
- 'identifier' => $this->getIdentifier($entity),
+ list($route, $routeEntity) = $this->getRouteAndEntity($entity);
+
+ return $this->router->generate($route, array(
+ 'identifier' => $this->getIdentifier($routeEntity),
'_format' => $format
), true);
}
diff --git a/src/Acts/CamdramBundle/Controller/AuditionController.php b/src/Acts/CamdramBundle/Controller/AuditionController.php
index 8a76f03c4..4275ba4f1 100644
--- a/src/Acts/CamdramBundle/Controller/AuditionController.php
+++ b/src/Acts/CamdramBundle/Controller/AuditionController.php
@@ -32,9 +32,7 @@ public function cgetDiaryAction()
$diary = new Diary;
$auditions = $this->getDoctrine()->getRepository('ActsCamdramBundle:Audition')->findUpcoming(null, Time::now());
-
- $events = $this->get('acts.camdram.diary_helper')->createEventsFromAuditions($auditions);
- $diary->addEvents($events);
+ $diary->addEvents($auditions);
$view = $this->view($diary)
->setTemplateVar('diary')
diff --git a/src/Acts/CamdramBundle/Controller/DiaryController.php b/src/Acts/CamdramBundle/Controller/DiaryController.php
index 9d6758b55..5283c8c48 100644
--- a/src/Acts/CamdramBundle/Controller/DiaryController.php
+++ b/src/Acts/CamdramBundle/Controller/DiaryController.php
@@ -122,9 +122,7 @@ public function singleWeekAction(Request $request, $date)
$repo = $this->getDoctrine()->getRepository('ActsCamdramBundle:Performance');
$performances = $repo->findInDateRange($start_date, $end_date);
-
- $events = $this->get('acts.camdram.diary_helper')->createEventsFromPerformances($performances);
- $diary->addEvents($events);
+ $diary->addEvents($performances);
return $this->renderDiary($request, $diary);
}
@@ -149,8 +147,7 @@ public function dateAction(Request $request, $start)
$repo = $this->getDoctrine()->getRepository('ActsCamdramBundle:Performance');
$performances = $repo->findInDateRange($start, $end);
- $events = $this->get('acts.camdram.diary_helper')->createEventsFromPerformances($performances);
- $diary->addEvents($events);
+ $diary->addEvents($performances);
$repo = $this->getDoctrine()->getRepository('ActsCamdramBundle:WeekName');
foreach ($repo->findBetween($start, $end) as $name) {
diff --git a/src/Acts/CamdramBundle/Controller/OrganisationController.php b/src/Acts/CamdramBundle/Controller/OrganisationController.php
index 54c3edd79..c83ea27b1 100644
--- a/src/Acts/CamdramBundle/Controller/OrganisationController.php
+++ b/src/Acts/CamdramBundle/Controller/OrganisationController.php
@@ -87,7 +87,7 @@ public function getShowsAction(Request $request, $identifier)
*
* @return mixed
*/
- public function getEventsAction(Request $request, $identifier)
+ public function getDiaryAction(Request $request, $identifier)
{
$diary = new Diary;
@@ -105,17 +105,25 @@ public function getEventsAction(Request $request, $identifier)
}
$performances = $this->getPerformances($identifier, $from, $to);
- $events = $this->get('acts.camdram.diary_helper')->createEventsFromPerformances($performances);
- $diary->addEvents($events);
+ $diary->addEvents($performances);
$view = $this->view($diary, 200)
->setTemplateVar('diary')
- ->setTemplate('organisation/shows.html.twig')
+ ->setTemplate('organisation/diary.html.twig')
;
return $view;
}
+ /**
+ * Redirect from /events -> /diary for backwards compatibility
+ */
+ public function getEventsAction(Request $request, $identifier)
+ {
+ return $this->redirect($this->generateUrl('get_'.$this->type.'_diary',
+ ['identifier' => $identifier, '_format' => $request->getRequestFormat()]));
+ }
+
private function getApplicationForm(Organisation $org, $obj = null, $method = 'POST')
{
if (!$obj) {
diff --git a/src/Acts/CamdramBundle/Controller/PerformanceController.php b/src/Acts/CamdramBundle/Controller/PerformanceController.php
deleted file mode 100644
index a55751e9f..000000000
--- a/src/Acts/CamdramBundle/Controller/PerformanceController.php
+++ /dev/null
@@ -1,37 +0,0 @@
-getTimestamp();
- $endDate = clone $startOfWeek;
- $endDate = $endDate->modify('+6 days')->getTimestamp();
-
- $repo = $this->getDoctrine()->getEntityManager()->getRepository('ActsCamdramBundle:Performance');
-
- $performances = $repo->findAuthorizedJoinedToShow($startDate, $endDate);
-
- $view = $this->view(array('startDate' => $startDate, 'endDate' => $endDate, 'performances' => $performances), 200)
- ->setTemplate('performance/index.html.twig')
- ->setTemplateVar('performances')
- ;
-
- return $view;
- }
-}
diff --git a/src/Acts/CamdramBundle/Entity/Audition.php b/src/Acts/CamdramBundle/Entity/Audition.php
index f3df80e55..fdf3c16f6 100644
--- a/src/Acts/CamdramBundle/Entity/Audition.php
+++ b/src/Acts/CamdramBundle/Entity/Audition.php
@@ -5,7 +5,9 @@
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Acts\CamdramApiBundle\Configuration\Annotation as Api;
+use Acts\DiaryBundle\Model\EventInterface;
use Gedmo\Mapping\Annotation as Gedmo;
+use JMS\Serializer\Annotation as Serializer;
/**
* Audition
@@ -16,8 +18,11 @@
* description="Auditions advertised for shows in Cambridge",
* template="audition/rss.html.twig")
* @Gedmo\Loggable
+ * @Serializer\ExclusionPolicy("all")
+ * @Serializer\XmlRoot("audition")
+ * @Api\Link(route="get_audition", params={"identifier": "object.getShow().getSlug()"})
*/
-class Audition
+class Audition implements EventInterface
{
/**
* @var int
@@ -25,6 +30,9 @@ class Audition
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
+ * @Serializer\XmlAttribute
+ * @Serializer\Expose()
+ * @Serializer\Type("integer")
*/
private $id;
@@ -35,6 +43,8 @@ class Audition
* @Assert\NotBlank()
* @Assert\Date()
* @Gedmo\Versioned
+ * @Serializer\Expose()
+ * @Serializer\XmlElement(cdata=false)
*/
private $date;
@@ -45,6 +55,8 @@ class Audition
* @Assert\NotBlank()
* @Assert\Time()
* @Gedmo\Versioned
+ * @Serializer\Expose()
+ * @Serializer\XmlElement(cdata=false)
*/
private $start_time;
@@ -54,6 +66,8 @@ class Audition
* @ORM\Column(name="endtime", type="time", nullable=true)
* @Assert\Time()
* @Gedmo\Versioned
+ * @Serializer\Expose()
+ * @Serializer\XmlElement(cdata=false)
*/
private $end_time;
@@ -63,6 +77,8 @@ class Audition
* @ORM\Column(name="location", type="string", nullable=false)
* @Assert\NotBlank()
* @Gedmo\Versioned
+ * @Serializer\Expose()
+ * @Serializer\XmlElement(cdata=false)
*/
private $location;
@@ -74,6 +90,7 @@ class Audition
* @ORM\JoinColumn(name="showid", referencedColumnName="id", onDelete="CASCADE")
* })
* @Gedmo\Versioned
+ * @Api\Link(embed=true, route="get_show", params={"identifier": "object.getShow().getSlug()"})
*/
private $show;
@@ -280,4 +297,36 @@ public function getSlug()
{
return $this->getShow()->getSlug();
}
+
+ // EventInterface
+
+ public function getName()
+ {
+ return $this->show->getName();
+ }
+
+ public function getStartDate()
+ {
+ return $this->date;
+ }
+
+ public function getEndDate()
+ {
+ return $this->date;
+ }
+
+ public function getVenueName()
+ {
+ return $this->location;
+ }
+
+ public function getVenue()
+ {
+ return null;
+ }
+
+ public function getUpdatedAt()
+ {
+ return $this->getShow()->getTimestamp();
+ }
}
diff --git a/src/Acts/CamdramBundle/Entity/Performance.php b/src/Acts/CamdramBundle/Entity/Performance.php
index f5b39f4cf..444db1d6e 100644
--- a/src/Acts/CamdramBundle/Entity/Performance.php
+++ b/src/Acts/CamdramBundle/Entity/Performance.php
@@ -6,6 +6,7 @@
use JMS\Serializer\Annotation as Serializer;
use Gedmo\Mapping\Annotation as Gedmo;
use Acts\CamdramApiBundle\Configuration\Annotation as Api;
+use Acts\DiaryBundle\Model\EventInterface;
/**
* Performance
@@ -15,9 +16,8 @@
* @Serializer\ExclusionPolicy("all")
* @Gedmo\Loggable
* @Serializer\XmlRoot("performance")
- *
*/
-class Performance
+class Performance implements EventInterface
{
/**
* @var int
@@ -25,6 +25,8 @@ class Performance
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
+ * @Serializer\Expose
+ * @Serializer\XmlAttribute
*/
private $id;
@@ -36,6 +38,7 @@ class Performance
* @ORM\JoinColumn(name="sid", referencedColumnName="id", onDelete="CASCADE")
* })
* @Gedmo\Versioned
+ * @Api\Link(embed=true, route="get_show", params={"identifier": "object.getShow().getSlug()"})
*/
private $show;
@@ -285,23 +288,24 @@ public function setVenue(\Acts\CamdramBundle\Entity\Venue $venue = null)
return $this;
}
- /**
- * Generate a more useful view of the performance dates, making it easier
- * to render the diary page.
- *
- * @return An array of diary entries (currently just one).
- */
- public function getDiaryEntries()
+ public function getName()
{
- $entries = array();
- $entry = array();
+ return $this->getShow()->getName();
+ }
- $entry['startdate'] = $this->start_date;
- $entry['enddate'] = $this->end_date;
- $entry['numdays'] = $entry['enddate']->diff($entry['startdate'])->d + 1;
+ public function getUpdatedAt()
+ {
+ return $this->getShow()->getTimestamp();
+ }
- $entries[] = $entry;
+ public function getStartTime()
+ {
+ return $this->getTime();
+ }
- return $entries;
+ public function getEndTime()
+ {
+ return null;
}
+
}
diff --git a/src/Acts/CamdramBundle/Entity/Venue.php b/src/Acts/CamdramBundle/Entity/Venue.php
index 6f7b974f2..e8fa15b0e 100644
--- a/src/Acts/CamdramBundle/Entity/Venue.php
+++ b/src/Acts/CamdramBundle/Entity/Venue.php
@@ -6,6 +6,7 @@
use JMS\Serializer\Annotation as Serializer;
use Gedmo\Mapping\Annotation as Gedmo;
use Acts\CamdramApiBundle\Configuration\Annotation as Api;
+use Acts\DiaryBundle\Model\VenueInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
@@ -15,7 +16,7 @@
* @Serializer\ExclusionPolicy("all")
* @Serializer\XmlRoot("venue")
*/
-class Venue extends Organisation
+class Venue extends Organisation implements VenueInterface
{
/**
* @var string
diff --git a/src/Acts/CamdramBundle/Resources/config/services.yml b/src/Acts/CamdramBundle/Resources/config/services.yml
index 4f04ba51b..f26924449 100644
--- a/src/Acts/CamdramBundle/Resources/config/services.yml
+++ b/src/Acts/CamdramBundle/Resources/config/services.yml
@@ -1,10 +1,5 @@
services:
- acts.camdram.diary_helper:
- class: Acts\CamdramBundle\Service\DiaryHelper
- arguments: ['@router']
- public: true
-
acts.camdram.type.form_extension:
class: Acts\CamdramBundle\Form\CamdramFormTypeExtension
tags:
diff --git a/src/Acts/CamdramBundle/Service/DiaryHelper.php b/src/Acts/CamdramBundle/Service/DiaryHelper.php
deleted file mode 100644
index 6978da876..000000000
--- a/src/Acts/CamdramBundle/Service/DiaryHelper.php
+++ /dev/null
@@ -1,132 +0,0 @@
-router = $router;
- }
-
- /**
- * Generate an event from a 'performance' of a show (which actually represents a range of performances)
- *
- * @param Show $show
- * @param Performance $performance
- *
- * @return MultiDayEvent
- */
- public function createEventsFromPerformance(Performance $performance)
- {
- $event = new MultiDayEvent();
- $event->setName($performance->getShow()->getName());
- $event->setLink($this->router->generate('get_show', array('identifier' => $performance->getShow()->getSlug())));
- $event->setStartTime($performance->getTime());
- $event->setVenue($performance->getVenueName());
- $event->setUpdatedAt($performance->getShow()->getTimestamp());
- $event->setUid($performance->getId().'@camdram.net');
- $event->setDescription($performance->getShow()->getDescription());
- if ($performance->getVenue()) {
- $event->setVenueLink($this->router->generate('get_venue', array('identifier' => $performance->getVenue()->getSlug())));
- }
-
- $event->setStartDate($performance->getStartDate());
- $event->setEndDate($performance->getEndDate());
-
- return array($event);
- }
-
- /**
- * Generate an array of events corresponding to the various performance ranges of the given show
- *
- * @param array $shows
- *
- * @return array
- */
- public function createEventsFromShows(array $shows)
- {
- $events = array();
- foreach ($shows as $show) {
- foreach ($show->getPerformances() as $perf) {
- foreach ($this->createEventsFromPerformance($perf) as $event) {
- $events[] = $event;
- }
- }
- }
-
- return $events;
- }
-
- /**
- * Generate an array of events from an array of performances
- *
- * @param array|Traversible $performances
- *
- * @return array
- */
- public function createEventsFromPerformances($performances)
- {
- if (!is_array($performances) && !$performances instanceof \Traversable) {
- throw new \InvalidArgumentException('$performances must either be an array or a Traversable object');
- }
-
- $events = array();
- foreach ($performances as $performance) {
- foreach ($this->createEventsFromPerformance($performance) as $event) {
- $events[] = $event;
- }
- }
-
- return $events;
- }
-
- public function createEventFromAudition(Audition $audition)
- {
- $event = new SingleDayEvent();
- $event->setName($audition->getShow()->getName());
- $event->setLink($this->router->generate('get_auditions').'#auditions-'.$audition->getShow()->getId());
- $event->setDate($audition->getDate());
- $event->setStartTime($audition->getStartTime());
- $event->setEndTime($audition->getEndTime());
- $event->setVenue($audition->getLocation());
-
- return $event;
- }
-
- public function createEventsFromAuditions($auditions)
- {
- if (!is_array($auditions) && !$auditions instanceof \Traversable) {
- throw new \InvalidArgumentException('$auditions must either be an array or a Traversable object');
- }
-
- $events = array();
- foreach ($auditions as $audition) {
- if (!$audition->getNonScheduled()) {
- $events[] = $this->createEventFromAudition($audition);
- }
- }
-
- return $events;
- }
-}
diff --git a/src/Acts/DiaryBundle/ActsDiaryBundle.php b/src/Acts/DiaryBundle/ActsDiaryBundle.php
index 4be713a76..32f46e86e 100644
--- a/src/Acts/DiaryBundle/ActsDiaryBundle.php
+++ b/src/Acts/DiaryBundle/ActsDiaryBundle.php
@@ -12,8 +12,7 @@
* the DiaryFactory, then adding event objects to it. The diary can then be passed to
* Acts\DiaryBundle\Diary\Renderer\HtmlRenderer to render it as HTML.
*
- * All Events must implement SingleDayEventInterface or MultiDayEventInterface depending on whether the event lasts
- * a single day or a period of days at the same time.
+ * All Events must implement EventInterface
*
* This bundle is deliberately de-coupled from CamdramBundle, such that it could be made into a useful external bundle.
* There's a helper class inside CamdramBundle which deals with turning shows and performances into events.
diff --git a/src/Acts/DiaryBundle/Diary/Diary.php b/src/Acts/DiaryBundle/Diary/Diary.php
index 66d20d33e..d728f921c 100644
--- a/src/Acts/DiaryBundle/Diary/Diary.php
+++ b/src/Acts/DiaryBundle/Diary/Diary.php
@@ -2,7 +2,8 @@
namespace Acts\DiaryBundle\Diary;
-use Acts\DiaryBundle\Event\EventInterface;
+use Acts\DiaryBundle\Model\EventInterface;
+use JMS\Serializer\Annotation as Serializer;
/**
* Class Diary
@@ -11,23 +12,36 @@
* end_date, which, if specified, cause the diary to ignore events or parts of multi-day events that take place
* outside that time period. Only start and end dates that are at the beginning/end of weeks (midnight Sunday morning)
* have been tested.
+ *
+ * @Serializer\XmlRoot("diary")
*/
class Diary
{
/**
* @var array An array of the events that have been added to the Diary.
+ *
+ * @Serializer\XmlList(inline = true, entry = "event")
*/
private $events = array();
+ /**
+ * @var array An array of week names and time periods relevant to the diary
+ *
+ * @Serializer\XmlList(inline = true, entry = "label")
+ */
private $labels = array();
/**
* @var \DateTime
+ *
+ * @Serializer\XmlElement(cdata=false)
*/
private $start_date;
/**
* @var \DateTime
+ *
+ * @Serializer\XmlElement(cdata=false)
*/
private $end_date;
diff --git a/src/Acts/DiaryBundle/Diary/DiaryItem.php b/src/Acts/DiaryBundle/Diary/DiaryItem.php
index 0736a8fe6..47e5c7d4f 100644
--- a/src/Acts/DiaryBundle/Diary/DiaryItem.php
+++ b/src/Acts/DiaryBundle/Diary/DiaryItem.php
@@ -2,7 +2,7 @@
namespace Acts\DiaryBundle\Diary;
-use Acts\DiaryBundle\Event\EventInterface;
+use Acts\DiaryBundle\Model\EventInterface;
/**
* Class DiaryItem
@@ -24,7 +24,7 @@ class DiaryItem
private $end_at;
/**
- * @var \Acts\DiaryBundle\Event\EventInterface The event associated with this diary item
+ * @var \Acts\DiaryBundle\Model\EventInterface The event associated with this diary item
*/
private $event;
diff --git a/src/Acts/DiaryBundle/Diary/DiaryRow.php b/src/Acts/DiaryBundle/Diary/DiaryRow.php
index 14832eafc..0a112586e 100644
--- a/src/Acts/DiaryBundle/Diary/DiaryRow.php
+++ b/src/Acts/DiaryBundle/Diary/DiaryRow.php
@@ -2,9 +2,7 @@
namespace Acts\DiaryBundle\Diary;
-use Acts\DiaryBundle\Event\EventInterface;
-use Acts\DiaryBundle\Event\SingleDayEventInterface;
-use Acts\DiaryBundle\Event\MultiDayEventInterface;
+use Acts\DiaryBundle\Model\EventInterface;
class DiaryRow
{
@@ -83,16 +81,10 @@ public function canAccept(EventInterface $event)
}
//Now see if there's space in the row
- if ($event instanceof SingleDayEventInterface) {
- $index = $this->calculateIndex($event->getDate());
+ $start_index = $this->calculateIndex($event->getStartDate());
+ $end_index = $this->calculateIndex($event->getEndDate());
- return $this->rangeIsFree($index, $index);
- } elseif ($event instanceof MultiDayEventInterface) {
- $start_index = $this->calculateIndex($event->getStartDate());
- $end_index = $this->calculateIndex($event->getEndDate());
-
- return $this->rangeIsFree($start_index, $end_index);
- }
+ return $this->rangeIsFree($start_index, $end_index);
}
public function addItem(DiaryItem $item)
@@ -114,19 +106,13 @@ public function addEvent(EventInterface $event)
$item->setStartAt($event->getStartTime());
$item->setEndAt($event->getEndTime());
- if ($event instanceof SingleDayEventInterface) {
- $item->setNumberOfDays(1);
- $item->setStartIndex($this->calculateIndex($event->getDate()));
+ $start_index = $this->calculateIndex($event->getStartDate());
+ $end_index = $this->calculateIndex($event->getEndDate());
+ $numberOfDays = $end_index - $start_index + 1;
+ if ($numberOfDays > 0) {
+ $item->setStartIndex($start_index);
+ $item->setNumberOfDays($end_index - $start_index + 1);
$this->addItem($item);
- } elseif ($event instanceof MultiDayEventInterface) {
- $start_index = $this->calculateIndex($event->getStartDate());
- $end_index = $this->calculateIndex($event->getEndDate());
- $numberOfDays = $end_index - $start_index + 1;
- if ($numberOfDays > 0) {
- $item->setStartIndex($start_index);
- $item->setNumberOfDays($end_index - $start_index + 1);
- $this->addItem($item);
- }
}
}
diff --git a/src/Acts/DiaryBundle/Diary/DiaryView.php b/src/Acts/DiaryBundle/Diary/DiaryView.php
index 47ff21a2c..9b1a26ee3 100644
--- a/src/Acts/DiaryBundle/Diary/DiaryView.php
+++ b/src/Acts/DiaryBundle/Diary/DiaryView.php
@@ -2,9 +2,7 @@
namespace Acts\DiaryBundle\Diary;
-use Acts\DiaryBundle\Event\EventInterface;
-use Acts\DiaryBundle\Event\MultiDayEventInterface;
-use Acts\DiaryBundle\Event\SingleDayEventInterface;
+use Acts\DiaryBundle\Model\EventInterface;
/**
* Class DiaryView
@@ -72,29 +70,15 @@ private function getWeekForDate(\DateTime $date)
*/
public function addEvent(EventInterface $event)
{
- if ($event instanceof MultiDayEventInterface) {
- //If it's a multi-day event, we may well need to display it in multiple weeks
- $week_start = Week::getWeekStart($event->getStartDate());
- do {
- $week = $this->getWeekForDate($week_start);
- if ($week) {
- $week->addEvent($event);
- }
- $week_start->modify('+7 days');
- } while ($week_start < $event->getEndDate());
- } elseif ($event instanceof SingleDayEventInterface) {
- $this->getWeekForDate($event->getDate())->addEvent($event);
-
- //If its end time is before its start time, we assume this means it continues until that time the next day
- if ($event->getEndTime() < $event->getStartTime()
- && $event->getDate()->format('N') == 6) {
- $tomorrow = $event->getDate()->modify('+1 day');
- $week = $this->getWeekForDate($tomorrow);
- if ($week) {
- $week->addEvent($event);
- }
+ //If it's a multi-day event, we may well need to display it in multiple weeks
+ $week_start = Week::getWeekStart($event->getStartDate());
+ do {
+ $week = $this->getWeekForDate($week_start);
+ if ($week) {
+ $week->addEvent($event);
}
- }
+ $week_start->modify('+7 days');
+ } while ($week_start < $event->getEndDate());
}
/**
diff --git a/src/Acts/DiaryBundle/Diary/Label.php b/src/Acts/DiaryBundle/Diary/Label.php
index c4166ed9b..c3563336e 100644
--- a/src/Acts/DiaryBundle/Diary/Label.php
+++ b/src/Acts/DiaryBundle/Diary/Label.php
@@ -2,6 +2,8 @@
namespace Acts\DiaryBundle\Diary;
+use JMS\Serializer\Annotation as Serializer;
+
/**
* Class Label
*
@@ -14,23 +16,30 @@ class Label
const TYPE_PERIOD = 'period';
/**
- * @var string
- * The type of label, either LABEL_TYPE_WEEK or LABEL_TYPE_PERIOD
+ * @var string The type of label, either LABEL_TYPE_WEEK or LABEL_TYPE_PERIOD
+ *
+ * @Serializer\XmlElement(cdata=false)
*/
private $type;
/**
* @var \DateTime The start time of the period this label refers to
+ *
+ * @Serializer\XmlElement(cdata=false)
*/
private $start_at;
/**
* @var \DateTime The end time of the period this label refers to
+ *
+ * @Serializer\XmlElement(cdata=false)
*/
private $end_at;
/**
- * @var string The column in which this event starts (0-based)
+ * @var string The user-visible name of the label
+ *
+ * @Serializer\XmlElement(cdata=false)
*/
private $text;
diff --git a/src/Acts/DiaryBundle/Diary/Renderer/ICalRenderer.php b/src/Acts/DiaryBundle/Diary/Renderer/ICalRenderer.php
index d5c82b89b..b19f04271 100644
--- a/src/Acts/DiaryBundle/Diary/Renderer/ICalRenderer.php
+++ b/src/Acts/DiaryBundle/Diary/Renderer/ICalRenderer.php
@@ -3,8 +3,6 @@
namespace Acts\DiaryBundle\Diary\Renderer;
use Acts\DiaryBundle\Diary\Diary;
-use Acts\DiaryBundle\Event\MultiDayEventInterface;
-use Acts\DiaryBundle\Event\SingleDayEventInterface;
use Sabre\VObject\Component\VCalendar;
/**
@@ -21,15 +19,12 @@ public function render(Diary $diary)
$vcalendar->add('PRODID', '-//Camdram//NONSGML Show Diary//EN');
foreach ($diary->getEvents() as $event) {
- $start_time = null;
- $rrule = array();
+ $start_time = new \DateTime($event->getStartDate()->format('Y-m-d').' '.$event->getStartTime()->format('H:i:s'));
+ $rrule = null;
- if ($event instanceof MultiDayEventInterface) {
- $start_time = new \DateTime($event->getStartDate()->format('Y-m-d').' '.$event->getStartTime()->format('H:i:s'));
+ if ($event->getStartDate() != $event->getEndDate()) {
$last_start_time = new \DateTime($event->getEndDate()->format('Y-m-d').' '.$event->getStartTime()->format('H:i:s'));
$rrule = 'FREQ=DAILY;UNTIL='.$last_start_time->format('Ymd\\THis\\Z');
- } elseif ($event instanceof SingleDayEventInterface) {
- $start_time = new \DateTime($event->getDate().' '.$event->getStartTime()->format('H:i:s'));
}
if ($start_time) {
@@ -42,12 +37,11 @@ public function render(Diary $diary)
$params = array(
'SUMMARY' => $event->getName(),
- 'LOCATION' => $event->getVenue(),
- 'UID' => $event->getUid(),
+ 'LOCATION' => $event->getVenue() ? $event->getVenue()->getName() : $event->getVenueName(),
+ 'UID' => $event->getId().'@camdram.net',
'DTSTAMP' => $dtstamp,
'DTSTART' => $start_time,
'DURATION' => 'PT2H00M00S',
- 'DESCRIPTION' => $event->getDescription()
);
if ($rrule) {
$params['RRULE'] = $rrule;
diff --git a/src/Acts/DiaryBundle/Diary/Week.php b/src/Acts/DiaryBundle/Diary/Week.php
index 0ffed72e6..e3f5d964d 100644
--- a/src/Acts/DiaryBundle/Diary/Week.php
+++ b/src/Acts/DiaryBundle/Diary/Week.php
@@ -2,7 +2,7 @@
namespace Acts\DiaryBundle\Diary;
-use Acts\DiaryBundle\Event\EventInterface;
+use Acts\DiaryBundle\Model\EventInterface;
/**
* Class Week
diff --git a/src/Acts/DiaryBundle/Event/MultiDayEvent.php b/src/Acts/DiaryBundle/Event/MultiDayEvent.php
deleted file mode 100644
index e5e8f707a..000000000
--- a/src/Acts/DiaryBundle/Event/MultiDayEvent.php
+++ /dev/null
@@ -1,52 +0,0 @@
-start_date;
- }
-
- /**
- * Set the first date on which the event takes place
- *
- * @param \DateTime $start_date
- */
- public function setStartDate(\DateTime $start_date)
- {
- $this->start_date = $start_date;
- }
-
- /**
- * {@inheritdoc}
- */
- public function getEndDate()
- {
- return $this->end_date;
- }
-
- /**
- * Set the last date on which the event takes place
- *
- * @param \DateTime $end_date
- */
- public function setEndDate(\DateTime $end_date)
- {
- $this->end_date = $end_date;
- }
-}
diff --git a/src/Acts/DiaryBundle/Event/MultiDayEventInterface.php b/src/Acts/DiaryBundle/Event/MultiDayEventInterface.php
deleted file mode 100644
index 3823159ea..000000000
--- a/src/Acts/DiaryBundle/Event/MultiDayEventInterface.php
+++ /dev/null
@@ -1,23 +0,0 @@
-date;
- }
-
- /**
- * Set the date on which the event takes place
- *
- * @param \DateTime $date
- */
- public function setDate(\DateTime $date)
- {
- $this->date = $date;
- }
-}
diff --git a/src/Acts/DiaryBundle/Event/SingleDayEventInterface.php b/src/Acts/DiaryBundle/Event/SingleDayEventInterface.php
deleted file mode 100644
index 9ff7063d4..000000000
--- a/src/Acts/DiaryBundle/Event/SingleDayEventInterface.php
+++ /dev/null
@@ -1,13 +0,0 @@
-venue = $venue;
+ return $this;
+ }
+
+ /**
+ * Set the event's venue
*/
public function getVenue()
{
@@ -81,49 +95,67 @@ public function getVenue()
}
/**
- * {@inheritdoc}
+ * Set the venue name
+ *
+ * @param string $venue
*/
- public function getLink()
+ public function setVenueName($venueName)
{
- return $this->link;
+ $this->venue_name = $venueName;
+ return $this;
}
/**
- * Set the URL reached by clicking on the event's name
+ * Get the venue name
*
- * @param string|null $link
+ * @param string $venue
*/
- public function setLink($link)
+ public function getVenueName()
{
- $this->link = $link;
+ return $this->venue_name;
}
/**
- * Set the venue name
+ * Convenience method to set start and end dates to the same value
+ */
+ public function setDate(\DateTime $date)
+ {
+ $this->setStartDate($date);
+ $this->setEndDate($date);
+ return $this;
+ }
+
+ public function getStartDate()
+ {
+ return $this->start_date;
+ }
+
+ /**
+ * Set the first date on which the event takes place
*
- * @param string $venue
+ * @param \DateTime $start_date
*/
- public function setVenue($venue)
+ public function setStartDate(\DateTime $start_date)
{
- $this->venue = $venue;
+ $this->start_date = $start_date;
}
/**
* {@inheritdoc}
*/
- public function getVenueLink()
+ public function getEndDate()
{
- return $this->venue_link;
+ return $this->end_date;
}
/**
- * Set the URL reached by clicking on the venue name
+ * Set the last date on which the event takes place
*
- * @param string|null $link
+ * @param \DateTime $end_date
*/
- public function setVenueLink($link)
+ public function setEndDate(\DateTime $end_date)
{
- $this->venue_link = $link;
+ $this->end_date = $end_date;
}
/**
@@ -163,19 +195,19 @@ public function setEndTime(\DateTime $end_time)
}
/**
- * @param null|string $uid
+ * @param int $uid
*/
- public function setUid($uid)
+ public function setId($id)
{
- $this->uid = $uid;
+ $this->id = $id;
}
/**
* @return null|string
*/
- public function getUid()
+ public function getId()
{
- return $this->uid;
+ return $this->id;
}
/**
@@ -209,4 +241,4 @@ public function getDescription()
{
return $this->description;
}
-}
+}
\ No newline at end of file
diff --git a/src/Acts/DiaryBundle/Event/EventInterface.php b/src/Acts/DiaryBundle/Model/EventInterface.php
similarity index 65%
rename from src/Acts/DiaryBundle/Event/EventInterface.php
rename to src/Acts/DiaryBundle/Model/EventInterface.php
index c25fae710..f8fe691f7 100644
--- a/src/Acts/DiaryBundle/Event/EventInterface.php
+++ b/src/Acts/DiaryBundle/Model/EventInterface.php
@@ -1,12 +1,9 @@
{% set last_index = -1 %}
{% for item in row.items %}
-
{# Jump through hoops here to get the start date of the event itself by treating the offset as seconds in a unix timestamp and
then rendering it to appear as a number of days to modify the date by. #}
{{ item.startAt | date('g:ia') }}{% if item.endAt %}-{{ item.endAt | date('g:ia') }}
{% endif %}
- {% if item.event.link %}
{{ item.event.name }}
+ {% if has_entity_url(item.event) %}
{{ item.event.name }}
{% else %}{{ item.event.name }}{% endif %}
{% if item.event.venue %}
{# Mandatory field, good enough for almost all cases. #}
- {%- if item.event.venueLink %}{{ item.event.venue }}
- {%- else %}{{ item.event.venue }}
+ {%- if item.event.venue %}{{ item.event.venue.name }}
+ {%- else %}{{ item.event.venueName }}
{% endif %}
{% endif %}
diff --git a/tests/CamdramBundle/Controller/DiaryControllerTest.php b/tests/CamdramBundle/Controller/DiaryControllerTest.php
index 9f6077c56..2d98a75f2 100644
--- a/tests/CamdramBundle/Controller/DiaryControllerTest.php
+++ b/tests/CamdramBundle/Controller/DiaryControllerTest.php
@@ -35,7 +35,7 @@ private function createShowWithDates($show_name, $days, $length, $time)
}
$start_date->modify('+'.$days.' day');
$end_date = clone $start_date;
- $end_date->modify('+'.$length.' days');
+ $end_date->modify('+'.($length - 1).' days');
$performance = new Performance();
$performance->setStartDate($start_date);
@@ -55,6 +55,41 @@ public function testMain()
$crawler = $this->client->request('GET', '/diary');
$this->assertEquals($crawler->filter('#diary:contains("Test Show 1")')->count(), 1);
$this->assertEquals($crawler->filter('#diary:contains("Test Show 2")')->count(), 1);
+
+ //JSON response
+ $data = $this->doJsonRequest('/diary.json');
+ $this->assertEquals(2, count($data['events']));
+ $this->assertArraySubset([
+ 'events' => [
+ [
+ 'show' => ['name' => 'Test Show 1'],
+ '_links' => [
+ 'show' => '/shows/test-show-1',
+ ],
+ 'start_date' => (new \DateTime('2000-07-03'))->format('c'),
+ 'end_date' => (new \DateTime('2000-07-06'))->format('c'),
+ 'time' => (new \DateTime('1970-01-01 19:30'))->format('c'),
+ ],
+ [
+ 'show' => ['name' => 'Test Show 2'],
+ '_links' => [
+ 'show' => '/shows/test-show-2',
+ ],
+ 'start_date' => (new \DateTime('2000-07-04'))->format('c'),
+ 'end_date' => (new \DateTime('2000-07-04'))->format('c'),
+ 'time' => (new \DateTime('1970-01-01 14:00'))->format('c'),
+ ],
+ ]
+ ], $data);
+
+ //iCal response
+ $vcal = $this->doICalRequest('/diary.ics');
+ $this->assertEquals(2, count($vcal->VEVENT));
+ $this->assertEquals('Test Show 1', $vcal->VEVENT[0]->SUMMARY);
+ $this->assertEquals(new \DateTime('2000-07-03 19:30'), $vcal->VEVENT[0]->DTSTART->getDateTime());
+ $this->assertArraySubset(['UNTIL' => '20000706T193000Z'], $vcal->VEVENT[0]->RRULE->getParts());
+ $this->assertEquals('Test Show 2', $vcal->VEVENT[1]->SUMMARY);
+ $this->assertEquals(new \DateTime('2000-07-04 14:00'), $vcal->VEVENT[1]->DTSTART->getDateTime());
}
public function testSpecificDate()
@@ -64,6 +99,22 @@ public function testSpecificDate()
$this->createShowWithDates("Test Show", -7, 2, '19:30');
$crawler = $this->client->request('GET', '/diary/2000-06-25?end=2000-07-01');
$this->assertEquals($crawler->filter('#diary:contains("Test Show")')->count(), 1);
+
+ $data = $this->doJsonRequest('/diary/2000-06-25.json?end=2000-07-01');
+ $this->assertEquals(1, count($data['events']));
+ $this->assertArraySubset([
+ 'events' => [
+ [
+ 'show' => ['name' => 'Test Show'],
+ '_links' => [
+ 'show' => '/shows/test-show',
+ ],
+ 'start_date' => (new \DateTime('2000-06-25'))->format('c'),
+ 'end_date' => (new \DateTime('2000-06-26'))->format('c'),
+ 'time' => (new \DateTime('1970-01-01 19:30'))->format('c'),
+ ],
+ ]
+ ], $data);
}
public function testSpecificYear()
@@ -73,6 +124,22 @@ public function testSpecificYear()
$this->createShowWithDates("Test Show", -30, 7, '19:30');
$crawler = $this->client->request('GET', '/diary/2000?end=2000-12-30');
$this->assertEquals($crawler->filter('#diary:contains("Test Show")')->count(), 1);
+
+ $data = $this->doJsonRequest('/diary/2000.json?end=2000-12-30');
+ $this->assertEquals(1, count($data['events']));
+ $this->assertArraySubset([
+ 'events' => [
+ [
+ 'show' => ['name' => 'Test Show'],
+ '_links' => [
+ 'show' => '/shows/test-show',
+ ],
+ 'start_date' => (new \DateTime('2000-06-02'))->format('c'),
+ 'end_date' => (new \DateTime('2000-06-08'))->format('c'),
+ 'time' => (new \DateTime('1970-01-01 19:30'))->format('c'),
+ ],
+ ]
+ ], $data);
}
public function testSpecificPeriod()
@@ -93,6 +160,29 @@ public function testSpecificPeriod()
$crawler = $this->client->request('GET', '/diary/2000/test-period');
$this->assertEquals($crawler->filter('#diary:contains("Test Show")')->count(), 1);
$this->assertEquals($crawler->filter('.diary-period-label:contains("Test Period")')->count(), 1);
+
+ $data = $this->doJsonRequest('/diary/2000.json?end=2000-12-30');
+ $this->assertEquals(1, count($data['events']));
+ $this->assertArraySubset([
+ 'events' => [
+ [
+ 'show' => ['name' => 'Test Show'],
+ '_links' => [
+ 'show' => '/shows/test-show',
+ ],
+ 'start_date' => (new \DateTime('2000-06-18'))->format('c'),
+ 'end_date' => (new \DateTime('2000-06-19'))->format('c'),
+ 'time' => (new \DateTime('1970-01-01 19:30'))->format('c'),
+ ],
+ ],
+ 'labels' => [
+ [
+ 'text' => 'Test Period',
+ 'start_at' => (new \DateTime('2000-06-01'))->format('c'),
+ 'end_at' => (new \DateTime('2000-07-15'))->format('c'),
+ ]
+ ]
+ ], $data);
}
}
\ No newline at end of file
diff --git a/tests/CamdramBundle/Service/DiaryHelperTest.php b/tests/CamdramBundle/Service/DiaryHelperTest.php
deleted file mode 100644
index e04a68440..000000000
--- a/tests/CamdramBundle/Service/DiaryHelperTest.php
+++ /dev/null
@@ -1,156 +0,0 @@
-router = $this->createMock('Symfony\\Component\\Routing\\RouterInterface');
- $this->diaryHelper = new DiaryHelper($this->router);
- }
-
- private function getPerformance()
- {
- $s = new Show();
- $s->setName('Test Show');
- $s->setSlug('test-show');
-
- $p = new Performance();
- $p->setShow($s);
- $p->setStartDate(new \DateTime('2013-02-10'));
- $p->setEndDate(new \DateTime('2013-02-15'));
- $p->setTime(new \DateTime('19:45'));
-
- return $p;
- }
-
- public function testCreateEventFromPerformance()
- {
- $performance = $this->getPerformance();
- $performance->setOtherVenue('Test Venue');
-
- $this->router->expects($this->once())
- ->method('generate')
- ->with('get_show', array('identifier' => 'test-show'))
- ->will($this->returnValue('/shows/test-show'));
-
- list($event) = $this->diaryHelper->createEventsFromPerformance($performance);
-
- $this->assertEquals('Test Show', $event->getName());
- $this->assertEquals(new \DateTime('2013-02-10'), $event->getStartDate());
- $this->assertEquals(new \DateTime('2013-02-15'), $event->getEndDate());
- $this->assertEquals(new \DateTime('19:45'), $event->getStartTime());
- $this->assertEquals('/shows/test-show', $event->getLink());
- $this->assertEquals('Test Venue', $event->getVenue());
- $this->assertEquals(null, $event->getVenueLink());
- }
-
- public function testCreateEventFromPerformance_VenueObject()
- {
- $performance = $this->getPerformance();
- $venue = new Venue();
- $venue->setName('Test Venue');
- $venue->setSlug('test-venue');
- $performance->setVenue($venue);
-
- $this->router->expects($this->exactly(2))
- ->method('generate')
- ->will($this->returnValueMap(array(
- array('get_show', array('identifier' => 'test-show'), UrlGeneratorInterface::ABSOLUTE_PATH, '/shows/test-show'),
- array('get_venue', array('identifier' => 'test-venue'), UrlGeneratorInterface::ABSOLUTE_PATH, '/venues/test-venue'),
- )));
-
- list($event) = $this->diaryHelper->createEventsFromPerformance($performance);
- $this->assertEquals('Test Show', $event->getName());
- $this->assertEquals(new \DateTime('2013-02-10'), $event->getStartDate());
- $this->assertEquals(new \DateTime('2013-02-15'), $event->getEndDate());
- $this->assertEquals(new \DateTime('19:45'), $event->getStartTime());
- $this->assertEquals('/shows/test-show', $event->getLink());
- $this->assertEquals('/venues/test-venue', $event->getVenueLink());
- }
-
- public function testCreateEventFromPerformances()
- {
- $s = new Show();
- $s->setName('Test Show');
- $s->setSlug('test-show');
-
- $p1 = new Performance();
- $p1->setStartDate(new \DateTime('2013-02-10'));
- $p1->setEndDate(new \DateTime('2013-02-15'));
- $p1->setTime(new \DateTime('19:45'));
- $p1->setShow($s);
-
- $p2 = new Performance();
- $p2->setStartDate(new \DateTime('2013-02-15'));
- $p2->setEndDate(new \DateTime('2013-02-15'));
- $p2->setTime(new \DateTime('14:30'));
- $p2->setShow($s);
-
- $events = $this->diaryHelper->createEventsFromPerformances(array($p1, $p2));
- $this->assertEquals(2, count($events));
- $this->assertEquals(new \DateTime('2013-02-10'), $events[0]->getStartDate());
- $this->assertEquals(new \DateTime('2013-02-15'), $events[1]->getStartDate());
- }
-
- public function testCreateEventFromShows()
- {
- $s1 = new Show();
- $s1->setName('Test Show 1');
- $s1->setSlug('test-show-1');
-
- $p1 = new Performance();
- $p1->setStartDate(new \DateTime('2013-04-01'));
- $p1->setEndDate(new \DateTime('2013-04-02'));
- $p1->setTime(new \DateTime('19:30'));
- $p1->setShow($s1);
- $s1->addPerformance($p1);
-
- $s2 = new Show();
- $s2->setName('Test Show 2');
- $s2->setSlug('test-show-2');
-
- $p2 = new Performance();
- $p2->setStartDate(new \DateTime('2013-02-10'));
- $p2->setEndDate(new \DateTime('2013-02-15'));
- $p2->setTime(new \DateTime('19:45'));
- $p2->setShow($s2);
- $s2->addPerformance($p2);
-
- $p3 = new Performance();
- $p3->setStartDate(new \DateTime('2013-02-15'));
- $p3->setEndDate(new \DateTime('2013-02-15'));
- $p3->setTime(new \DateTime('14:30'));
- $p3->setShow($s2);
- $s2->addPerformance($p3);
-
- $events = $this->diaryHelper->createEventsFromShows(array($s1, $s2));
- $this->assertEquals(3, count($events));
- $this->assertEquals(new \DateTime('2013-04-01'), $events[0]->getStartDate());
- $this->assertEquals(new \DateTime('2013-02-10'), $events[1]->getStartDate());
- $this->assertEquals(new \DateTime('2013-02-15'), $events[2]->getStartDate());
- }
-}
diff --git a/tests/DiaryBundle/Diary/DiaryItemTest.php b/tests/DiaryBundle/Diary/DiaryItemTest.php
index c8eff750a..a48cfa493 100644
--- a/tests/DiaryBundle/Diary/DiaryItemTest.php
+++ b/tests/DiaryBundle/Diary/DiaryItemTest.php
@@ -3,14 +3,14 @@
namespace Camdram\Tests\DiaryBundle\Diary;
use Acts\DiaryBundle\Diary\DiaryItem;
-use Acts\DiaryBundle\Event\SingleDayEvent;
+use Acts\DiaryBundle\Model\Event;
use PHPUnit\Framework\TestCase;
class DiaryItemTest extends TestCase
{
public function testDiaryItem()
{
- $event = new SingleDayEvent();
+ $event = new Event();
$event->setName('Test Event');
$item = new DiaryItem();
diff --git a/tests/DiaryBundle/Diary/DiaryRowTest.php b/tests/DiaryBundle/Diary/DiaryRowTest.php
index b8c057d27..16738ac01 100644
--- a/tests/DiaryBundle/Diary/DiaryRowTest.php
+++ b/tests/DiaryBundle/Diary/DiaryRowTest.php
@@ -4,8 +4,7 @@
use Acts\DiaryBundle\Diary\DiaryItem;
use Acts\DiaryBundle\Diary\DiaryRow;
-use Acts\DiaryBundle\Event\MultiDayEvent;
-use Acts\DiaryBundle\Event\SingleDayEvent;
+use Acts\DiaryBundle\Model\Event;
use PHPUnit\Framework\TestCase;
class DiaryRowTest extends TestCase
@@ -31,7 +30,7 @@ public function testGetTimes()
public function testAddSingleDayEvent()
{
- $event = new SingleDayEvent();
+ $event = new Event();
$event->setDate(new \DateTime('2014-02-03'));
$event->setStartTime(new \DateTime('14:00'));
$event->setEndTime(new \DateTime('15:00'));
@@ -45,7 +44,7 @@ public function testAddSingleDayEvent()
public function testAddMultiDayEvent()
{
- $event = new MultiDayEvent();
+ $event = new Event();
$event->setStartDate(new \DateTime('2014-02-02'));
$event->setEndDate(new \DateTime('2014-02-05'));
$event->setStartTime(new \DateTime('14:00'));
@@ -60,7 +59,7 @@ public function testAddMultiDayEvent()
public function testAddMultiDayEvent_OverlapStart()
{
- $event = new MultiDayEvent();
+ $event = new Event();
$event->setStartDate(new \DateTime('2014-01-30'));
$event->setEndDate(new \DateTime('2014-02-02'));
$event->setStartTime(new \DateTime('14:00'));
@@ -75,7 +74,7 @@ public function testAddMultiDayEvent_OverlapStart()
public function testAddMultiDayEvent_OverlapEnd()
{
- $event = new MultiDayEvent();
+ $event = new Event();
$event->setStartDate(new \DateTime('2014-02-06'));
$event->setEndDate(new \DateTime('2014-02-10'));
$event->setStartTime(new \DateTime('14:00'));
@@ -90,7 +89,7 @@ public function testAddMultiDayEvent_OverlapEnd()
public function testCanAccept_WithinTimeThreshold()
{
- $event = new SingleDayEvent();
+ $event = new Event();
$event->setDate(new \DateTime('2014-02-01'));
$event->setStartTime(new \DateTime('14:00'));
$event->setEndTime(new \DateTime('15:00'));
@@ -99,7 +98,7 @@ public function testCanAccept_WithinTimeThreshold()
public function testCanAccept_OutsideTimeThreshold()
{
- $event = new SingleDayEvent();
+ $event = new Event();
$event->setDate(new \DateTime('2014-02-01'));
$event->setStartTime(new \DateTime('16:00'));
$event->setEndTime(new \DateTime('17:00'));
@@ -108,13 +107,13 @@ public function testCanAccept_OutsideTimeThreshold()
public function testCanAccept_Clash()
{
- $event1 = new SingleDayEvent();
+ $event1 = new Event();
$event1->setDate(new \DateTime('2014-02-01'));
$event1->setStartTime(new \DateTime('14:00'));
$event1->setEndTime(new \DateTime('15:00'));
$this->row->addEvent($event1);
- $event2 = new SingleDayEvent();
+ $event2 = new Event();
$event2->setDate(new \DateTime('2014-02-01'));
$event2->setStartTime(new \DateTime('14:00'));
$event2->setEndTime(new \DateTime('15:00'));
@@ -124,14 +123,14 @@ public function testCanAccept_Clash()
public function testCanAccept_MultiDay()
{
- $event1 = new MultiDayEvent();
+ $event1 = new Event();
$event1->setStartDate(new \DateTime('2014-02-02'));
$event1->setEndDate(new \DateTime('2014-02-04'));
$event1->setStartTime(new \DateTime('14:00'));
$event1->setEndTime(new \DateTime('15:00'));
$this->row->addEvent($event1);
- $event2 = new SingleDayEvent();
+ $event2 = new Event();
$event2->setDate(new \DateTime('2014-02-01'));
$event2->setStartTime(new \DateTime('14:00'));
$event2->setEndTime(new \DateTime('15:00'));
@@ -141,14 +140,14 @@ public function testCanAccept_MultiDay()
public function testCanAccept_MultiDayClash()
{
- $event1 = new MultiDayEvent();
+ $event1 = new Event();
$event1->setStartDate(new \DateTime('2014-02-02'));
$event1->setEndDate(new \DateTime('2014-02-04'));
$event1->setStartTime(new \DateTime('14:00'));
$event1->setEndTime(new \DateTime('15:00'));
$this->row->addEvent($event1);
- $event2 = new SingleDayEvent();
+ $event2 = new Event();
$event2->setDate(new \DateTime('2014-02-02'));
$event2->setStartTime(new \DateTime('14:00'));
$event2->setEndTime(new \DateTime('15:00'));
diff --git a/tests/DiaryBundle/Diary/DiaryWeekTest.php b/tests/DiaryBundle/Diary/DiaryWeekTest.php
index b504e0a8e..8f001ccb5 100644
--- a/tests/DiaryBundle/Diary/DiaryWeekTest.php
+++ b/tests/DiaryBundle/Diary/DiaryWeekTest.php
@@ -3,7 +3,7 @@
namespace Camdram\Tests\DiaryBundle\Diary;
use Acts\DiaryBundle\Diary\Week;
-use Acts\DiaryBundle\Event\SingleDayEvent;
+use Acts\DiaryBundle\Model\Event;
use PHPUnit\Framework\TestCase;
class DiaryWeekTest extends TestCase
@@ -50,7 +50,7 @@ public function testGetters()
public function testAddEvent()
{
- $event = new SingleDayEvent();
+ $event = new Event();
$event->setDate(new \DateTime('2014-02-01'));
$event->setStartTime(new \DateTime('14:00'));
$event->setEndTime(new \DateTime('15:00'));
@@ -64,12 +64,12 @@ public function testAddEvent()
public function testAddEvent_DifferentDays()
{
- $event1 = new SingleDayEvent();
+ $event1 = new Event();
$event1->setDate(new \DateTime('2014-01-29'));
$event1->setStartTime(new \DateTime('14:00'));
$event1->setEndTime(new \DateTime('15:00'));
- $event2 = new SingleDayEvent();
+ $event2 = new Event();
$event2->setDate(new \DateTime('2014-02-01'));
$event2->setStartTime(new \DateTime('14:00'));
$event2->setEndTime(new \DateTime('15:00'));
@@ -83,12 +83,12 @@ public function testAddEvent_DifferentDays()
public function testAddEvent_SameDay()
{
- $event1 = new SingleDayEvent();
+ $event1 = new Event();
$event1->setDate(new \DateTime('2014-01-29'));
$event1->setStartTime(new \DateTime('14:00'));
$event1->setEndTime(new \DateTime('15:00'));
- $event2 = new SingleDayEvent();
+ $event2 = new Event();
$event2->setDate(new \DateTime('2014-01-29'));
$event2->setStartTime(new \DateTime('14:00'));
$event2->setEndTime(new \DateTime('15:00'));
diff --git a/tests/DiaryBundle/Event/AbstractEventTest.php b/tests/DiaryBundle/Event/AbstractEventTest.php
deleted file mode 100644
index 20d583766..000000000
--- a/tests/DiaryBundle/Event/AbstractEventTest.php
+++ /dev/null
@@ -1,26 +0,0 @@
-getMockForAbstractClass('\\Acts\\DiaryBundle\\Event\\AbstractEvent');
- $event->setName('Test Event');
- $event->setVenue('Test Venue');
- $event->setStartTime(new \DateTime('14:00'));
- $event->setEndTime(new \DateTime('16:00'));
- $event->setLink('http://www.testevent.com/');
- $event->setVenueLink('http://www.testvenue.com/');
-
- $this->assertEquals('Test Event', $event->getName());
- $this->assertEquals('Test Venue', $event->getVenue());
- $this->assertEquals('14:00', $event->getStartTime()->format('H:i'));
- $this->assertEquals('16:00', $event->getEndTime()->format('H:i'));
- $this->assertEquals('http://www.testevent.com/', $event->getLink());
- $this->assertEquals('http://www.testvenue.com/', $event->getVenueLink());
- }
-}
diff --git a/tests/DiaryBundle/Event/MultiDayEventTest.php b/tests/DiaryBundle/Event/MultiDayEventTest.php
deleted file mode 100644
index 7b6c0ecf7..000000000
--- a/tests/DiaryBundle/Event/MultiDayEventTest.php
+++ /dev/null
@@ -1,19 +0,0 @@
-setStartDate(new \DateTime('2014-02-01'));
- $event->setEndDate(new \DateTime('2014-02-07'));
-
- $this->assertEquals('1 February 2014', $event->getStartDate()->format('j F Y'));
- $this->assertEquals('7 February 2014', $event->getEndDate()->format('j F Y'));
- }
-}
diff --git a/tests/DiaryBundle/Event/SingleDayEventTest.php b/tests/DiaryBundle/Event/SingleDayEventTest.php
deleted file mode 100644
index 235387ee5..000000000
--- a/tests/DiaryBundle/Event/SingleDayEventTest.php
+++ /dev/null
@@ -1,16 +0,0 @@
-setDate(new \DateTime('2014-02-01'));
- $this->assertEquals('1 February 2014', $event->getDate()->format('j F Y'));
- }
-}
diff --git a/tests/RestTestCase.php b/tests/RestTestCase.php
index 6172c0893..8a212e450 100644
--- a/tests/RestTestCase.php
+++ b/tests/RestTestCase.php
@@ -4,6 +4,7 @@
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\BrowserKit\Cookie;
use HWI\Bundle\OAuthBundle\Security\Core\Authentication\Token\OAuthToken;
+use Sabre\VObject;
use Acts\CamdramSecurityBundle\Entity\AccessControlEntry;
use Acts\CamdramSecurityBundle\Security\Acl\AclProvider;
@@ -81,4 +82,15 @@ protected function doXmlRequest($url, $params = [])
$this->assertContains('text/xml', $response->headers->get('Content-Type'));
return new \SimpleXMLElement($response->getContent());
}
+
+ protected function doICalRequest($url)
+ {
+ $this->client->request('GET', $url);
+ $response = $this->client->getResponse();
+ $this->assertEquals(200, $response->getStatusCode());
+ $this->assertContains('text/calendar', $response->headers->get('Content-Type'));
+ $vobj = VObject\Reader::read($response->getContent());
+ $this->assertEquals(0, count($vobj->validate()));
+ return $vobj;
+ }
}