Hi,
On my views I want to show only the next upcoming date repeat (or the last one), usually an event in the next couple of days with views. In order to fix this I added the following code to a module:

function mymodule_views_pre_render(&$view) {
  if($view->name=='home_all_events_block'){
    foreach($view->result as $viewskey => $viewsrow){
      if(isset($view->result[$viewskey]->field_field_campus_event_when)){
$mindate=$view->result[$viewskey]->field_data_field_campus_event_when_field_campus_event_when_v;
        sscanf($mindate, "%d-%d-%d %d:%d:%d", $year, $month, $day, $hour, $minute, $second);
        $mindate = mktime($hour, $minute, $second, $month, $day, $year);
        $found=0;
        $arraycount = count($view->result[$viewskey]->field_field_campus_event_when)-1;
        foreach($view->result[$viewskey]->field_field_campus_event_when as $whenkey => $whenvalue){
          $currdate = $whenvalue['raw']['value'];
          sscanf($currdate, "%d-%d-%d %d:%d:%d", $year, $month, $day, $hour, $minute, $second);
          $currdate = mktime($hour, $minute, $second, $month, $day, $year);
          if( ($whenkey<$arraycount) && ($currdate<=$mindate) ){
            unset($view->result[$viewskey]->field_field_campus_event_when[$whenkey]);
          }
          elseif( ($whenkey<$arraycount) && ($currdate>$mindate) && ($found==0)){
            $found=1;
          }
          elseif( ($whenkey!=$arraycount) && ($found==1) ){
            unset($view->result[$viewskey]->field_field_campus_event_when[$whenkey]);
          }
          elseif( ($whenkey==$arraycount) && ($found==1) ){
            unset($view->result[$viewskey]->field_field_campus_event_when[$whenkey]);
          }
        }
      }
    }
  }
}

Comments

pixelsweatshop’s picture

KarenS, any chance of utilizing what SangersDrupalDude has used in a separate module to be included as a direct fix in the date module?

chiebert’s picture

Is this issue related to node displays or to views? The text of the OP seems to indicate it's a views issue, but I'm pretty sure the current version handles this fine. If it's about node displays, I just posted a discovery over at #1401688: How do I make the node view of a repeating date event only show the specific date of the instance I'm viewing. (which issue seems to point here as a duplicate...).

If all this is irrelevant, just ignore my ramblings. ;)

kjauslin’s picture