only in past + nicer podcast names + fix rassegna

This commit is contained in:
root 2022-01-04 01:06:58 +01:00
parent ba615b5706
commit 9fe9412d17

View file

@ -24,13 +24,16 @@ class PodcastRorController extends ControllerBase {
private function query($baseQuery) {
//TODO: estrai argomento dall'url
$arg = array('ror_news', 'redazionali', 'news_trasmissioni');
$arg = array('ror_news', 'redazionali', 'news_trasmissioni', 'rassegna_stampa');
$now = new \Drupal\Core\Datetime\DrupalDateTime('now');
$now_formatted = $now->format(\Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface::DATETIME_STORAGE_FORMAT);
$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));
->condition('field_tx_date', $now_formatted, '<')
->sort('field_tx_date', 'DESC')
->range(0, 30);
// \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
@ -43,9 +46,13 @@ class PodcastRorController extends ControllerBase {
$data['nodes'] = array();
foreach($nodes_e as $nid => $node) {
$data['nodes'][$nid] = $node->toArray();
$data['nodes'][$nid]['summary'] = htmlspecialchars(substr(
html_entity_decode(strip_tags($data['nodes'][$nid]['body'][0]['value'])),
0, 3500), ENT_XML1, 'UTF-8');
if( count($data['nodes'][$nid]['body']) > 0 ) {
$data['nodes'][$nid]['summary'] = htmlspecialchars(substr(
html_entity_decode(strip_tags($data['nodes'][$nid]['body'][0]['value'])),
0, 3500), ENT_XML1, 'UTF-8');
} else {
$data['nodes'][$nid]['summary'] = "";
}
}
$first = true;
@ -54,26 +61,42 @@ class PodcastRorController extends ControllerBase {
$data['nodes'][$nid]['img'] = array();
foreach( $node->get('field_contenuti_audio')->referencedEntities() as $ai => $entity) {
$data['nodes'][$nid]['audio'][$ai] = $entity->toArray();
//$data['nodes'][$nid]['audio'][$ai]['text'] = print_r($data['nodes'][$nid]['audio'][$ai]['field_audio_link'], true);
}
foreach( $node->get('field_image')->referencedEntities() as $ai => $entity) {
$arr = $entity->toArray();
$data['nodes'][$nid]['img'][] = array(
'uri' => file_create_url($arr['uri'][0]['value']),
// 'raw' => $arr,
if($node->hasField('field_image')) {
$node_images = $node->get('field_image');
foreach( $node_images->referencedEntities() as $ai => $entity) {
$arr = $entity->toArray();
$data['nodes'][$nid]['img'][] = array(
'uri' => file_create_url($arr['uri'][0]['value']),
// 'raw' => $arr,
);
}
} else { // alcuni content_type non hanno immagine (rassegna stampa)
$data['nodes'][$nid]['img'][] = [];
}
$data['nodes'][$nid]['tx'] = "";
if($node->getType() == 'news_trasmissioni') {
$tx = \Drupal\taxonomy\Entity\Term::load(
$node->get('field_trasmissione')->target_id
);
if($tx !== null) {
$data['nodes'][$nid]['tx'] = $tx->getName();
}
}
if($first === true) {
// print_r($data['nodes'][$nid]['img']);
$first = false;
}
}
return $data;
}
public function podcast($query) {
public function podcast($query, $title) {
// TODO: add $title argument to the function
$template = $this->twig->loadTemplate(drupal_get_path('module', 'podcast_ror') . '/templates/podcast.html.twig');
$tmpl_data = [ 'ror' => array('podcast' => $this->query($query),
'url' => \Drupal::service('path.current')->getPath(),
'title' => $title,
)];
//$variables['ror']['url'] =
$xml = $template->render($tmpl_data);
@ -82,18 +105,19 @@ class PodcastRorController extends ControllerBase {
}
public function podcastAll() {
$query = \Drupal::entityQuery('node');
return $this->podcast($query);
return $this->podcast($query, 'Tutti gli aggiornamenti, i redazionali, le trasmissioni della radio di chi se la sente');
}
//public function podcastByType(NodeInterface $ctype) {
public function podcastByType($contentType) {
$query = \Drupal::entityQuery('node')
->condition('type', $contentType);
return $this->podcast($query);
// TODO: get "nice name" for $contentType
return $this->podcast($query, $contentType);
}
public function podcastByTrxID($trxID) {
$query = \Drupal::entityQuery('node')
->condition('type', 'news_trasmissioni')
->condition('field_trasmissione', $trxID);
return $this->podcast($query);
// TODO: discover Trx name, and pass it as podcast title
return $this->podcast($query, 'Trasmissione ' . $trxID);
}
}