diff --git a/README.md b/README.md
old mode 100644
new mode 100755
diff --git a/README_pt.md b/README_pt.md
old mode 100644
new mode 100755
diff --git a/forms/fields.xml b/forms/fields.xml
index b0e8630..82a6071 100755
--- a/forms/fields.xml
+++ b/forms/fields.xml
@@ -74,6 +74,14 @@
size="10"
default="2"
/>
+
+
diff --git a/images/01.png b/images/01.png
old mode 100644
new mode 100755
diff --git a/images/02.png b/images/02.png
old mode 100644
new mode 100755
diff --git a/images/03.png b/images/03.png
old mode 100644
new mode 100755
diff --git a/images/04.png b/images/04.png
old mode 100644
new mode 100755
diff --git a/images/05.png b/images/05.png
old mode 100644
new mode 100755
diff --git a/language/en-GB/en-GB.plg_fabrik_form_workflow.ini b/language/en-GB/en-GB.plg_fabrik_form_workflow.ini
index a44a83b..0dadcf8 100755
--- a/language/en-GB/en-GB.plg_fabrik_form_workflow.ini
+++ b/language/en-GB/en-GB.plg_fabrik_form_workflow.ini
@@ -130,4 +130,6 @@ PLG_FORM_WORKFLOW_ERROR_APPROVE_EMPTY="Select Approve field and try again"
PLG_FORM_WORKFLOW_VOTES_TO_APPROVE_LABEL="Votes to Approve"
PLG_FORM_WORKFLOW_VOTES_TO_DISAPPROVE_LABEL="Votes to Disapprove"
-PLG_FABRIK_FORM_WORKFLOW="Something went wrong"
\ No newline at end of file
+PLG_FABRIK_FORM_WORKFLOW="Something went wrong"
+PLG_FORM_WORKFLOW_CONTRIBUTION_TO_VOTE_LABEL="Number of contribution"
+PLG_FORM_WORKFLOW_CONTRIBUTION_TO_VOTE_DESC="Number of contribution that user need to have to be capable to vote. Definition of contribution is the number of registers the user added in this list"
\ No newline at end of file
diff --git a/language/pt-BR/pt-BR.plg_fabrik_form_workflow.ini b/language/pt-BR/pt-BR.plg_fabrik_form_workflow.ini
index 4b3b983..ab14baf 100755
--- a/language/pt-BR/pt-BR.plg_fabrik_form_workflow.ini
+++ b/language/pt-BR/pt-BR.plg_fabrik_form_workflow.ini
@@ -132,4 +132,6 @@ PLG_FORM_WORKFLOW_ERROR_APPROVE_EMPTY="Selecione o campo Aprovar e tente novamen
PLG_FORM_WORKFLOW_VOTES_TO_APPROVE_LABEL="Votos para aprovar"
PLG_FORM_WORKFLOW_VOTES_TO_DISAPPROVE_LABEL="Votos para reprovar"
-PLG_FABRIK_FORM_WORKFLOW="Algo deu errado"
\ No newline at end of file
+PLG_FABRIK_FORM_WORKFLOW="Algo deu errado"
+PLG_FORM_WORKFLOW_CONTRIBUTION_TO_VOTE_LABEL="Número de contribuições"
+PLG_FORM_WORKFLOW_CONTRIBUTION_TO_VOTE_DESC="Número de contribuições que o usuário precisa ter para conseguir votar em uma requisição. Contribuições aqui definido como número de registros que o usuário adiciona na lista"
\ No newline at end of file
diff --git a/layouts/fabrik-form-workflow-modal-body.php b/layouts/fabrik-form-workflow-modal-body.php
old mode 100644
new mode 100755
diff --git a/workflow.php b/workflow.php
index 8d768ce..1ba5e33 100755
--- a/workflow.php
+++ b/workflow.php
@@ -872,7 +872,8 @@ public function createLog($formData, $hasPermission)
if (isset($owner_id) && !empty($owner_id)) {
$formData["owner_id"] = $owner_id;
} else {
- die(Text::_("PLG_FORM_WORKFLOW_OWNER_NOT_SET"));
+ return;
+ // die(Text::_("PLG_FORM_WORKFLOW_OWNER_NOT_SET"));
}
$logData = $this->getFormDataToLog($formData, $hasPermission);
@@ -935,7 +936,8 @@ public function saveLog($formData)
}
} else {
if (!empty($v) || in_array($this->requestType, ['4', '5'])) {
- if (end(explode('_', $k)) == 'orig') {
+ $explode = explode('_', $k);
+ if (end($explode) == 'orig') {
$k = array_shift(explode('_orig', $k));
}
$mainListFormData->$k = $v;
@@ -1767,11 +1769,47 @@ protected function canViewRequests($allow_review_request='')
$canView = 'all';
} else if (in_array($allow_review_request, $groups)) {
$canView = 'all';
+ } else if ($this->isPermittedToVote()) {
+ $canView = 'all';
}
return $canView;
}
+ /**
+ * This method verify if is permitted the user vote following the rules
+ * 1. Approve by votes must be high
+ * 2. User must contribute at least the number saved
+ *
+ * @param int $listId List id to check if vote is permitted
+ * @return bool
+ * @since 4.2.3
+ */
+ private function isPermittedToVote(int $listId = 0): bool
+ {
+ $listModel = Factory::getApplication()->bootComponent('com_fabrik')->getMVCFactory()->createModel('List', 'FabrikFEModel');
+ $db = Factory::getContainer()->get('DatabaseDriver');
+ $app = Factory::getApplication();
+
+ $input = $app->getInput();
+ $listId = $listId ?: $input->get('listid');
+ $listModel->setId($listId);
+
+ $formModel = $listModel->getFormModel();
+ $params = $formModel->getParams();
+ $isApproveByVote = $params->get('workflow_approval_by_vote');
+ $minContribution = (int) $params->get('workflow_contribution_to_vote', '5');
+
+ $query = $db->getQuery(true);
+ $query->select('count(*)')
+ ->from($db->qn($formModel->getTableName()))
+ ->where($db->qn('created_by') . ' = ' . $db->q($this->user->id));
+ $db->setQuery($query);
+ $contributionCount = $db->loadResult();
+
+ return $isApproveByVote && $contributionCount >= $minContribution;
+ }
+
/**
* Checks if the user can approve requests
* For next release use this method to check if the user can approve requests in js file
@@ -1787,7 +1825,10 @@ public function canApproveRequests($dataRequest)
$dataRequest = $dataRequest[0];
if(empty($dataRequest)) {
- return $this->user->authorise('core.admin') || in_array($this->getParams()->get('allow_review_request'), $groups);
+ return
+ $this->user->authorise('core.admin') ||
+ in_array($this->getParams()->get('allow_review_request'), $groups) ||
+ $this->isPermittedToVote();
}
$reviewersVotes = explode(',', $request->req_reviewers_votes);
@@ -1799,7 +1840,7 @@ public function canApproveRequests($dataRequest)
}
// Admins and list admins can approve requests
- $canApproveRequests = $this->user->authorise('core.admin') || in_array($this->getParams()->get('allow_review_request'), $groups);
+ $canApproveRequests = $this->user->authorise('core.admin') || in_array($this->getParams()->get('allow_review_request'), $groups) || $this->isPermittedToVote($dataRequest->req_list_id);
// If user is the owner of the request and the option approve for own records is set then user can approve if request is a edit or delete request of itens or fields
if($dataRequest->req_owner_id == $this->user->id && (bool) $this->params->get('approve_for_own_records')) {
@@ -1823,9 +1864,13 @@ public function canApproveRequests($dataRequest)
protected function checkAddRequestButton()
{
$listModel = $this->getModel()->getListModel();
+ $addUrl = $listModel->getAddRecordLink();
+ $varsUrl = parse_url($addUrl);
+ $addRequestLink = $this->getFriendlyUrl($listModel->getId(), 'form', $listModel->getFormModel()->getId());
+ $addRequestLink = $addRequestLink . ($varsUrl['query'] ? '?' . $varsUrl['query'] . '&wfl_action=request' : '?wfl_action=request');
$_REQUEST['workflow']['showAddRequest'] = !$listModel->canAdd() && $this->canRequest();
- $_REQUEST['workflow']['addRequestLink'] = $this->getFriendlyUrl($listModel->getId(), 'form', $listModel->getFormModel()->getId()) . '?wfl_action=request';
+ $_REQUEST['workflow']['addRequestLink'] = $addRequestLink;
$_REQUEST['workflow']['listLinkUrl'] = $this->getFriendlyUrl($listModel->getId(), 'list');
$_REQUEST['workflow']['requestLabel'] = Text::_('PLG_FORM_WORKFLOW_BUTTON_NEW_REQUEST');
$_REQUEST['workflow']['eventsButton'] = Text::_('PLG_FORM_WORKFLOW_BUTTON_EVENTS');
diff --git a/workflow.xml b/workflow.xml
index be35e9f..de40db1 100755
--- a/workflow.xml
+++ b/workflow.xml
@@ -7,7 +7,7 @@
GNU/GPL http://www.gnu.org/copyleft/gpl.html
contact@jlowcode.org
www.jlowcode.org
- 4.2.2
+ 4.2.3
PLG_FORM_WORKFLOW_DESCRIPTION