<?php

/**
 * @file
 * Module file. Defines module hooks.
 */

function opigno_forum_app_views_api() {
  return array('api' => '3.0');
}

function opigno_forum_app_opigno_tool($node = NULL) {
  $give = NULL;
  if (isset($node)) {
    $subquery1 = db_select('taxonomy_term_data', 'tt');
    $subquery1->addField('tt', 'tid', 'tid');
    $subquery1->addField('tt', 'vid', 'vid');
    $subquery2 = db_select('taxonomy_vocabulary', 'tv');
    $subquery2->addField('tv', 'vid', 'vid');
    $subquery2->addField('tv', 'machine_name', 'machine_name');
    $subquery2->condition('tv.machine_name', 'forums', '=');
    $query = db_select('og_membership', 'og_m');
    $query->fields('og_m', array('etid', 'entity_type', 'gid'));
    $query->join($subquery1, 'tt', 'og_m.etid=tt.tid');
    $query->join($subquery2, 'tv', 'tt.vid=tv.vid');
    $query->condition('og_m.entity_type', 'taxonomy_term', '=');
    $query->condition('og_m.gid', $node->nid, '=');
    $query->orderBy('og_m.etid', 'ASC');
    $result1 = $query->execute();
    foreach ($result1 as $record) {
      $give = $record->etid;
      break;
    }
  }
  return array(
    'forum' => array(
      'name' => t("Forum"),
      'path' => isset($give) ? "forum/" . $give : '',
      'description' => t("Forums allow teachers and students to communicate."),
    ),
  );
}