lcollong
FabriKant d'applications web
Hi,
I'm using the sequence element (on submit) for a custom CRM (offers, invoices, contracts, etc...). It's doing perfect as far as the new row follows the manual mechanism (add a new row, fill the elements and submit the form to create it).
But in some situations, I need to create several of them from an external script (actually onAfterProcess php plugin from a specific form). I create the rows and the joined tables ones "by hand", directly in the DB. Not using the Fabrik's class/method.
Is there any "easy way" to trigger a new sequence number from the script ? The "getSequence" method from the plugin class expects a complex array. Is there a way I can build this array and call the getSequence from a script in another form (not knowing about the sequence element params) ?
Meanwhile, I did an horrible hack so that the first time the user see the newly created row (form view) the sequence element says "Assigned after form is submitted" and on the next submit the actual sequence number is calculated (onStoreRow around line 94) :
Definitively not something for which I could make a github's PR ;-)
Other point :
Is there any underlying mechanism to prevent two "getSequence" updating/inserting the table on the same time with the same number (such as the new lock feature) ?
Should I check by myself that the sequence number is effectively unique (or add a SQL constraint) ?
Thanks,
I'm using the sequence element (on submit) for a custom CRM (offers, invoices, contracts, etc...). It's doing perfect as far as the new row follows the manual mechanism (add a new row, fill the elements and submit the form to create it).
But in some situations, I need to create several of them from an external script (actually onAfterProcess php plugin from a specific form). I create the rows and the joined tables ones "by hand", directly in the DB. Not using the Fabrik's class/method.
Is there any "easy way" to trigger a new sequence number from the script ? The "getSequence" method from the plugin class expects a complex array. Is there a way I can build this array and call the getSequence from a script in another form (not knowing about the sequence element params) ?
Meanwhile, I did an horrible hack so that the first time the user see the newly created row (form view) the sequence element says "Assigned after form is submitted" and on the next submit the actual sequence number is calculated (onStoreRow around line 94) :
PHP:
$element = $this->getElement();
$formModel = $this->getFormModel();
$params = $this->getParams();
$method = $params->get('sequence_method', 'load');
// if ($formModel->isNewRecord() && $method === 'submit')
if (($formModel->isNewRecord() || $formModel->getElementData($element->name) == JText::_('PLG_ELEMENT_SEQUENCE_ASSIGNED_AFTER_SUBMIT')) && $method === 'submit')
{
$formData = json_decode(json_encode($formModel->formDataWithTableName));
$this->swapValuesForLabels($formData);
$this->setStoreDatabaseFormat($formData, $repeatCounter);
$data[$element->name] = $data[$element->name . '_raw'] = $this->getSequence($formData);
}
Definitively not something for which I could make a github's PR ;-)
Other point :
Is there any underlying mechanism to prevent two "getSequence" updating/inserting the table on the same time with the same number (such as the new lock feature) ?
Should I check by myself that the sequence number is effectively unique (or add a SQL constraint) ?
Thanks,