Work in progress...

CommentFileSizeAuthor
#5 Screen shot 2011-05-05 at 3.50.56 PM.png201.26 KBosman
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

greg.harvey’s picture

Awesome, let me know if we can help!

nicholasThompson’s picture

Status: Needs work » Fixed

Marking as fixed as the dev branch now has this feature. Please re-open if it needs more work, or open another ticket if there are issues with it....

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

osman’s picture

Status: Closed (fixed) » Active

Hi there,

I am having an issue with Views. Generated stats URL has vid missing. Thus, the links returns "Page not found" errors.

The CCK file field is set to "Generic files + Stats URL" in content-type Display settings and also in the view I attached below.

Apparently the stats URLs forget the node vid when they are generated only in the views. Any suggestions or fixes are very much welcome.

Thanks,
osman

Formatted file link rendered on the view page:
http://www.example.com/_/filefield_stats/73//3/0d12714bb4d03622ecbcf8383...

Formatted file link rendered on the node page:
http:/www.example.com/_/filefield_stats/73/82/3/8485a696367d8ea490646204fe8284cb

The copy of the VIEW:

$view = new view;
$view->name = 'client_files';
$view->description = 'Client Resource Files';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
  'field_clientfile_file_fid' => array(
    'label' => 'File',
    'required' => 0,
    'delta' => -1,
    'id' => 'field_clientfile_file_fid',
    'table' => 'node_data_field_clientfile_file',
    'field' => 'field_clientfile_file_fid',
    'relationship' => 'none',
  ),
));
$handler->override_option('fields', array(
  'field_clientfile_cat_value' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'none',
    'format' => 'default',
    'multiple' => array(
      'group' => TRUE,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => FALSE,
    ),
    'exclude' => 1,
    'id' => 'field_clientfile_cat_value',
    'table' => 'node_data_field_clientfile_cat',
    'field' => 'field_clientfile_cat_value',
    'relationship' => 'none',
  ),
  'field_clientfile_desc_value' => array(
    'label' => 'Description',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'widget',
    'format' => 'default',
    'multiple' => array(
      'group' => TRUE,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => FALSE,
    ),
    'exclude' => 1,
    'id' => 'field_clientfile_desc_value',
    'table' => 'node_data_field_clientfile_desc',
    'field' => 'field_clientfile_desc_value',
    'relationship' => 'none',
  ),
  'title' => array(
    'label' => 'Title',
    'alter' => array(
      'alter_text' => 1,
      'text' => '<strong title="[field_clientfile_desc_value]">[title]</strong>',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
  'field_clientfile_file_fid' => array(
    'label' => 'Download',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'custom',
    'format' => 'stats_default',
    'multiple' => array(
      'group' => TRUE,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => FALSE,
    ),
    'exclude' => 0,
    'id' => 'field_clientfile_file_fid',
    'table' => 'node_data_field_clientfile_file',
    'field' => 'field_clientfile_file_fid',
    'relationship' => 'field_clientfile_file_fid',
  ),
  'filesize' => array(
    'label' => 'Size',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'file_size_display' => 'formatted',
    'exclude' => 0,
    'id' => 'filesize',
    'table' => 'files',
    'field' => 'filesize',
    'relationship' => 'field_clientfile_file_fid',
  ),
  'field_clientfile_cat2_value' => array(
    'label' => 'Category',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'custom',
    'format' => 'default',
    'multiple' => array(
      'group' => TRUE,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => FALSE,
    ),
    'exclude' => 0,
    'id' => 'field_clientfile_cat2_value',
    'table' => 'node_data_field_clientfile_cat2',
    'field' => 'field_clientfile_cat2_value',
    'relationship' => 'none',
  ),
  'field_clientfile_date_value' => array(
    'label' => 'Date',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'widget',
    'format' => 'default',
    'multiple' => array(
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_to' => '',
      'group' => '',
    ),
    'repeat' => array(
      'show_repeat_rule' => '',
    ),
    'fromto' => array(
      'fromto' => 'both',
    ),
    'exclude' => 0,
    'id' => 'field_clientfile_date_value',
    'table' => 'node_data_field_clientfile_date',
    'field' => 'field_clientfile_date_value',
    'relationship' => 'none',
  ),
));
$handler->override_option('sorts', array(
  'field_clientfile_cat2_value' => array(
    'order' => 'ASC',
    'delta' => -1,
    'id' => 'field_clientfile_cat2_value',
    'table' => 'node_data_field_clientfile_cat2',
    'field' => 'field_clientfile_cat2_value',
    'relationship' => 'none',
  ),
  'field_clientfile_date_value' => array(
    'order' => 'DESC',
    'delta' => -1,
    'id' => 'field_clientfile_date_value',
    'table' => 'node_data_field_clientfile_date',
    'field' => 'field_clientfile_date_value',
    'relationship' => 'none',
  ),
  'title' => array(
    'order' => 'ASC',
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
));
$handler->override_option('filters', array(
  'status' => array(
    'operator' => '=',
    'value' => '1',
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'status',
    'table' => 'node',
    'field' => 'status',
    'relationship' => 'none',
  ),
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'client_file' => 'client_file',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'relationship' => 'none',
  ),
  'title' => array(
    'operator' => 'contains',
    'value' => '',
    'group' => '0',
    'exposed' => TRUE,
    'expose' => array(
      'use_operator' => 0,
      'operator' => 'title_op',
      'identifier' => 'title',
      'label' => 'Title',
      'optional' => 1,
      'remember' => 0,
    ),
    'case' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
  'field_clientfile_cat_value_many_to_one' => array(
    'operator' => 'or',
    'value' => array(),
    'group' => '0',
    'exposed' => TRUE,
    'expose' => array(
      'use_operator' => 0,
      'operator' => 'field_clientfile_cat_value_many_to_one_op',
      'identifier' => 'cat',
      'label' => '',
      'bef_filter_description' => '',
      'bef_format' => 'bef',
      'optional' => 1,
      'single' => 0,
      'remember' => 0,
      'reduce' => 0,
      'vfs_selective' => 1,
      'vfs_active' => 0,
      'bef_select_all_none' => 0,
    ),
    'id' => 'field_clientfile_cat_value_many_to_one',
    'table' => 'node_data_field_clientfile_cat',
    'field' => 'field_clientfile_cat_value_many_to_one',
    'relationship' => 'none',
    'reduce_duplicates' => 0,
  ),
));
$handler->override_option('access', array(
  'type' => 'role',
  'role' => array(
    '2' => 2,
  ),
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('title', 'Document Library');
$handler->override_option('header', '<p>This is a list of files available to you. You can easily search or sort the list to find the file you are looking for. While you can download the files immediately by just clicking on their file names, you can also open the details page by clicking on the title of the file.</p>');
$handler->override_option('header_format', '2');
$handler->override_option('header_empty', 1);
$handler->override_option('footer_format', '2');
$handler->override_option('footer_empty', 0);
$handler->override_option('empty', '<p>There is no file available based on your access level and/or search criteria. Please try different keywords or filters if you searched; or contact us if you think there is a mistake.</p>');
$handler->override_option('empty_format', '2');
$handler->override_option('items_per_page', 0);
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
  'grouping' => 'field_clientfile_cat_value',
  'override' => 1,
  'sticky' => 1,
  'order' => 'asc',
  'columns' => array(
    'field_clientfile_cat_value' => 'field_clientfile_cat_value',
    'field_clientfile_desc_value' => 'field_clientfile_desc_value',
    'title' => 'title',
    'field_clientfile_file_fid' => 'field_clientfile_file_fid',
    'filesize' => 'filesize',
    'field_clientfile_cat2_value' => 'field_clientfile_cat2_value',
    'field_clientfile_date_value' => 'field_clientfile_date_value',
  ),
  'info' => array(
    'field_clientfile_cat_value' => array(
      'sortable' => 0,
      'separator' => '',
    ),
    'field_clientfile_desc_value' => array(
      'sortable' => 0,
      'separator' => '',
    ),
    'title' => array(
      'sortable' => 1,
      'separator' => '',
    ),
    'field_clientfile_file_fid' => array(
      'separator' => '',
    ),
    'filesize' => array(
      'sortable' => 1,
      'separator' => '',
    ),
    'field_clientfile_cat2_value' => array(
      'sortable' => 1,
      'separator' => '',
    ),
    'field_clientfile_date_value' => array(
      'sortable' => 1,
      'separator' => '',
    ),
  ),
  'default' => '-1',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'support/document-library');
$handler->override_option('menu', array(
  'type' => 'normal',
  'title' => 'Document Library',
  'description' => 'Document Library',
  'weight' => '2',
  'name' => 'secondary-links',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));

Drupal 6.20
Filefield Stats 6.x-1.x-dev (2011-Apr-18)

osman’s picture

Category: feature » bug
FileSize
201.26 KB

Seems like $node = $element['#node']; can only get its value, when the file is displayed on nodes.

theme_filefield_stats_formatter() function returns NULL for $node when it is used in the views, even though the formatter is available in the Views (See screenshot).

I am not sure how to make $node object available in this formatter. It is a great module and I thank for it.

Any ideas how to make it Views friendly?

Thanks,

/**
 * Theme function for filefield download links
 */
function theme_filefield_stats_formatter($element, $with_count = FALSE) {
  global $user;

  $file = $element['#item'];
  $node = $element['#node'];
  $field = content_fields($element['#field_name']);

  module_load_include('inc', 'filefield', 'filefield_formatter');

  // If we have access to the field and the file is listed forthis field, define some output
  if (filefield_view_access($field['field_name']) && filefield_file_listed($file, $field)) {
    $options = array(
      'attributes' => array(
        'type' => $file['filemime'] . '; length=' . $file['filesize'],
      ),
    );

    // Use the description as the link text if available.
    if (empty($file['data']['description'])) {
      $link_text = $file['filename'];
    }
    else {
      $link_text = $file['data']['description'];
      $options['attributes']['title'] = $file['filename'];
    }

    $count = '';
    if ($with_count) {
      $downloads = filefield_stats_get_stats($file['fid'], $node->vid);
      $count = ' ('. format_plural($downloads, '@count download', '@count downloads') .')';
    }

    $args = array($file['fid'], $node->vid, $user->uid);

    $url = file_create_url('filefield_stats/'. implode('/', $args) .'/'. filefield_stats_hash($args));
    $icon = theme('filefield_icon', $file);

    return '<div class="filefield-file clear-block">'. $icon . l($link_text, $url, $options) . $count .'</div>';
  }

  return '';
}
osman’s picture

Category: bug » support
Priority: Critical » Normal
Status: Active » Needs review

Solution:
The view should have been based on File type, not Node.

Once the view type is set to File; and relationships to Content: File; both node and file fields become available in Fields options.

For testing purposes, I added $element's output to theme_filefield_stats_formatter function.
Here are the results:

Node view:

Array
(
    [#theme] => filefield_stats_formatter_stats_default
    [#field_name] => field_file
    [#type_name] => 
    [#formatter] => stats_default
    [#node] => stdClass Object
        (
            [nid] => 
            [files_node_data_field_file_node_data_field_file_field_file_fid] => 2
            [files_node_data_field_file_node_data_field_file_field_file_list] => 1
            [files_node_data_field_file_node_data_field_file_field_file_data] => a:0:{}
            [node_title] => test 2
            [type] => 
            [vid] => 
            [build_mode] => 0
        )

    [#delta] => 0
    [#item] => Array
        (
            [fid] => 2
            [uid] => 1
            [filename] => nodeembed-6x-14tar.gz
            [filepath] => _/private/nodeembed-6x-14tar.gz
            [filemime] => application/octet-stream
            [filesize] => 15929
            [status] => 1
            [timestamp] => 1306042389
            [origname] => node_embed-6.x-1.4.tar_.gz
            [list] => 1
            [data] => Array
                (
                )

            [#delta] => 0
            [nid] => 
        )

)

File view:

Array
(
    [#theme] => filefield_stats_formatter_stats_default
    [#field_name] => field_file
    [#type_name] => file
    [#formatter] => stats_default
    [#node] => stdClass Object
        (
            [fid] => 2
            [node_node_data_field_file_title] => test 2
            [node_node_data_field_file_nid] => 3
            [node_node_data_field_file_node_data_field_file_field_file_fid] => 2
            [node_node_data_field_file_node_data_field_file_field_file_list] => 1
            [node_node_data_field_file_node_data_field_file_field_file_data] => a:0:{}
            [node_node_data_field_file_type] => file
            [node_node_data_field_file_vid] => 3
            [type] => file
            [nid] => 3
            [vid] => 3
            [build_mode] => 0
        )

    [#delta] => 0
    [#item] => Array
        (
            [fid] => 2
            [uid] => 1
            [filename] => nodeembed-6x-14tar.gz
            [filepath] => _/private/nodeembed-6x-14tar.gz
            [filemime] => application/octet-stream
            [filesize] => 15929
            [status] => 1
            [timestamp] => 1306042389
            [origname] => node_embed-6.x-1.4.tar_.gz
            [list] => 1
            [data] => Array
                (
                )

            [#delta] => 0
            [nid] => 3
        )

)

Both views are listing the same file field from the same content-type. Notice the missing data from the $node object on the first one?

Cheers,
Osman

kbk’s picture

Thanks for the documentation, Osman. Here's a bit more that incorporates NID arguments and multiple relationships into the view.

I have two content types with a node reference between them: [Data Set]->[Data File]. I'm also using the Node Referrer module to reverse the node reference direction. This is D6. Here are the fields of interest:

[Data Set]
Associated Data File : [field_dataset_datafile_ref] - Node Reference Type

[Data File]
Public Data File: [field_datafile_public] - FileField Type
Associated Data Set: [field_dataset_referrer] - Node Referrer Type

I want to display referenced [Data Files] on the [Data Set] node via a View that takes the NID of the [Data Set] as an argument and uses relationships to pull in a list of files from the [Data Files] nodes. I will embed this View into a Panels Node Template. Originally, I used a Node type view, but the download link fails because of previously mentioned problems.

Here's my setup:

View Type: File
Relationship 1: "Content: Public Data File Field" > Label: Public Data File
Relationship 2: "Node: Referrer" > Relationship: Public Data File > Label: Referencing Public Data Nodes > Using field: [field_dataset_datafile_ref]

Argument: "Node: Nid" > Relationship: Referencing Public Data Nodes

Fields
Content: Public Data File (field_datafile_public) > Relationship: Public Data File

Here's an example of a Data Set node displaying the file from a Data File node: http://umbs.lsa.umich.edu/research/node/8021

kbk’s picture

Turns out the view I constructed in #7 doesn't solve the Page Not Found error. Any suggestions welcome. This is a bit frustrating.

Edit: More testing reveals that this isn't a Views problem for me. I get a Page Not Found error when hitting the "Generic Files + Stats URL link on the default node page for my content type.

kbk’s picture

Status: Needs review » Active

there's no patch for review.