Browse Source

add podcast by-type e by-trx

root 3 years ago
parent
commit
42fe3cacb8
2 changed files with 35 additions and 13 deletions
  1. 12 3
      podcast_ror.routing.yml
  2. 23 10
      src/Controller/PodcastRorController.php

+ 12 - 3
podcast_ror.routing.yml

@@ -7,12 +7,21 @@ podcast_ror.all:
         _access: 'TRUE'
     options:
         no_cache: 'TRUE'
-podcast_ror.any:
-    path: '/podcast/{ctype}.xml'
+podcast_ror.bytype:
+    path: '/podcast/by-type/{contentType}/podcast.xml'
     defaults:
-        _controller: '\Drupal\podcast_ror\Controller\PodcastRorController::podcastAny'
+        _controller: '\Drupal\podcast_ror\Controller\PodcastRorController::podcastByType'
         _title: 'Podcast for any type'
     requirements:
         _access: 'TRUE'
     options:
         no_cache: 'TRUE'
+podcast_ror.bytrxid:
+    path: '/podcast/by-trx-id/{trxID}/podcast.xml'
+    defaults:
+        _controller: '\Drupal\podcast_ror\Controller\PodcastRorController::podcastByTrxID'
+        _title: 'Basic podcast for a single show'
+    requirements:
+        _access: 'TRUE'
+    options:
+        no_cache: 'TRUE'

+ 23 - 10
src/Controller/PodcastRorController.php

@@ -22,15 +22,20 @@ class PodcastRorController extends ControllerBase {
         );
     }
 
-    private function query() {
+    private function query($baseQuery) {
         //TODO: estrai argomento dall'url
         $arg = array('ror_news', 'redazionali', 'news_trasmissioni');
-        $query = \Drupal::entityQuery('node');
-        $query
+        $query = $baseQuery
             ->condition('status', '1')
             ->condition('type', $arg, 'IN')
             ->sort('nid', 'DESC')
             ->range(0, 20);
+        \Drupal::logger('podcast_ror')->info(var_export(\Drupal::request()->query->get('trxid'), true));
+        //$trxid = \Drupal::request()->query->get('trxid');
+        // TODO: se nell'url c'e' un trx=, allora bisogna
+        // aggiungere che  arg=news_trasmissioni
+        // fare join con node__field_trasmissione ON // node.nid = node__field_trasmissione.entity_id
+        // condition: node__field_trasmissione.field_trasmissione_target_id=$trx
         $nids = $query->execute();
         // TODO: load contenuti_audio referenced entities
         $data = array();
@@ -65,10 +70,9 @@ class PodcastRorController extends ControllerBase {
         }
         return $data;
     }
-    public function podcast($path) {
-        // TODO: use $path
+    public function podcast($query) {
         $template = $this->twig->loadTemplate(drupal_get_path('module', 'podcast_ror') . '/templates/podcast.html.twig');
-        $tmpl_data = [ 'ror' => array('podcast' => $this->query(),
+        $tmpl_data = [ 'ror' => array('podcast' => $this->query($query),
             'url' => \Drupal::service('path.current')->getPath(),
         )];
         //$variables['ror']['url'] = 
@@ -77,10 +81,19 @@ class PodcastRorController extends ControllerBase {
         return $resp;
     }
     public function podcastAll() {
-        return $this->podcast('all.xml');
+        $query = \Drupal::entityQuery('node');
+        return $this->podcast($query);
+    }
+    //public function podcastByType(NodeInterface $ctype) {
+    public function podcastByType($contentType) {
+        $query = \Drupal::entityQuery('node')
+            ->condition('type', $contentType);
+        return $this->podcast($query);
     }
-    public function podcastAny(NodeInterface $ctype) {
-        return new Response('tipo: BOH', 200,array( 'Content-Type' => 'application/rss+xml'));
-        // return $this->podcast($ctype);
+    public function podcastByTrxID($trxID) {
+        $query = \Drupal::entityQuery('node')
+            ->condition('type', 'news_trasmissioni')
+            ->condition('field_trasmissione', $trxID);
+        return $this->podcast($query);
     }
 }