2010-01-30 4 views
5

filefield_stats 모듈은 API을 통해 Views 모듈에 데이터를 노출하는 기능을 제공합니다. filefield_stats 스키마는 다음과 같다 :해당 API를 사용하여 모듈 2의 데이터를 Views2에 노출

function filefield_stats_schema() { 
    $schema['filefield_stats'] = array(
    'fields' => array(  
     'fid'  => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'Primary Key: the {files}.fid'), 
     'vid'  => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'Primary Key: the {node}.vid'),  
     'uid'  => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'The {users}.uid of the downloader'), 
     'timestamp' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'The timestamp of the download'), 
     'hostname' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => '', 'description' => 'The hostname downloading the file (usually IP)'), 
     'referer' => array('type' => 'text', 'not null' => FALSE, 'description' => 'Referer for the download'), 
    ), 
    'indexes' => array('fid_vid' => array('fid', 'vid')), 
); 
    return $schema; 
} 

음, 그래서 나는 & 여기에, 모듈의 루트 디렉토리에 filefield_stats.views.inc 파일을 추가 filefield_stats.module에 hook_views_api()를 구현 그것은 :

// $Id$ 

/** 
* @file 
* Provide the ability of exposing data to Views2, for filefield_stats module. 
*/ 

function filefield_stats_views_data() { 
    $data = array(); 
    $data['filefield_stats']['table']['group'] = t('FilefieldStats'); 

    // Referencing the {node_revisions} table. 
    $data['filefield_stats']['table']['join'] = array(
     'node_revisions' => array(
      'left_field' => 'vid', 
      'field' => 'vid', 
     ), 
     'files' => array(
      'left_field' => 'fid', 
      'field' => 'fid', 
     ), 
     'users' => array(
      'left_field' => 'uid', 
      'field' => 'uid', 
     ), 
    ); 

    // Introducing filefield_stats table fields to Views2. 
    // vid: The node's revision ID which wrapped the downloaded file 
    $data['filefield_stats']['vid'] = array(
     'title' => t('Node revision ID'), 
     'help' => t('The node\'s revision ID which wrapped the downloaded file'), 
     'relationship' => array(
      'base' => 'node_revisions', 
      'field' => 'vid', 
      'handler' => 'views_handler_relationship', 
      'label' => t('Node Revision Reference.'), 
     ), 
    ); 

    // uid: The ID of the user who downloaded the file. 
    $data['filefield_stats']['uid'] = array(
     'title' => t('User ID'), 
     'help' => t('The ID of the user who downloaded the file.'), 
     'relationship' => array(
      'base' => 'users', 
      'field' => 'uid', 
      'handler' => 'views_handler_relationship', 
      'label' => t('User Reference.'), 
     ), 
    ); 

    // fid: The ID of the downloaded file. 
    $data['filefield_stats']['fid'] = array(
     'title' => t('File ID'), 
     'help' => t('The ID of the downloaded file.'), 
     'relationship' => array(
      'base' => 'files', 
      'field' => 'fid', 
      'handler' => 'views_handler_relationship', 
      'label' => t('File Reference.'), 
     ), 
    ); 

    // hostname: The hostname which the file has been downloaded from. 
    $data['filefield_stats']['hostname'] = array(
     'title' => t('The Hostname'), 
     'help' => t('The hostname which the file has been downloaded from.'), 
     'field' => array(
      'handler' => 'views_handler_field', 
      'click sortable' => TRUE, 
     ), 
     'sort' => array(
      'handler' => 'views_handler_sort', 
     ), 
     'filter' => array(
      'handler' => 'views_handler_filter_string', 
     ), 
     'argument' => array(
      'handler' => 'views_handler_argument_string', 
     ), 
    ); 

    // referer: The referer address which the file download link has been triggered from. 
    $data['filefield_stats']['referer'] = array(
     'title' => t('The Referer'), 
     'help' => t('The referer which the file download link has been triggered from.'), 
     'field' => array(
      'handler' => 'views_handler_field', 
      'click sortable' => TRUE, 
     ), 
     'sort' => array(
      'handler' => 'views_handler_sort', 
     ), 
     'filter' => array(
      'handler' => 'views_handler_filter_string', 
     ), 
     'argument' => array(
      'handler' => 'views_handler_argument_string', 
     ), 
    ); 

    // timestamp: The time of the download. 
    $data['filefield_stats']['timestamp'] = array(
     'title' => t('Download Time'), 
     'help' => t('The time of the download.'), 
     'field' => array(
      'handler' => 'views_handler_field_date', 
      'click sortable' => TRUE, 
     ), 
     'sort' => array(
      'handler' => 'views_handler_sort_date', 
     ), 
     'filter' => array(
      'handler' => 'views_handler_filter_date', 
     ), 
    ); 

    return $data; 
} // filefield_stats_views_data() 

Views2 문서에 따르면 이것은 최소한으로 작동해야한다고 생각합니다. 그러나 그렇지 않습니다! 또한 어떤 종류의 오류도 없다. 뷰 UI를 통해 들어 왔을 때, filefield_stats 데이터에 대해서는 아무 것도 없다. 어떤 생각?

답변

3

문제 이름이 hook_views_data() 인 경우 filefield_stats_views_data()이어야합니다. hook_views_api()filefield_stats_views_api()이어야합니다.

모듈에 구현할 때 항상 모듈 이름으로 후크를 교체하십시오.

+0

오, 모듈 소스에서 후크 이름이 정확합니다. 오타, 내가 질문을 쓸 때. 나는 질문을 갱신 할 것이다, 고마워. – sepehr

+0

죄송합니다. 죄송합니다. p. 캐시를 비우려고 했습니까? 테이블을 두 번 확인 하시겠습니까? – Januz

+0

예, 플러시했습니다. 모듈을 제거하고 다시 설치 했는데도 아무 것도 없습니다. 사실, Drupal db api를 통해 filefield_stats 테이블을 쿼리하려고합니다. 불행히도이 문제로 고생 할 시간이 없습니다. 다시 감사합니다. – sepehr