HOR-455
This commit is contained in:
@@ -1437,70 +1437,43 @@ class pmDynaform
|
||||
*/
|
||||
public function validatePost($post = array())
|
||||
{
|
||||
$aux = $post;
|
||||
$json = G::json_decode($this->record["DYN_CONTENT"]);
|
||||
$modeForm = $json->items[0]->mode;
|
||||
foreach ($aux as $key => $value) {
|
||||
if (substr($key, -6, 6) === "_label") {
|
||||
continue;
|
||||
}
|
||||
$modeField = null;
|
||||
$protectedValue = null;
|
||||
$field = $this->jsonsf($json, $key, "variable");
|
||||
if ($field !== null) {
|
||||
if (isset($field->mode)) {
|
||||
$modeField = $field->mode;
|
||||
$result = array();
|
||||
$previusFunction = $this->onPropertyRead;
|
||||
$this->onPropertyRead = function($json, $key, $value) use (&$post) {
|
||||
if ($key === "type" && isset($json->variable) && !empty($json->variable)) {
|
||||
if (isset($json->protectedValue) && $json->protectedValue === true) {
|
||||
if (isset($post[$json->variable])) {
|
||||
unset($post[$json->variable]);
|
||||
}
|
||||
if (isset($post[$json->variable . "_label"])) {
|
||||
unset($post[$json->variable . "_label"]);
|
||||
}
|
||||
}
|
||||
if ($modeField === "parent") {
|
||||
$modeField = $modeForm;
|
||||
}
|
||||
if (isset($field->protectedValue)) {
|
||||
$protectedValue = $field->protectedValue;
|
||||
}
|
||||
}
|
||||
//insert for strict validation: || $modeField === "view" || $this->fields["STEP_MODE"] === "VIEW"
|
||||
if ($field === null || $protectedValue === true) {
|
||||
if (isset($post[$key])) {
|
||||
unset($post[$key]);
|
||||
}
|
||||
if (isset($post[$key . "_label"])) {
|
||||
unset($post[$key . "_label"]);
|
||||
}
|
||||
}
|
||||
//columns
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $keyRow => $valueRow) {
|
||||
foreach ($valueRow as $keyCell => $valueCell) {
|
||||
if (substr($keyCell, -6, 6) === "_label") {
|
||||
continue;
|
||||
}
|
||||
$modeField = null;
|
||||
$protectedValue = null;
|
||||
$field = $this->jsonsf($json, $keyCell, "id");
|
||||
if ($field !== null) {
|
||||
if (isset($field->mode)) {
|
||||
$modeField = $field->mode;
|
||||
}
|
||||
if ($modeField === "parent") {
|
||||
$modeField = $modeForm;
|
||||
}
|
||||
if (isset($field->protectedValue)) {
|
||||
$protectedValue = $field->protectedValue;
|
||||
}
|
||||
}
|
||||
//insert for strict validation: || $modeField === "view" || $this->fields["STEP_MODE"] === "VIEW"
|
||||
if ($field === null || $protectedValue === true) {
|
||||
if (isset($post[$key][$keyRow][$keyCell])) {
|
||||
unset($post[$key][$keyRow][$keyCell]);
|
||||
}
|
||||
if (isset($post[$key][$keyRow][$keyCell . "_label"])) {
|
||||
unset($post[$key][$keyRow][$keyCell . "_label"]);
|
||||
if ($json->type === "grid" && is_array($json->columns)) {
|
||||
foreach ($json->columns as $column) {
|
||||
if (isset($column->protectedValue) && $column->protectedValue === true) {
|
||||
$dataGrid = is_array($post[$json->variable]) ? $post[$json->variable] : array();
|
||||
foreach ($dataGrid as $keyRow => $row) {
|
||||
if (isset($post[$json->variable][$keyRow][$column->id])) {
|
||||
unset($post[$json->variable][$keyRow][$column->id]);
|
||||
}
|
||||
if (isset($post[$json->variable][$keyRow][$column->id . "_label"])) {
|
||||
unset($post[$json->variable][$keyRow][$column->id . "_label"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//validator data
|
||||
$validatorClass = ProcessMaker\BusinessModel\DynaForm\ValidatorFactory::createValidatorClass($json->type, $json);
|
||||
if ($validatorClass !== null) {
|
||||
$validatorClass->validatePost($post);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
$json = G::json_decode($this->record["DYN_CONTENT"]);
|
||||
$this->jsonr($json);
|
||||
$this->onPropertyRead = $previusFunction;
|
||||
return $post;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\BusinessModel\DynaForm;
|
||||
|
||||
abstract class Validator implements ValidatorInterface
|
||||
{
|
||||
|
||||
protected $json;
|
||||
|
||||
public function __construct($json)
|
||||
{
|
||||
$this->json = $json;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\BusinessModel\DynaForm;
|
||||
|
||||
class ValidatorCheckGroup extends Validator
|
||||
{
|
||||
|
||||
public function validatePost(&$post)
|
||||
{
|
||||
$json = $this->json;
|
||||
if ($json === null) {
|
||||
return;
|
||||
}
|
||||
if (!isset($post[$json->variable])) {
|
||||
$post[$json->variable] = array();
|
||||
$post[$json->variable . "_label"] = \G::json_encode(array());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\BusinessModel\DynaForm;
|
||||
|
||||
class ValidatorFactory
|
||||
{
|
||||
|
||||
const TITLE = "title";
|
||||
const SUBTITLE = "subtitle";
|
||||
const LABEL = "label"; //deprecated
|
||||
const LINK = "link";
|
||||
const IMAGE = "image";
|
||||
const FILE = "file";
|
||||
const SUBMIT = "submit";
|
||||
const BUTTON = "button";
|
||||
const GRID = "grid";
|
||||
const SUBFORM = "subform";
|
||||
const TEXT = "text";
|
||||
const TEXTAREA = "textarea";
|
||||
const DROPDOWN = "dropdown";
|
||||
const CHECKBOX = "checkbox";
|
||||
const CHECKGROUP = "checkgroup";
|
||||
const RADIO = "radio";
|
||||
const DATETIME = "datetime";
|
||||
const SUGGEST = "suggest";
|
||||
const HIDDEN = "hidden";
|
||||
const FORM = "form";
|
||||
const CELL = "cell";
|
||||
const ANNOTATION = "label"; //todo
|
||||
const GEOMAP = "location";
|
||||
const QRCODE = "scannerCode";
|
||||
const SIGNATURE = "signature";
|
||||
const IMAGEM = "imageMobile";
|
||||
const AUDIOM = "audioMobile";
|
||||
const VIDEOM = "videoMobile";
|
||||
const PANEL = "panel";
|
||||
const MSGPANEL = "msgPanel";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type $type
|
||||
* @param type $json
|
||||
* @return \ProcessMaker\BusinessModel\DynaForm\ValidatorInterface
|
||||
*/
|
||||
public static function createValidatorClass($type = '', $json = null)
|
||||
{
|
||||
switch ($type) {
|
||||
case ValidatorFactory::CHECKGROUP:
|
||||
return new ValidatorCheckGroup($json);
|
||||
default :
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\BusinessModel\DynaForm;
|
||||
|
||||
interface ValidatorInterface
|
||||
{
|
||||
|
||||
public function validatePost(&$post);
|
||||
}
|
||||
Reference in New Issue
Block a user