Skip to content

Commit

Permalink
Small change to Limit plugin, to allow not specifying a user element,…
Browse files Browse the repository at this point in the history
… and just treating the limit as an overall limit on submissions to the list.
  • Loading branch information
cheesegrits committed May 6, 2016
1 parent fa262da commit 115125f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Expand Up @@ -24,7 +24,7 @@ PLG_FORM_LIMIT_USER_ELEMENT_DESC="The element that contains user or user group i
PLG_FORM_LIMIT_MAX_ELEMENT_LABEL="Max element"
PLG_FORM_LIMIT_MAX_ELEMENT_DESC="The element that states how many entries the user can enter"
PLG_FORM_LIMIT_USER_LABEL="User element"
PLG_FORM_LIMIT_USER_DESC="The forms user element that stores the user id"
PLG_FORM_LIMIT_USER_DESC="The forms user element that stores the user id. Specify this if you want to limit per user. Leave blank if you just want a single overall limit on submissions to this list."
PLG_FORM_LIMIT_REACHED_MSG_LABEL="Limit reached message"
PLG_FORM_LIMIT_REACHED_MSG_DESC="The message to show when the user can no longer add records. Use '{limit}' to show the user's maximum number of allowed entries"
PLG_FORM_LIMIT_SHOW_LIMIT_MESSAGE_DESC="This message tells the user how many entries he can still submit"
Expand Down
22 changes: 15 additions & 7 deletions plugins/fabrik_form/limit/limit.php
Expand Up @@ -58,6 +58,13 @@ private function _process()
}

$limit = $this->limit();

// Allow for unlimited
if ($limit == -1)
{
return true;
}

$c = $this->count();

if ($c === false)
Expand All @@ -67,12 +74,6 @@ private function _process()
return false;
}

// Allow for unlimited
if ($limit == -1)
{
return true;
}

if ($c >= $limit)
{
$msg = $params->get('limit_reached_message', JText::sprintf('PLG_FORM_LIMIT_LIMIT_REACHED', $limit));
Expand Down Expand Up @@ -105,10 +106,12 @@ protected function count()
$fk = $params->get('limit_fk');
$fkVal = '';

/*
if (empty($field))
{
return false;
}
*/

if (!empty($fk))
{
Expand All @@ -127,8 +130,13 @@ protected function count()
$list = $listModel->getTable();
$db = $listModel->getDb();
$query = $db->getQuery(true);
$query->clear()->select(' COUNT(' . $field . ')')->from($list->db_table_name)->where($field . ' = ' .
$query->clear()->select(' COUNT(*)')->from($list->db_table_name);

if (!empty($field))
{
$query->where($field . ' = ' .
(int) $this->user->get('id'));
}

if (!empty($fkVal))
{
Expand Down

0 comments on commit 115125f

Please sign in to comment.