I have been writing a number of plugins to display data in a way that ee won’t do easily and found it surprisingly easy. Here is the template for a plugin to gather and list data.
$plugin_info = array(
'pi_name' => 'MyPlugin', // rename as required
'pi_version' => '1.0',
'pi_author' => 'Phoebe bright',
'pi_author_url' => '',
'pi_description' => 'Display some data.',
'pi_usage' => MyPlugin::usage()
);
class MyPlugin
{
var $return_data = '';
function entries() {
global $DB,$TMPL;
// if you need to add parameters to your sql, get the values here
$entry_id = $TMPL->fetch_param('entry_id');
$return_data='';
// AMEND THIS BIT TO GATHER THE DATA YOU WANT
$sql = "SELECT field_id_1 as myfield1,
field_id_2 as myfield2
FROM exp_weblog_data
WHERE entry_id=".$entry_id."
ORDER BY myfield1 ASC";
// SHOULDN'T NEED TO CHANGE THE REST
$query = $DB->query($sql);
unset($sql);
if ($query->num_rows == 0){
return false;
}
$rows=$query->result;
// get your template here
$tagdata = $TMPL->tagdata;
$rows=$query->result;
foreach ($rows as $row) { // for each record
$t=$tagdata;
foreach ($row as $key=>$value) { // instantiate the field into the template
$t =str_replace(
'{'.$key.'}',
$value,
$t
);
} //foreach
$return_data.=$t;
} //foreach
return $return_data;
} //MyPlugin
function usage()
{
ob_start();
?>
==========
TAG PARAMETERS
==========
entry_id=
entry_id you want to display categories for
==========
TAG VARIABLES
==========
{myfield1}
{myfield1}
Usage:
{exp:myplugin:list entry_id="{entry_id}"}
{myfield1}
{myfield2}
{/exp:myplugin:list}
<?php
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
} //usage
} //myplugin
All the fields in the SELECT part of the statement are available as tag variables.
I did a data model for EE some time ago. It is a bit out of date but may be useful in getting to grips with relationships. It is at Data Model
Category:Plugins Category:Templates Category:Development
