You are here

function gc_views_pre_render in GatherContent 8

Implements hook_views_pre_render().

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

File

./_old.gc.module, line 334

Code

function gc_views_pre_render(&$view) {
  if ($view->name == 'update') {
    $results =& $view->result;
    $used_mappings = array();
    $nids = array();
    foreach ($results as $result) {
      $nids[] = $result->nid;
    }
    $nodes = \Drupal::entityManager()
      ->getStorage('node')
      ->loadMultiple($nids);
    foreach ($nodes as $node) {
      if (!in_array($node->gc_mapping_id, $used_mappings)) {
        $used_mappings[] = $node->gc_mapping_id;
      }
    }
    $selected_projects = array();
    $contents = array();
    $content_obj = new Content();
    $mappings = \Drupal::entityManager()
      ->getStorage('gc_mapping');
    foreach ($mappings as $mapping) {
      if (!in_array($mapping->gc_project_id, $selected_projects)) {
        $selected_projects[] = $mapping->gc_project_id;
        $content = $content_obj
          ->getContents($mapping->gc_project_id);
        foreach ($content as $c) {
          $single_content = array();
          $single_content['gc_updated'] = $c->updated_at;
          $single_content['status'] = $c->status;
          $single_content['name'] = $c->name;
          $contents[$c->id] = $single_content;
        }
      }
    }
    $view->field['gc_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['gc_updated']->templates = $templates;
  }
}