only in past + nicer podcast names + fix rassegna
This commit is contained in:
parent
ba615b5706
commit
9fe9412d17
1 changed files with 42 additions and 18 deletions
|
@ -24,13 +24,16 @@ class PodcastRorController extends ControllerBase {
|
||||||
|
|
||||||
private function query($baseQuery) {
|
private function query($baseQuery) {
|
||||||
//TODO: estrai argomento dall'url
|
//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
|
$query = $baseQuery
|
||||||
->condition('status', '1')
|
->condition('status', '1')
|
||||||
->condition('type', $arg, 'IN')
|
->condition('type', $arg, 'IN')
|
||||||
->sort('nid', 'DESC')
|
->condition('field_tx_date', $now_formatted, '<')
|
||||||
->range(0, 20);
|
->sort('field_tx_date', 'DESC')
|
||||||
\Drupal::logger('podcast_ror')->info(var_export(\Drupal::request()->query->get('trxid'), true));
|
->range(0, 30);
|
||||||
|
// \Drupal::logger('podcast_ror')->info(var_export(\Drupal::request()->query->get('trxid'), true));
|
||||||
//$trxid = \Drupal::request()->query->get('trxid');
|
//$trxid = \Drupal::request()->query->get('trxid');
|
||||||
// TODO: se nell'url c'e' un trx=, allora bisogna
|
// TODO: se nell'url c'e' un trx=, allora bisogna
|
||||||
// aggiungere che arg=news_trasmissioni
|
// aggiungere che arg=news_trasmissioni
|
||||||
|
@ -43,9 +46,13 @@ class PodcastRorController extends ControllerBase {
|
||||||
$data['nodes'] = array();
|
$data['nodes'] = array();
|
||||||
foreach($nodes_e as $nid => $node) {
|
foreach($nodes_e as $nid => $node) {
|
||||||
$data['nodes'][$nid] = $node->toArray();
|
$data['nodes'][$nid] = $node->toArray();
|
||||||
|
if( count($data['nodes'][$nid]['body']) > 0 ) {
|
||||||
$data['nodes'][$nid]['summary'] = htmlspecialchars(substr(
|
$data['nodes'][$nid]['summary'] = htmlspecialchars(substr(
|
||||||
html_entity_decode(strip_tags($data['nodes'][$nid]['body'][0]['value'])),
|
html_entity_decode(strip_tags($data['nodes'][$nid]['body'][0]['value'])),
|
||||||
0, 3500), ENT_XML1, 'UTF-8');
|
0, 3500), ENT_XML1, 'UTF-8');
|
||||||
|
} else {
|
||||||
|
$data['nodes'][$nid]['summary'] = "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$first = true;
|
$first = true;
|
||||||
|
@ -54,26 +61,42 @@ class PodcastRorController extends ControllerBase {
|
||||||
$data['nodes'][$nid]['img'] = array();
|
$data['nodes'][$nid]['img'] = array();
|
||||||
foreach( $node->get('field_contenuti_audio')->referencedEntities() as $ai => $entity) {
|
foreach( $node->get('field_contenuti_audio')->referencedEntities() as $ai => $entity) {
|
||||||
$data['nodes'][$nid]['audio'][$ai] = $entity->toArray();
|
$data['nodes'][$nid]['audio'][$ai] = $entity->toArray();
|
||||||
|
|
||||||
//$data['nodes'][$nid]['audio'][$ai]['text'] = print_r($data['nodes'][$nid]['audio'][$ai]['field_audio_link'], true);
|
//$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) {
|
if($node->hasField('field_image')) {
|
||||||
|
$node_images = $node->get('field_image');
|
||||||
|
foreach( $node_images->referencedEntities() as $ai => $entity) {
|
||||||
$arr = $entity->toArray();
|
$arr = $entity->toArray();
|
||||||
$data['nodes'][$nid]['img'][] = array(
|
$data['nodes'][$nid]['img'][] = array(
|
||||||
'uri' => file_create_url($arr['uri'][0]['value']),
|
'uri' => file_create_url($arr['uri'][0]['value']),
|
||||||
// 'raw' => $arr,
|
// '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) {
|
if($first === true) {
|
||||||
// print_r($data['nodes'][$nid]['img']);
|
|
||||||
$first = false;
|
$first = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $data;
|
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');
|
$template = $this->twig->loadTemplate(drupal_get_path('module', 'podcast_ror') . '/templates/podcast.html.twig');
|
||||||
$tmpl_data = [ 'ror' => array('podcast' => $this->query($query),
|
$tmpl_data = [ 'ror' => array('podcast' => $this->query($query),
|
||||||
'url' => \Drupal::service('path.current')->getPath(),
|
'url' => \Drupal::service('path.current')->getPath(),
|
||||||
|
'title' => $title,
|
||||||
)];
|
)];
|
||||||
//$variables['ror']['url'] =
|
//$variables['ror']['url'] =
|
||||||
$xml = $template->render($tmpl_data);
|
$xml = $template->render($tmpl_data);
|
||||||
|
@ -82,18 +105,19 @@ class PodcastRorController extends ControllerBase {
|
||||||
}
|
}
|
||||||
public function podcastAll() {
|
public function podcastAll() {
|
||||||
$query = \Drupal::entityQuery('node');
|
$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) {
|
public function podcastByType($contentType) {
|
||||||
$query = \Drupal::entityQuery('node')
|
$query = \Drupal::entityQuery('node')
|
||||||
->condition('type', $contentType);
|
->condition('type', $contentType);
|
||||||
return $this->podcast($query);
|
// TODO: get "nice name" for $contentType
|
||||||
|
return $this->podcast($query, $contentType);
|
||||||
}
|
}
|
||||||
public function podcastByTrxID($trxID) {
|
public function podcastByTrxID($trxID) {
|
||||||
$query = \Drupal::entityQuery('node')
|
$query = \Drupal::entityQuery('node')
|
||||||
->condition('type', 'news_trasmissioni')
|
->condition('type', 'news_trasmissioni')
|
||||||
->condition('field_trasmissione', $trxID);
|
->condition('field_trasmissione', $trxID);
|
||||||
return $this->podcast($query);
|
// TODO: discover Trx name, and pass it as podcast title
|
||||||
|
return $this->podcast($query, 'Trasmissione ' . $trxID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue