| 
					
				 | 
			
			
				@@ -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; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 |