So here's my situation:

We have a third party system in which our donor relations team manages events. I can easily enough pull all of the data for the events out of the SQL database that runs the event system.

What I'm trying to do is call out to our api to retrieve the information, and inject the events into our calendar in real time.

Currently what I'm trying is hooking into views_pre_render and adding rows to the $view->result array.

This works for everything, except the date of the event. Going over the code, it looks like the calendar module does a node load of the ID and reads the date information off of the node it loads, INSTEAD of reading the date information from the result array that already exists.

This bones me, because the events I'm trying to add to the calendar are not, and never will be, nodes. Can anyone help point me in the right direction here? If I can get this working well, I'd like to make a module out of it, but I'm not very well versed in the Calendar module.

Code I've tried that *almost* works:

<?php

function calendar2_views_pre_render(&$view) {
  
  
  

  // CHECK FOR RE EVENTS TO ADD TO THE CALENDAR
  $json = ''; // This is where I retrieve event json from our API.
  
  $events = json_decode($json);

  $results = &$view->result;
  
  foreach($events as $event) {

    $results[] = unserialize(serialize($results[0]));
    $new = (count($results)-1);
    $fd =  $results[$new]->_field_data['nid']['entity'];
   

    //################################## EVENT MANIPULATION
    // NAME
    $results[$new]->node_title = $event->name;
    $fd->title = $event->name;
    // DESCRIPTION
    $results[$new]->field_body[0]['rendered']['#markup'] = $event->description;
    $results[$new]->field_body[0]['raw']['value'] = $event->description;
    $fd->body['und'][0]['value'] = $event->description;
    // DATE
    $results[$new]->field_field_calendar_date[0]['rendered']['#markup'] = date("m/d/Y",strtotime($event->sdate));
    $results[$new]->field_field_calendar_date[0]['raw']['value'] = date("m/d/Y",strtotime($event->sdate))." ".$event->stime;
    $results[$new]->field_field_calendar_date[0]['raw']['value2'] = date("m/d/Y",strtotime($event->edate))." ".$event->etime;
    $results[$new]->field_data_field_calendar_date_field_calendar_date_value2 = date("m/d/Y",strtotime($event->edate))." ".$event->etime;
    $fd->field_calendar_date['und'][0]['value'] = date("m/d/Y",strtotime($event->sdate))." ".$event->stime;
    $fd->field_calendar_date['und'][0]['value2'] = date("m/d/Y",strtotime($event->edate))." ".$event->etime;
    $fd->vid="custom";
    $fd->nid="custom";
    $results[$new]->nid="custom";
    $results[$new]->date_id_field_calendar_date="custom";
    $results[$new]->_field_data['nid']['entity'] = $fd;
     
    
  
  }



}

Comments

vrwired’s picture

great idea - not very handy that it doesn't read date from array and instead goes to node for it. Did you ever figure out why and/or a workaround for that?

I'm looking to do something similar and probably easier though still wrapping my head around what is needed. I'm need to group events or rather, do a count of events and display an image of a number that reflects that count - instead of displaying the actual event name. The list of event names will show on hover for any particular day.

Looks like your code may be something to refer to... how'd your goal end up?

webadpro’s picture

Id be interrested to know if you did manage to fixed your issue.

cameron prince’s picture

cameron prince’s picture

Issue summary: View changes

edited

nishant.bhorodia’s picture

Thank you for the solution @cameronbprince
You think there could be a way to add custom multi-day events ?

Neslee Canil Pinto’s picture

Status: Active » Closed (outdated)