Sorry for the stupid request, but I would need a working sample that shows the PHP code needed to call the API, supposing I would like to extract COLUMNA and COLUMNB from table TABLEA.
thanks a lot and compliments for your great module, that adds a lot of possibilities to Drupal

Matteo Ferrari

CommentFileSizeAuthor
#6 filesview.info161 bytesmandclu
#5 filesview.module.txt2.79 KBmandclu

Comments

mandclu’s picture

That is absolutely not a stupid request. My initial intention was to have a sample module that implements tha API as part of the inital release, but finding the time to do so was proving difficult, so I decided to release it without, with the intention to come back and add the example.

As it is, I'll probably try to base the example on something in core (like files), so that it's easier to try it out and see how it works. Stay tuned, I'll try to get something posted as soon as possible.

mandclu’s picture

Here is an example that will list files in the site, giving you the option to filter based on a certain MIME type, file size, and so on. It's a pretty simple example at this point, but hopefully it will be a reasonable starting point:

function filesview_get_model() {
	$filesview_fields = array(

	    'fid'		=> array('type' => 'int',
							'pkey' => 'y',
							'hidden' => 'y'),

	    'nid'		=> array('type' => 'int',
							'hidden' => 'y'),

	    'filename'	=> array('type' => 'string',
							'label' => 'File Name',
							'required' => 'y'),

	    'filepath'	=> array('type' => 'string',
							'label' => 'File Path',
							'hidden' => 'y',
							'required' => 'y'),

	    'filemime'	=> array('type' => 'string',
							'label' => 'Mime Type',
							'filter' => 'y',
							'sortable' => 'y',
							'required' => 'y'),

	    'filesize'	=> array('type' => 'int',
							'label' => 'File Size (bytes)',
							'filter' => 'y',
							'sortable' => 'y',
							'required' => 'y'),

	);
	
	$filesview_data_model = array(
	    'tablename'				=> 'files',
	    'title'					=> 'Site Files',
	    'menu'					=> 'filesview',
	    'rows_per_page'			=> 0,
	    'default_orderby'		=> 'filemime,filesize',
	    'default_orderby_seq'	=> 'desc',
		'label_color'			=> 'CC0011',
		'fields'				=> $filesview_fields,
	);

	return $filesview_data_model;
}

/**
 * Implementation of hook_perm()
 */
function filesview_perm() {
  return array('access filesview');
}

/**
 * Implementation of hook_menu()
 */
function filesview_menu($may_cache) {
	static $data_model;
	
	if (empty($data_model)) {
	  $data_model = filesview_get_model();
	}
	
	$items = array();

	 $items[] = array(
	    'path' => 'filesview',
	    'title' => t('Site Files'),
	    'callback' => 'filesview_view',
	    'access' => user_access('access filesview'),
	    'description' => t('View list of site files'),
	    'type' => MENU_CALLBACK,
	  );
	
	return $items;
}

function filesview_view() {
	if (!user_access('access filesview')) {
	  return;
	}
	
	$data_model = filesview_get_model();
	
	$output = dataview_build_view($data_model);
	
	if(!$output) $output = 'Error, no data found.';
	
	return $output;
}

As time goes on I'd like to allow for a callback function on the field, so that the module implementing the API can perform addtitional processing before diplaying it. In this example, it would allow for the display of the nid field, with a callback that might retrieve and display the node's title as a link to view the node.

Note that in the field descriptions I've included fields that aren't intended for diplay (as designated with the 'hidden' parameter). In my modules that implemented the dataview API, I did this to fully support an external data set, so I could import and store the complete data set, but only retrieve and display the appropriate fields.

I'll try to add to this example over time, and will probably include it in a future version of the distribution.

mandclu’s picture

OK, I've just committed a new dev version that supports a display callback, and will include an examples folder containing the filesview module. It's still a little rough around the edges, but hopefully will give you enough information to get started.

wvd_vegt’s picture

Hi,

If i may add another stupid question, where do i put the script you posted (filename etc).

I installed dataview in the hope i could use it to display user dependent data (grades).

mandclu’s picture

StatusFileSize
new2.79 KB

It should be put into a module. I tried to include it with the updated distrib, but it didn't seem to pick it up. I'll try to correct that, in the meantime here's the module (it's updated a bit from what I posted before) - I had to add .txt to the name, please remove it before use.

As for using it to display user-dependant data, that should work fine as long as the data itself all resides in one table. You can, however, use a callback function to augment the display of the data. For example, if one field is the uid of the user, you could use a callback to look up the user and diaplay the user name as a link to their profile.

mandclu’s picture

StatusFileSize
new161 bytes

...and a .info file for use with the module.