added prev next nav in perf nodes

This commit is contained in:
2021-12-09 22:20:39 +01:00
parent 5171cef481
commit 3730ae432a
5 changed files with 197 additions and 3 deletions
@@ -210,3 +210,114 @@ function perfart_init() {
// }
/**
* Implements hook_block_info().
*/
function perfart_block_info() {
$blocks = array();
$blocks['perf_prevnext'] = array(
'info' => t('Performance prev next btns'),
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function perfart_block_view($delta='') {
$block = array();
switch($delta) {
case 'perf_prevnext' :
$block['content'] = perf_prevnext_view();
break;
}
return $block;
}
/**
* Custom function to assemble renderable array for block content.
* Returns a renderable array with the block content.
* @return
* returns a renderable array of block content.
*/
function perf_prevnext_view() {
global $language;
// get current perf nid
$current_perf = menu_get_object();
if ($current_perf && $current_perf->nid && $current_perf->type == 'performance') {
// dsm($current_perf);
// You have a valid node to work with.
// get all perfs
$query = new EffectuationEntityFieldQuery;
$result = $query->execute();
$perfs = array();
foreach ($result['node'] as $eff) {
$eff = node_load($eff->nid);
if(!isset($eff->field_date_de_debut) || !isset($eff->field_performances))
continue;
$debut = $eff->field_date_de_debut['und'][0]['value'];
//1969/06/06-18:00
$pattern = '/^(\d{4})\/?(\d{2})?\/?(\d{2})?-?(\d{2})?:?+(\d{2})?$/';
preg_match($pattern, $debut, $debutMatches);
if(!isset($debutMatches[1]))
continue;
$perfadded = array();
foreach ($eff->field_performances['und'] as $perf) {
if(in_array($perf['target_id'], $perfadded))
continue;
$perfadded[] = $perf['target_id'];
$perfs[] = $perf['target_id'];
}
}
dsm($perfs);
// get prev and next
// build links
$index = array_search($current_perf->nid, $perfs);
dsm($index);
$list = array();
if($index > 0){
$prev_nid = $perfs[$index-1];
$prev = node_load($prev_nid);
$prev_path = drupal_get_path_alias('node/'.$prev->nid, $language->language);
$prev_link = l('< ' . $prev->title, $prev_path, array('html'=>true));
$list['items'][] = array(
'data' => $prev_link,
'class' => array('perf-prev-link'),
);
}
if ($index < count($perfs)-1) {
$next_nid = $perfs[$index+1];
$next = node_load($next_nid);
$next_path = drupal_get_path_alias('node/'.$next->nid, $language->language);
$next_link = l($next->title . ' >', $next_path, array('html'=>true));
$list['items'][] = array(
'data' => $next_link,
'class' => array('perf-next-link'),
);
}
$list['attributes']['id'] = "perf-prev-next-btns";
dsm($list);
return theme('item_list', $list);
}
return null;
}
@@ -258,7 +258,7 @@ function perfart_get_performances(){
$count = $count_query->count()->execute();
pager_default_initialize($count, $limit);
foreach ($result['node'] as $eff) {
foreach ($result['node'] as $eff) {
$eff = node_load($eff->nid);
//$eff = entity_load('node', array($eff->nid), NULL, FALSE);
// dsm($eff, '$eff');
@@ -445,7 +445,7 @@ function perfart_get_performances(){
# filter artistes
// $date['filters']['peoples'] = $personnes;
pager_default_initialize($count, $limit);
// pager_default_initialize($count, $limit);
// $data[] = $date;