Skip to content
Snippets Groups Projects
Commit aa253ee4 authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FEAT #13049 TIME 1:00 set action required_fields in action create/update

parent 0a4ca386
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@
namespace Action\controllers;
use Basket\models\GroupBasketRedirectModel;
use CustomField\models\CustomFieldModel;
use Group\controllers\GroupController;
use Group\controllers\PrivilegeController;
use Group\models\GroupModel;
......@@ -104,6 +105,28 @@ class ActionController
}
unset($body['actionPageId']);
if (!empty($body['required_fields'])) {
if (!Validator::arrayType()->validate($body['required_fields'])) {
return $response->withStatus(400)->withJson(['errors' => 'Data required_fields is not an array']);
}
$customFields = CustomFieldModel::get(['select' => ['id']]);
$customFields = array_column($customFields, 'id');
$requiredFields = [];
foreach ($body['required_fields'] as $key => $requiredField) {
if (strpos($requiredField, 'indexingCustomField_') !== false) {
$idCustom = explode("_", $requiredField);
$idCustom = $idCustom[1];
if (!in_array($idCustom, $customFields)) {
return $response->withStatus(400)->withJson(['errors' => 'Data custom field does not exist']);
}
$requiredFields[] = $requiredField;
}
}
$body['required_fields'] = json_encode($requiredFields);
}
$id = ActionModel::create($body);
if (!empty($body['actionCategories'])) {
ActionModel::createCategories(['id' => $id, 'categories' => $body['actionCategories']]);
......@@ -147,6 +170,26 @@ class ActionController
return $response->withStatus(400)->withJson(['errors' => 'Data actionPageId does not exist']);
}
$requiredFields = [];
if (!empty($body['required_fields'])) {
if (!Validator::arrayType()->validate($body['required_fields'])) {
return $response->withStatus(400)->withJson(['errors' => 'Data required_fields is not an array']);
}
$customFields = CustomFieldModel::get(['select' => ['id']]);
$customFields = array_column($customFields, 'id');
foreach ($body['required_fields'] as $key => $requiredField) {
if (strpos($requiredField, 'indexingCustomField_') !== false) {
$idCustom = explode("_", $requiredField);
$idCustom = $idCustom[1];
if (!in_array($idCustom, $customFields)) {
return $response->withStatus(400)->withJson(['errors' => 'Data custom field does not exist']);
}
$requiredFields[] = $requiredField;
}
}
}
$body['required_fields'] = json_encode($requiredFields);
ActionModel::update($body);
ActionModel::deleteCategories(['id' => $aArgs['id']]);
if (!empty($body['actionCategories'])) {
......
......@@ -71,23 +71,24 @@ abstract class ActionModelAbstract
return $nextSequenceId;
}
public static function update(array $aArgs)
public static function update(array $args)
{
ValidatorModel::notEmpty($aArgs, ['id']);
ValidatorModel::intVal($aArgs, ['id']);
ValidatorModel::notEmpty($args, ['id']);
ValidatorModel::intVal($args, ['id']);
DatabaseModel::update([
'table' => 'actions',
'set' => [
'keyword' => $aArgs['keyword'],
'label_action' => $aArgs['label_action'],
'id_status' => $aArgs['id_status'],
'action_page' => $aArgs['action_page'],
'component' => $aArgs['component'],
'history' => $aArgs['history'],
'table' => 'actions',
'set' => [
'keyword' => $args['keyword'],
'label_action' => $args['label_action'],
'id_status' => $args['id_status'],
'action_page' => $args['action_page'],
'component' => $args['component'],
'history' => $args['history'],
'required_fields' => $args['required_fields'],
],
'where' => ['id = ?'],
'data' => [$aArgs['id']]
'where' => ['id = ?'],
'data' => [$args['id']]
]);
return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment