Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diary refactor #530

Merged
merged 4 commits into from Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/Resources/views/audition/diary.html.twig
Expand Up @@ -7,8 +7,9 @@
<ul class="inline-list right">
<li><a href="{{ path('get_auditions') }}">List View</a></li>
<li>Diary view</li>
<li><a href="auditions.rss"><i class="fa fa-rss"></i> RSS Feed</a></li>
<li><a href="auditions.txt"><i class="fa fa-file-text-o"></i> Plain Text</a></li>
<li><a href="{{ path('get_auditions_diary', {_format: 'ics'}) }}"><i class="fa fa-calendar"></i> iCal</a></li>
<li><a href="{{ path('get_auditions', {_format: 'rss'}) }}"><i class="fa fa-rss"></i> RSS Feed</a></li>
<li><a href="{{ path('get_auditions', {_format: 'txt'}) }}"><i class="fa fa-file-text-o"></i> Plain Text</a></li>
</ul>

<h3>Auditions</h3>
Expand Down
5 changes: 3 additions & 2 deletions app/Resources/views/audition/index.html.twig
Expand Up @@ -9,8 +9,9 @@
<ul role="navigation">
<li><i class="fa fa-list"></i> List view</li>
<li><a href="{{ path('get_auditions_diary') }}"><i class="fa fa-calendar"></i> Diary View</a></li>
<li><a href="auditions.rss"><i class="fa fa-rss"></i> RSS Feed</a></li>
<li><a href="auditions.txt"><i class="fa fa-file-text-o"></i> Plain Text</a></li>
<li><a href="{{ path('get_auditions_diary', {_format: 'ics'}) }}"><i class="fa fa-calendar"></i> iCal</a></li>
<li><a href="{{ path('get_auditions', {_format: 'rss'}) }}"><i class="fa fa-rss"></i> RSS Feed</a></li>
<li><a href="{{ path('get_auditions', {_format: 'txt'}) }}"><i class="fa fa-file-text-o"></i> Plain Text</a></li>
</ul>
{% endblock %}

Expand Down
3 changes: 1 addition & 2 deletions app/Resources/views/diary/toolbar.html.twig
Expand Up @@ -2,8 +2,7 @@
<div class="split-header">
<h3>Diary</h3>
<ul role="navigation">
<li><a href="diary.ics"><i class="fa fa-calendar"></i> iCal</a></li>
<li><a href="diary.rss"><i class="fa fa-rss"></i> RSS</a></li>
<li><a href="{{ url('acts_camdram_diary', {_format: 'ics'}) }}"><i class="fa fa-calendar"></i> iCal</a></li>
</ul>
</div>

Expand Down
@@ -1,2 +1 @@
<h3>Shows</h3>
{{ render_diary(diary) }}
12 changes: 11 additions & 1 deletion app/Resources/views/society/show.html.twig
Expand Up @@ -68,7 +68,17 @@
</div>

<div class="row">
{{ render(url('get_society_events', {identifier: society.slug})) }}
<div class="split-header">
<h3>Shows</h3>
<ul role="navigation">
<li>
<a href="{{ path('get_society_diary', {identifier: society.slug, _format: 'ics'}) }}">
<i class="fa fa-calendar"></i> iCal
</a>
</li>
</ul>
</div>
{{ render(url('get_society_diary', {identifier: society.slug})) }}
</div>

{% endblock %}
12 changes: 11 additions & 1 deletion app/Resources/views/venue/show.html.twig
Expand Up @@ -78,7 +78,17 @@
</div>

<div class="row">
{{ render(url('get_venue_events', {identifier: venue.slug})) }}
<div class="split-header">
<h3>Shows</h3>
<ul role="navigation">
<li>
<a href="{{ path('get_venue_diary', {identifier: venue.slug, _format: 'ics'}) }}">
<i class="fa fa-calendar"></i> iCal
</a>
</li>
</ul>
</div>
{{ render(url('get_venue_diary', {identifier: venue.slug})) }}
</div>
{% endblock %}

Expand Down
9 changes: 7 additions & 2 deletions src/Acts/CamdramApiBundle/Configuration/AnnotationReader.php
Expand Up @@ -13,6 +13,9 @@ class AnnotationReader
{
private $reader;

/**
* @var EntityManagerInterface
*/
private $em;

public function __construct(Reader $reader, EntityManagerInterface $em)
Expand Down Expand Up @@ -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');
Expand All @@ -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());
Expand Down
3 changes: 3 additions & 0 deletions src/Acts/CamdramApiBundle/Serializer/XmlEventSubscriber.php
Expand Up @@ -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)
Expand Down
44 changes: 33 additions & 11 deletions src/Acts/CamdramApiBundle/Service/EntityUrlGenerator.php
Expand Up @@ -6,18 +6,31 @@
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'
);

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)
Expand All @@ -35,38 +48,47 @@ 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;
}

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);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Acts/CamdramBundle/Controller/AuditionController.php
Expand Up @@ -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')
Expand Down
7 changes: 2 additions & 5 deletions src/Acts/CamdramBundle/Controller/DiaryController.php
Expand Up @@ -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);
}
Expand All @@ -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) {
Expand Down
16 changes: 12 additions & 4 deletions src/Acts/CamdramBundle/Controller/OrganisationController.php
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down
37 changes: 0 additions & 37 deletions src/Acts/CamdramBundle/Controller/PerformanceController.php

This file was deleted.