commit 9c00c08235f30264f5f25759e3b13744e1734e2e Author: root Date: Fri Sep 14 16:43:38 2018 +0200 basic functionalities working diff --git a/podcast_ror.info.yml b/podcast_ror.info.yml new file mode 100644 index 0000000..8a1890d --- /dev/null +++ b/podcast_ror.info.yml @@ -0,0 +1,9 @@ +name: Podcast per ROR +type: module +description: 'Podcast specifici per radio ondarossa' +core: 8.x +version: 0.1 +package: Ondarossa +dependencies: + - field + - link diff --git a/podcast_ror.routing.yml b/podcast_ror.routing.yml new file mode 100644 index 0000000..34614d8 --- /dev/null +++ b/podcast_ror.routing.yml @@ -0,0 +1,9 @@ +podcast_ror.all: + path: '/podcast/all.xml' + defaults: + _controller: '\Drupal\podcast_ror\Controller\PodcastRorController::podcastAll' + _title: 'Global podcast' + requirements: + _access: 'TRUE' + options: + no_cache: 'TRUE' diff --git a/src/Controller/PodcastRorController.php b/src/Controller/PodcastRorController.php new file mode 100644 index 0000000..3633ee4 --- /dev/null +++ b/src/Controller/PodcastRorController.php @@ -0,0 +1,61 @@ +state = $state; + $this->twig = $twig; + } + + public static function create(ContainerInterface $container) { + return new static( + $container->get('state'), + $container->get('twig') + ); + } + + private function query() { + //TODO: estrai argomento dall'url + $arg = 'ror_news'; + $query = \Drupal::entityQuery('node'); + $query + ->condition('status', '1') + ->condition('type', $arg) + ->sort('nid', 'DESC') + ->range(0, 10); + $nids = $query->execute(); + // TODO: load contenuti_audio referenced entities + $data = array(); + $data['nodes'] = \Drupal\node\Entity\Node::loadMultiple($nids); + // TODO: metti anche qui toArray() ? sembra piu pratico... + + $data['audio'] = array(); + $first = true; + foreach($data['nodes'] as $nid => $node) { + $data['audio'][$nid] = array(); + foreach( $node->get('field_contenuti_audio')->referencedEntities() as $ai => $audio) { + // print_r(get_class_methods(get_class($audio))); + $data['audio'][$nid][$ai] = $audio->toArray(); + } + if($first === true) { + $first = false; + } + } + return $data; + } + public function podcastAll() { + $template = $this->twig->loadTemplate(drupal_get_path('module', 'podcast_ror') . '/templates/podcast.html.twig'); + $tmpl_data = [ 'ror' => array('podcast' => $this->query()) ]; + $xml = $template->render($tmpl_data); + $resp = new Response($xml, 200, array( + 'Content-Type' => 'application/rss+xml')); + return $resp; + } +} diff --git a/templates/podcast.html.twig b/templates/podcast.html.twig new file mode 100644 index 0000000..6fc053c --- /dev/null +++ b/templates/podcast.html.twig @@ -0,0 +1,49 @@ + + + +Radio Onda Rossa +it-it +La radio di chi se la sente +Ondarossa +Podcast completo +Tutti gli aggiornamenti, i redazionali, le trasmissioni della radio di chi se la sente + + Ondarossa + ondarossa@ondarossa.info + +no + + + +{% for nid, node in ror.podcast.nodes %} + + {% for num, audio in ror.podcast.audio[nid] %} + {% set audiourl = audio.field_audio_link[0].uri %} + {% set ext = audiourl|split('.')|last %} + {% set durata = audio.field_durata[0].value %} + {% set duratamin = durata // 60 %} + {% set duratasec = durata % 60 %} + {{node.getTitle()}} + Description of podcast episode content + {{ node.get('body').getValue().0.value }} + http://example.com/podcast-1 {# node.getLink#} + + {# TODO: detect ogg/mp3 #} + + {# TODO: formatta pubDate #} + Thu, 21 Dec 2016 16:01:07 +0000 + Redazione Ondarossa + 00:{{"%02d" | format(duratamin)}}:{{"%02d" | format(duratasec)}} + no + {{ audiourl }} + {% endfor %} + {# [fields] + {% for field in node.getFields() %} + [[ {{ field.getName() }} ]] + {% endfor %} + [/fields] #} + +{% endfor %} + + +