Example #1
0
 public static function GetPropertiesDialogValues($documentType, $activityName, &$workflowTemplate, &$workflowParameters, &$workflowVariables, $currentValues, &$errors)
 {
     $runtime = CBPRuntime::GetRuntime();
     $errors = array();
     $map = array('setstatusmessage' => 'SetStatusMessage', 'statusmessage' => 'StatusMessage', 'usesubscription' => 'UseSubscription', 'timeoutduration' => 'TimeoutDuration', 'timeoutdurationtype' => 'TimeoutDurationType');
     $properties = array();
     foreach ($map as $key => $value) {
         $properties[$value] = $currentValues[$key];
     }
     $activityData = self::getRestActivityData();
     $activityProperties = isset($activityData['PROPERTIES']) && is_array($activityData['PROPERTIES']) ? $activityData['PROPERTIES'] : array();
     /** @var CBPDocumentService $documentService */
     $documentService = $runtime->GetService('DocumentService');
     $activityDocumentType = is_array($activityData['DOCUMENT_TYPE']) ? $activityData['DOCUMENT_TYPE'] : $documentType;
     foreach ($activityProperties as $name => $property) {
         $requestName = strtolower($name);
         if (isset($properties[$requestName])) {
             continue;
         }
         $errors = array();
         $properties[$name] = $documentService->GetFieldInputValue($activityDocumentType, $property, $requestName, $currentValues, $errors);
         if (count($errors) > 0) {
             return false;
         }
     }
     if (static::checkAdminPermissions()) {
         $properties['AuthUserId'] = CBPHelper::usersStringToArray($currentValues['authuserid'], $documentType, $errors);
         if (count($errors) > 0) {
             return false;
         }
     } else {
         unset($properties['AuthUserId']);
     }
     if (!empty($activityData['USE_SUBSCRIPTION'])) {
         $properties['UseSubscription'] = $activityData['USE_SUBSCRIPTION'];
     }
     $errors = self::ValidateProperties($properties, new CBPWorkflowTemplateUser(CBPWorkflowTemplateUser::CurrentUser));
     if (count($errors) > 0) {
         return false;
     }
     $currentActivity =& CBPWorkflowTemplateLoader::FindActivityByName($workflowTemplate, $activityName);
     $currentActivity["Properties"] = $properties;
     return true;
 }
Example #2
0
 public function GetFieldInputValue($documentType, $fieldType, $fieldName, $request, &$errors)
 {
     $iblockId = intval(substr($documentType, strlen("iblock_")));
     if ($iblockId <= 0) {
         throw new CBPArgumentOutOfRangeException("documentType", $documentType);
     }
     $result = array();
     if ($fieldType["Type"] == "user") {
         $value = $request[$fieldName["Field"]];
         if (strlen($value) > 0) {
             $result = CBPHelper::usersStringToArray($value, array("lists", get_called_class(), $documentType), $errors);
             if (count($errors) > 0) {
                 foreach ($errors as $e) {
                     $errors[] = $e;
                 }
             }
         } else {
             $result = null;
         }
     } elseif (array_key_exists($fieldName["Field"], $request) || array_key_exists($fieldName["Field"] . "_text", $request)) {
         $valueArray = array();
         if (array_key_exists($fieldName["Field"], $request)) {
             $valueArray = $request[$fieldName["Field"]];
             if (!is_array($valueArray) || is_array($valueArray) && CBPHelper::isAssociativeArray($valueArray)) {
                 $valueArray = array($valueArray);
             }
         }
         if (array_key_exists($fieldName["Field"] . "_text", $request)) {
             $valueArray[] = $request[$fieldName["Field"] . "_text"];
         }
         foreach ($valueArray as $value) {
             if (is_array($value) || !is_array($value) && !\CBPDocument::IsExpression(trim($value))) {
                 if ($fieldType["Type"] == "int") {
                     if (strlen($value) > 0) {
                         $value = str_replace(" ", "", $value);
                         if ($value . "|" == intval($value) . "|") {
                             $value = intval($value);
                         } else {
                             $value = null;
                             $errors[] = array("code" => "ErrorValue", "message" => GetMessage("LISTS_BIZPROC_INVALID_INT"), "parameter" => $fieldName["Field"]);
                         }
                     } else {
                         $value = null;
                     }
                 } elseif ($fieldType["Type"] == "double") {
                     if (strlen($value) > 0) {
                         $value = str_replace(" ", "", str_replace(",", ".", $value));
                         if (is_numeric($value)) {
                             $value = doubleval($value);
                         } else {
                             $value = null;
                             $errors[] = array("code" => "ErrorValue", "message" => GetMessage("LISTS_BIZPROC_INVALID_INT"), "parameter" => $fieldName["Field"]);
                         }
                     } else {
                         $value = null;
                     }
                 } elseif ($fieldType["Type"] == "select") {
                     if (!is_array($fieldType["Options"]) || count($fieldType["Options"]) <= 0 || strlen($value) <= 0) {
                         $value = null;
                     } else {
                         $ar = array_values($fieldType["Options"]);
                         if (is_array($ar[0])) {
                             $b = false;
                             foreach ($ar as $a) {
                                 if ($a[0] == $value) {
                                     $b = true;
                                     break;
                                 }
                             }
                             if (!$b) {
                                 $value = null;
                                 $errors[] = array("code" => "ErrorValue", "message" => GetMessage("LISTS_BIZPROC_INVALID_SELECT"), "parameter" => $fieldName["Field"]);
                             }
                         } else {
                             if (!array_key_exists($value, $fieldType["Options"])) {
                                 $value = null;
                                 $errors[] = array("code" => "ErrorValue", "message" => GetMessage("LISTS_BIZPROC_INVALID_SELECT"), "parameter" => $fieldName["Field"]);
                             }
                         }
                     }
                 } elseif ($fieldType["Type"] == "bool") {
                     if ($value !== "Y" && $value !== "N") {
                         if ($value === true) {
                             $value = "Y";
                         } elseif ($value === false) {
                             $value = "N";
                         } elseif (strlen($value) > 0) {
                             $value = strtolower($value);
                             if (in_array($value, array("y", "yes", "true", "1"))) {
                                 $value = "Y";
                             } elseif (in_array($value, array("n", "no", "false", "0"))) {
                                 $value = "N";
                             } else {
                                 $value = null;
                                 $errors[] = array("code" => "ErrorValue", "message" => GetMessage("BPCGWTL_INVALID45"), "parameter" => $fieldName["Field"]);
                             }
                         } else {
                             $value = null;
                         }
                     }
                 } elseif ($fieldType["Type"] == "file") {
                     if (is_array($value) && array_key_exists("name", $value) && strlen($value["name"]) > 0) {
                         if (!array_key_exists("MODULE_ID", $value) || strlen($value["MODULE_ID"]) <= 0) {
                             $value["MODULE_ID"] = "bizproc";
                         }
                         $value = CFile::saveFile($value, "bizproc_wf", true, true);
                         if (!$value) {
                             $value = null;
                             $errors[] = array("code" => "ErrorValue", "message" => GetMessage("BPCGWTL_INVALID915"), "parameter" => $fieldName["Field"]);
                         }
                     } else {
                         $value = null;
                     }
                 } elseif ($fieldType["Type"] == "date") {
                     if (strlen($value) > 0) {
                         if (!CheckDateTime($value, FORMAT_DATE)) {
                             $value = null;
                             $errors[] = array("code" => "ErrorValue", "message" => GetMessage("LISTS_BIZPROC_INVALID_DATE"), "parameter" => $fieldName["Field"]);
                         }
                     } else {
                         $value = null;
                     }
                 } elseif ($fieldType["Type"] == "datetime") {
                     if (strlen($value) > 0) {
                         $valueTemporary = array();
                         $valueTemporary["VALUE"] = $value;
                         $result = CIBlockPropertyDateTime::checkFields('', $valueTemporary);
                         if (!empty($result)) {
                             $message = '';
                             foreach ($result as $error) {
                                 $message .= $error;
                             }
                             $value = null;
                             $errors[] = array("code" => "ErrorValue", "message" => $message, "parameter" => $fieldName["Field"]);
                         }
                     } else {
                         $value = null;
                     }
                 } elseif (strpos($fieldType["Type"], ":") !== false && $fieldType["Type"] != "S:HTML") {
                     $customType = CIBlockProperty::getUserType(substr($fieldType["Type"], 2));
                     if (array_key_exists("GetLength", $customType)) {
                         if (call_user_func_array($customType["GetLength"], array(array("LINK_IBLOCK_ID" => $fieldType["Options"]), array("VALUE" => $value))) <= 0) {
                             $value = null;
                         }
                     }
                     if ($value != null && array_key_exists("CheckFields", $customType)) {
                         $errorsTemporary = call_user_func_array($customType["CheckFields"], array(array("LINK_IBLOCK_ID" => $fieldType["Options"]), array("VALUE" => $value)));
                         if (count($errorsTemporary) > 0) {
                             $value = null;
                             foreach ($errorsTemporary as $e) {
                                 $errors[] = array("code" => "ErrorValue", "message" => $e, "parameter" => $fieldName["Field"]);
                             }
                         }
                     } elseif (!array_key_exists("GetLength", $customType) && $value === '') {
                         $value = null;
                     }
                     if ($value !== null && $fieldType["Type"] == "S:employee" && COption::getOptionString("bizproc", "employee_compatible_mode", "N") != "Y") {
                         $value = "user_" . $value;
                     }
                 } else {
                     if (!is_array($value) && strlen($value) <= 0) {
                         $value = null;
                     }
                 }
             }
             if ($value !== null) {
                 $result[] = $value;
             }
         }
     }
     if (!$fieldType["Multiple"]) {
         if (is_array($result) && count($result) > 0) {
             $result = $result[0];
         } else {
             $result = null;
         }
     }
     return $result;
 }
Example #3
0
 /**
  * @param FieldType $fieldType Document field type.
  * @param array $field Form field.
  * @param array $request Request data.
  * @return array|null
  */
 protected static function extractValue(FieldType $fieldType, array $field, array $request)
 {
     $value = parent::extractValue($fieldType, $field, $request);
     $result = null;
     if (is_string($value) && strlen($value) > 0) {
         $errors = array();
         $result = \CBPHelper::usersStringToArray($value, $fieldType->getDocumentType(), $errors);
         if (sizeof($errors) > 0) {
             static::addErrors($errors);
         }
     }
     return $result;
 }