You are here

function gathercontent_views_pre_render in GatherContent 7.3

Implements hook_views_pre_render().

Show real-time data in views resources "effective" way.

File

./gathercontent.module, line 1081

Code

function gathercontent_views_pre_render(&$view) {
  if ($view->name == 'update') {
    $results =& $view->result;
    $used_mappings = array();
    $nids = array();
    foreach ($results as $result) {
      $nids[] = $result->nid;
    }
    $nodes = node_load_multiple($nids);
    foreach ($nodes as $node) {
      if (!in_array($node->gathercontent_mapping_id, $used_mappings)) {
        $used_mappings[] = $node->gathercontent_mapping_id;
      }
    }
    $selected_projects = array();
    $contents = array();
    $content_obj = new \GatherContent\Content();
    $mappings = entity_load('gathercontent_mapping', $used_mappings);
    foreach ($mappings as $mapping) {
      if (!in_array($mapping->gathercontent_project_id, $selected_projects)) {
        $selected_projects[] = $mapping->gathercontent_project_id;
        $content = $content_obj
          ->getContents($mapping->gathercontent_project_id);
        foreach ($content as $c) {
          $single_content = array();
          $single_content['gathercontent_updated'] = $c->updated_at;
          $single_content['status'] = $c->status;
          $single_content['name'] = $c->name;
          $contents[$c->id] = $single_content;
        }
      }
    }
    $view->field['gathercontent_status']->contents = $contents;
  }
  if ($view->name == 'mapping') {
    $project_obj = new Project();
    $projects = $project_obj
      ->getProjectObjects();
    $temp_obj = new Template();
    $templates = array();
    foreach ($projects as $project) {
      $remote_templates = $temp_obj
        ->getTemplatesObject($project->id);
      foreach ($remote_templates as $remote_template) {
        $templates[$remote_template->id]['updated_at'] = $remote_template->updated_at;
      }
    }
    $view->field['gathercontent_updated']->templates = $templates;
  }
}