Skip to content

Commit

Permalink
Added optional WHERE clause to form limit plugin, so you can do stuff…
Browse files Browse the repository at this point in the history
… like (say) apply the limit to just "today", or records with published=1, or whatever.
  • Loading branch information
cheesegrits committed Feb 24, 2017
1 parent b16980a commit 4d8a88e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
8 changes: 7 additions & 1 deletion plugins/fabrik_form/limit/forms/fields.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@
onlytablefields="0"
repeat="true"
valueformat="tableelement"/>


<field name="limit_where"
type="fabrikeditor"
mode="mysql"
description="PLG_FORM_LIMIT_WHERE_DESC"
label="PLG_FORM_LIMIT_WHERE_LABEL" />

<field name="OR" type="spacer"/>

<field name="limit_connection"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ PLG_FORM_LIMIT_SHOW_LIMIT_MESSAGE_LABEL="Show limit message"
PLG_FORM_LIMIT_USER="User"
PLG_FORM_LIMIT_CONDITION_LABEL="Condition"
PLG_FORM_LIMIT_CONDITION_DESC="Optional PHP code. If code returns false, limit is not applied.<br />The form data is contained within the variable $data. The form's original data is available as an array called $origData"

PLG_FORM_LIMIT_WHERE_DESC="Optional SQL where clause to be appended to the query that counts records, using AND (do not prepend your statement with WHERE, or AND, etc). For instance, to limit it to only rows with a 'published' field set to one, use <b>published = 1</b>. Or for just rows added today, using a date element 'your_date', <b>DAYOFYEAR(your_date) = DAYOFYEAR(NOW()) AND YEAR(your_date) = YEAR(NOW))</b>"
PLG_FORM_LIMIT_WHERE_LABEL="Where Clause"
; front end
PLG_FORM_LIMIT_ENTRIES_LEFT_MESSAGE="You have %s of %s entries remaining"
PLG_FORM_LIMIT_LIMIT_REACHED="You have reached your limit of %s records"
Expand Down
7 changes: 7 additions & 0 deletions plugins/fabrik_form/limit/limit.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ protected function count()
$params = $this->getParams();
$field = $params->get('limit_userfield');
$fk = $params->get('limit_fk');
$where = trim($params->get('limit_where', ''));

$fkVal = '';

/*
Expand Down Expand Up @@ -143,6 +145,11 @@ protected function count()
$query->where($db->qn($fk) . ' = ' . $db->q($fkVal), 'AND');
}

if (!empty($where))
{
$query->where($where);
}

$db->setQuery($query);

return (int) $db->loadResult();
Expand Down

0 comments on commit 4d8a88e

Please sign in to comment.