Skip to content

Commit

Permalink
v1.2
Browse files Browse the repository at this point in the history
Added the ability to use group headers throughout the list. Your query must be ordered properly for this to work but does not need to be grouped by anything.
  • Loading branch information
bascherz authored May 9, 2020
1 parent af46346 commit 70acd1c
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 17 deletions.
8 changes: 4 additions & 4 deletions manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<description>Joomla! Table Dump Module</description>
<element>mod_tabledump</element>
<type>module</type>
<version>1.1</version>
<version>1.2</version>
<client>site</client>
<infourl title="Table Dump Module">https://github.com/bascherz/Table-Dump-Module/releases/tag/1.1</infourl>
<infourl title="Table Dump Module">https://github.com/bascherz/Table-Dump-Module/releases/tag/1.2</infourl>
<downloads>
<downloadurl type="full" format="zip">https://github.com/bascherz/Table-Dump-Module/releases/download/1.1/mod_tabledump_1.1.zip</downloadurl>
<downloadurl type="full" format="zip">https://github.com/bascherz/Table-Dump-Module/releases/download/1.2/mod_tabledump_1.2.zip</downloadurl>
</downloads>
<targetplatform name="joomla" version="3.[6789]" />
</update>
</updates>
</updates>
52 changes: 44 additions & 8 deletions src/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ public static function getTableDump($params)
$fieldnames = explode(",",preg_replace("/\s+/",",",$params->get('fieldnames')));
$tablequery = $params->get('tablequery');
$errormessage = $params->get('errormessage');
$tablehtml = $params->get('tablehead');
$tableprefix = $params->get('tableprefix','<table>');
$tablehead = $params->get('tablehead');
$tablerow = $params->get('tablerow');
$tablefoot = $params->get('tablefoot');
$tablefoot = $params->get('tablefoot','</tbody></table>');
$hardspaces = $params->get('hard_spaces');
$groupby = trim($params->get('groupby'));
$grouphead = $params->get('grouphead');
$hard_spaces = $params->get('hard_spaces');

// Prepare the query
$db->setQuery($tablequery);
Expand All @@ -45,28 +50,59 @@ public static function getTableDump($params)
{
$tablehtml = $errormessage;
}
// Replace the special tags.
$tablehtml = html_entity_decode(str_replace("{tablerows}",count($records),$tablehtml),ENT_QUOTES);
$tablefoot = html_entity_decode(str_replace("{tablerows}",count($records),$tablefoot),ENT_QUOTES);

// Replace tags in rows
$lastgroup = "";
$thisgrouphead = "";
if ($records)
{
// Iterate over every row in the database recordset returned.
foreach ($records as $record)
{
// See if we need a group header and if it's time to output one.
if ($groupby)
{
$thisgroup = $record->$groupby;
$thisgrouphead = "";
if ($thisgroup != $lastgroup)
{
if ($hard_spaces)
$thisgrouphard = html_entity_decode(str_replace(array(" ","-","\n"),array("&nbsp;","&#8209;","<br/>"),$thisgroup),ENT_QUOTES);
else
$thisgrouphard = $thisgroup;

$thisgrouphead = html_entity_decode(str_replace("{".$groupby."}",$thisgrouphard,$grouphead),ENT_QUOTES);
}
$lastgroup = $thisgroup;
}

// Get the HTML for the next row ready.
$thisrow = $tablerow;

// Go through the list of field names and replace each {fieldname} in the user-provided HTML for this row.
foreach ($fieldnames as $fieldname)
{
$thisrow = html_entity_decode(str_replace("{".$fieldname."}",$record->$fieldname,$thisrow),ENT_QUOTES);
$fielddata = $record->$fieldname;
if ($hard_spaces) $fielddata = html_entity_decode(str_replace(array(" ","-","\n"),array("&nbsp;","&#8209;","<br/>"),$fielddata),ENT_QUOTES);
$thisrow = html_entity_decode(str_replace("{".$fieldname."}",$fielddata,$thisrow),ENT_QUOTES);
}
// Add the processed row to the growing structure.
$tablehtml .= $thisrow;
$tablehtml .= $thisgrouphead.$thisrow;
}
}
// Replace the special tags.
if ($groupby)
{
$tablehead = '<table border="2">';
}
else
{
$tablehead = html_entity_decode(str_replace("{tablerows}",count($records),$tablehead),ENT_QUOTES);
}
$tablefoot = html_entity_decode(str_replace("{tablerows}",count($records),$tablefoot),ENT_QUOTES);

// Return the table with all fieldname substitutions made and footer appended.
return $tablehtml.($tablefoot ? $tablefoot : "</tbody></table>");
return $tableprefix.$tablehead.$tablehtml.($tablefoot ? $tablefoot : "</tbody></table>");
}
}
?>
50 changes: 45 additions & 5 deletions src/mod_tabledump.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<extension type="module" version="3.1.0" client="site" method="upgrade">
<name>Table Dump</name>
<author>Bruce Scherzinger</author>
<version>1.1</version>
<version>1.2</version>
<description>Extracts rows of data from the database and replaces field data in an HTML table structure. A special tag {tablerows} can be placed in either the header or footer and is replaced by the total rows returned by the query.</description>
<files>
<filename>mod_tabledump.xml</filename>
Expand All @@ -26,6 +26,17 @@
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field
name="hard_spaces"
type="radio"
label="Hard Spaces:"
description="Optionally replace all spaces, hyphens, and newlines with non-breaking HTML entities. This applies only to data in rows."
class="btn-group btn-group-yesno"
default="0"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
</fieldset>
<fieldset name="query" label="Query">
<field
Expand Down Expand Up @@ -57,17 +68,46 @@
filter="raw"
label="Error Message:" />
</fieldset>
<fieldset name="headfoot" label="Head/Foot">
<fieldset name="headfoot" label="Head/Foot/Group">
<field
name="tableprefix"
description="HTML code for your table prefix. Do not use field names in this section as they will not be replaced. Defaults to plain table."
type="editor"
editor="None"
height="50"
width="1000"
default=""
filter="raw"
label="Table Prefix HTML:" />
<field
name="tablehead"
description="HTML code optionally containing placeholders for your table heading. Do not use field names in this section as they will not be replaced."
description="HTML code for the actual first row of your table. Do not use field names in this section as they will not be replaced."
type="editor"
editor="None"
height="500"
height="200"
width="1000"
default=""
filter="raw"
label="Table Heading HTML:" />
<field
name="groupby"
description="Optional column name for grouping. If left empty, no group sub-headers will appear. Must be a single column name."
type="text"
editor="None"
width="100"
default=""
filter="raw"
label="Group By:" />
<field
name="grouphead"
description="HTML code optionally containing placeholders for your group heading. You can use field names in this section."
type="editor"
editor="None"
height="200"
width="1000"
default=""
filter="raw"
label="Group Heading HTML:" />
<field
name="tablefoot"
description="Optional HTML code containing placeholders for your table heading. Do not use field names in this section as they will not be replaced. If left empty, a basic table terminator will be added for you."
Expand All @@ -85,7 +125,7 @@
description="HTML code containing field names for your table data. This section will be used to format each row of data fetched from your table."
type="editor"
editor="None"
height="600"
height="300"
width="1000"
default=""
filter="raw"
Expand Down

0 comments on commit 70acd1c

Please sign in to comment.