public static function formatValueMultiple(FieldType $fieldType, $value, $format = 'printable')
 {
     if (!is_array($value) || is_array($value) && \CBPHelper::isAssociativeArray($value)) {
         $value = array($value);
     }
     foreach ($value as $k => $v) {
         $value[$k] = static::formatValuePrintable($fieldType, $v);
     }
     return implode(static::getFormatSeparator($format), $value);
 }
Пример #2
0
 /**
  * @param FieldType $fieldType Document field type.
  * @param array $field Form field.
  * @param mixed $value Field value.
  * @param bool $allowSelection Allow selection flag.
  * @param int $renderMode Control render mode.
  * @return string
  */
 public static function renderControlMultiple(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
 {
     if ($renderMode & FieldType::RENDER_MODE_DESIGNER) {
         if (is_array($value) && !\CBPHelper::isAssociativeArray($value)) {
             reset($value);
             $value = current($value);
         }
         return parent::renderControlSingle($fieldType, $field, $value, $allowSelection, $renderMode);
     }
     return parent::renderControlMultiple($fieldType, $field, $value, $allowSelection, $renderMode);
 }
Пример #3
0
 public function GetFieldInputValuePrintable($documentType, $fieldType, $fieldValue)
 {
     $result = $fieldValue;
     switch ($fieldType['Type']) {
         case "user":
             if (!is_array($fieldValue)) {
                 $fieldValue = array($fieldValue);
             }
             $result = CBPHelper::usersArrayToString($fieldValue, null, array("lists", get_called_class(), $documentType));
             break;
         case "bool":
             if (is_array($fieldValue)) {
                 $result = array();
                 foreach ($fieldValue as $r) {
                     $result[] = strtoupper($r) != "N" && !empty($r) ? GetMessage("BPVDX_YES") : GetMessage("BPVDX_NO");
                 }
             } else {
                 $result = strtoupper($fieldValue) != "N" && !empty($fieldValue) ? GetMessage("BPVDX_YES") : GetMessage("BPVDX_NO");
             }
             break;
         case "file":
             if (is_array($fieldValue)) {
                 $result = array();
                 foreach ($fieldValue as $r) {
                     $r = intval($r);
                     $imgQuery = CFile::getByID($r);
                     if ($img = $imgQuery->fetch()) {
                         $result[] = "[url=/bitrix/tools/bizproc_show_file.php?f=" . htmlspecialcharsbx($img["FILE_NAME"]) . "&i=" . $r . "&h=" . md5($img["SUBDIR"]) . "]" . htmlspecialcharsbx($img["ORIGINAL_NAME"]) . "[/url]";
                     }
                 }
             } else {
                 $fieldValue = intval($fieldValue);
                 $imgQuery = CFile::getByID($fieldValue);
                 if ($img = $imgQuery->fetch()) {
                     $result = "[url=/bitrix/tools/bizproc_show_file.php?f=" . htmlspecialcharsbx($img["FILE_NAME"]) . "&i=" . $fieldValue . "&h=" . md5($img["SUBDIR"]) . "]" . htmlspecialcharsbx($img["ORIGINAL_NAME"]) . "[/url]";
                 }
             }
             break;
         case "select":
             if (is_array($fieldType["Options"])) {
                 if (is_array($fieldValue)) {
                     $result = array();
                     foreach ($fieldValue as $r) {
                         if (array_key_exists($r, $fieldType["Options"])) {
                             $result[] = $fieldType["Options"][$r];
                         }
                     }
                 } else {
                     if (array_key_exists($fieldValue, $fieldType["Options"])) {
                         $result = $fieldType["Options"][$fieldValue];
                     }
                 }
             }
             break;
     }
     if (strpos($fieldType['Type'], ":") !== false) {
         if ($fieldType["Type"] == "S:employee") {
             $fieldValue = CBPHelper::stripUserPrefix($fieldValue);
         }
         $customType = CIBlockProperty::getUserType(substr($fieldType['Type'], 2));
         if (array_key_exists("GetPublicViewHTML", $customType)) {
             if (is_array($fieldValue) && !CBPHelper::isAssociativeArray($fieldValue)) {
                 $result = array();
                 foreach ($fieldValue as $value) {
                     $r = call_user_func_array($customType["GetPublicViewHTML"], array(array("LINK_IBLOCK_ID" => $fieldType["Options"]), array("VALUE" => $value), ""));
                     $result[] = HTMLToTxt($r);
                 }
             } else {
                 $result = call_user_func_array($customType["GetPublicViewHTML"], array(array("LINK_IBLOCK_ID" => $fieldType["Options"]), array("VALUE" => $fieldValue), ""));
                 $result = HTMLToTxt($result);
             }
         }
     }
     return $result;
 }
Пример #4
0
 /**
  * @param FieldType $fieldType Document field type.
  * @param mixed $value Field value.
  * @return void
  */
 public static function clearValueMultiple(FieldType $fieldType, $value)
 {
     if (!is_array($value) || is_array($value) && \CBPHelper::isAssociativeArray($value)) {
         $value = array($value);
     }
     foreach ($value as $v) {
         static::clearValueSingle($fieldType, $v);
     }
 }
Пример #5
0
 /**
  * @param FieldType $fieldType Document field type.
  * @param array $field Form field.
  * @param array $request Request data.
  * @return array
  */
 public static function extractValueMultiple(FieldType $fieldType, array $field, array $request)
 {
     $name = $field['Field'];
     $value = isset($request[$name]) ? $request[$name] : array();
     if (!is_array($value) || is_array($value) && \CBPHelper::isAssociativeArray($value)) {
         $value = array($value);
     }
     $value = array_unique($value);
     $request[$name] = $value;
     return parent::extractValueMultiple($fieldType, $field, $request);
 }
Пример #6
0
 /**
  * @param FieldType $fieldType Document field type.
  * @param array $field Form field.
  * @param mixed $value Field value.
  * @param bool $allowSelection Allow selection flag.
  * @param int $renderMode Control render mode.
  * @return string
  */
 public static function renderControlMultiple(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
 {
     if (!is_array($value) || is_array($value) && \CBPHelper::isAssociativeArray($value)) {
         $value = array($value);
     }
     if (empty($value)) {
         $value[] = null;
     }
     $controls = array();
     foreach ($value as $k => $v) {
         $singleField = $field;
         $singleField['Index'] = $k;
         $controls[] = static::renderControl($fieldType, $singleField, $v, $allowSelection, $renderMode);
     }
     $renderResult = static::wrapCloneableControls($controls, static::generateControlName($field));
     return $renderResult;
 }
 /**
  * @param FieldType $fieldType Document field object.
  * @param array $field Form field information.
  * @param mixed $value Field value.
  * @param bool $allowSelection Allow selection flag.
  * @param int $renderMode Control render mode.
  * @return string
  */
 public static function renderControlMultiple(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
 {
     $selectorValue = null;
     $typeValue = array();
     if (!is_array($value) || is_array($value) && \CBPHelper::isAssociativeArray($value)) {
         $value = array($value);
     }
     foreach ($value as $v) {
         if (\CBPActivity::isExpression($v)) {
             $selectorValue = $v;
         } else {
             $typeValue[] = $v;
         }
     }
     // need to show at least one control
     if (empty($typeValue)) {
         $typeValue[] = null;
     }
     $controls = array();
     foreach ($typeValue as $k => $v) {
         $singleField = $field;
         $singleField['Index'] = $k;
         $controls[] = static::renderControl($fieldType, $singleField, $v, $allowSelection, $renderMode);
     }
     $renderResult = static::wrapCloneableControls($controls, static::generateControlName($field));
     if ($allowSelection) {
         $renderResult .= static::renderControlSelector($field, $selectorValue, true);
     }
     return $renderResult;
 }
Пример #8
0
 /**
  * @param FieldType $fieldType Document field type.
  * @param mixed $value Field value.
  * @param string $toTypeClass Type class name.
  * @return array
  */
 public static function convertValueMultiple(FieldType $fieldType, $value, $toTypeClass)
 {
     if (is_array($value) && \CBPHelper::isAssociativeArray($value)) {
         $value = array_keys($value);
     }
     return parent::convertValueMultiple($fieldType, $value, $toTypeClass);
 }
Пример #9
0
 /**
  * @param FieldType $fieldType Document field object.
  * @param array $field Form field information.
  * @param mixed $value Field value.
  * @param bool $allowSelection Allow selection flag.
  * @param int $renderMode Control render mode.
  * @return string
  */
 public static function renderControlMultiple(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
 {
     $selectorValue = null;
     $typeValue = array();
     if (!is_array($value) || is_array($value) && \CBPHelper::isAssociativeArray($value)) {
         $value = array($value);
     }
     foreach ($value as $v) {
         if (\CBPActivity::isExpression($v)) {
             $selectorValue = $v;
         } else {
             $typeValue[] = $v;
         }
     }
     $userType = static::getUserType($fieldType);
     if (!empty($userType['GetPublicEditHTMLMulty'])) {
         foreach ($typeValue as $k => &$fld) {
             if (!isset($fld['VALUE'])) {
                 $fld = array('VALUE' => $fld);
             }
             if ($fld['VALUE'] === null) {
                 unset($typeValue[$k]);
             }
         }
         $typeValue = array_values($typeValue);
         $renderResult = call_user_func_array($userType['GetPublicEditHTMLMulty'], array(array('LINK_IBLOCK_ID' => $fieldType->getOptions()), $typeValue, array('FORM_NAME' => $field['Form'], 'VALUE' => static::generateControlName($field)), true));
     } else {
         $controls = array();
         // need to show at least one control
         if (empty($typeValue)) {
             $typeValue[] = null;
         }
         foreach ($typeValue as $k => $v) {
             $singleField = $field;
             $singleField['Index'] = $k;
             $controls[] = static::renderControlSingle($fieldType, $singleField, $v, $allowSelection, $renderMode);
         }
         $renderResult = static::wrapCloneableControls($controls, static::generateControlName($field));
     }
     if ($allowSelection) {
         $renderResult .= static::renderControlSelector($field, $selectorValue, true);
     }
     return $renderResult;
 }
 /**
  * @param FieldType $fieldType Document field object.
  * @param array $field Form field information.
  * @param mixed $value Field value.
  * @param bool $allowSelection Allow selection flag.
  * @param int $renderMode Control render mode.
  * @return string
  */
 public static function renderControlMultiple(FieldType $fieldType, array $field, $value, $allowSelection, $renderMode)
 {
     $value = static::fixUserPrefix($value);
     $renderResult = parent::renderControlMultiple($fieldType, $field, $value, false, $renderMode);
     if ($allowSelection) {
         $selectorValue = null;
         if (!is_array($value) || is_array($value) && \CBPHelper::isAssociativeArray($value)) {
             $value = array($value);
         }
         foreach ($value as $v) {
             if (\CBPActivity::isExpression($v)) {
                 $selectorValue = $v;
             }
         }
         $renderResult .= static::renderControlSelector($field, $selectorValue, true, 'employee');
     }
     return $renderResult;
 }
Пример #11
0
 /**
  * ћетод создает новый документ с указанными свойствами (пол¤ми).
  *
  * @param array $arFields - массив значений свойств документа в виде array(код_свойства => значение, ...).  оды свойств соответствуют кодам свойств, возвращаемым методом GetDocumentFields.
  * @return int - код созданного документа.
  */
 public function CreateDocument($parentDocumentId, $arFields)
 {
     if (!array_key_exists("IBLOCK_ID", $arFields) || intval($arFields["IBLOCK_ID"]) <= 0) {
         throw new Exception("IBlock ID is not found");
     }
     $arFieldsPropertyValues = array();
     $arDocumentFields = self::GetDocumentFields("iblock_" . $arFields["IBLOCK_ID"]);
     $arKeys = array_keys($arFields);
     $listId = array();
     foreach ($arKeys as $key) {
         if (!array_key_exists($key, $arDocumentFields)) {
             continue;
         }
         $arFields[$key] = is_array($arFields[$key]) && !CBPHelper::IsAssociativeArray($arFields[$key]) ? $arFields[$key] : array($arFields[$key]);
         $realKey = substr($key, 0, strlen("PROPERTY_")) == "PROPERTY_" ? substr($key, strlen("PROPERTY_")) : $key;
         if ($arDocumentFields[$key]["Type"] == "user") {
             $ar = array();
             foreach ($arFields[$key] as $v1) {
                 if (substr($v1, 0, strlen("user_")) == "user_") {
                     $ar[] = substr($v1, strlen("user_"));
                 } else {
                     $a1 = self::GetUsersFromUserGroup($v1, $parentDocumentId);
                     foreach ($a1 as $a11) {
                         $ar[] = $a11;
                     }
                 }
             }
             $arFields[$key] = $ar;
         } elseif ($arDocumentFields[$key]["Type"] == "select") {
             $arV = array();
             $db = CIBlockProperty::GetPropertyEnum($realKey, false, array("IBLOCK_ID" => $arFields["IBLOCK_ID"]));
             while ($ar = $db->GetNext()) {
                 $arV[$ar["XML_ID"]] = $ar["ID"];
             }
             $listValue = array();
             foreach ($arFields[$key] as &$value) {
                 if (CBPHelper::isAssociativeArray($value)) {
                     $listXmlId = array_keys($value);
                     foreach ($listXmlId as $xmlId) {
                         $listValue[] = $arV[$xmlId];
                     }
                 } else {
                     if (array_key_exists($value, $arV)) {
                         $value = $arV[$value];
                     }
                 }
             }
             if (!empty($listValue)) {
                 $arFields[$key] = $listValue;
             }
         } elseif ($arDocumentFields[$key]["Type"] == "file") {
             foreach ($arFields[$key] as &$value) {
                 $value = CFile::MakeFileArray($value);
             }
         } elseif ($arDocumentFields[$key]["Type"] == "S:DiskFile") {
             foreach ($arFields[$key] as &$value) {
                 if (is_array($value)) {
                     foreach ($value as $attachId) {
                         $listId[$realKey][] = $attachId;
                     }
                 } else {
                     $listId[$realKey][] = $value;
                 }
             }
         } elseif ($arDocumentFields[$key]["Type"] == "S:HTML") {
             foreach ($arFields[$key] as &$value) {
                 $value = array("VALUE" => $value);
             }
         }
         if (!$arDocumentFields[$key]["Multiple"] && is_array($arFields[$key])) {
             if (count($arFields[$key]) > 0) {
                 $a = array_values($arFields[$key]);
                 $arFields[$key] = $a[0];
             } else {
                 $arFields[$key] = null;
             }
         }
         if (substr($key, 0, strlen("PROPERTY_")) == "PROPERTY_") {
             $realKey = substr($key, strlen("PROPERTY_"));
             $arFieldsPropertyValues[$realKey] = is_array($arFields[$key]) && !CBPHelper::IsAssociativeArray($arFields[$key]) ? $arFields[$key] : array($arFields[$key]);
             unset($arFields[$key]);
         }
     }
     if (count($arFieldsPropertyValues) > 0) {
         $arFields["PROPERTY_VALUES"] = $arFieldsPropertyValues;
     }
     $iblockElement = new CIBlockElement();
     $id = $iblockElement->Add($arFields, false, true, true);
     if (!$id || $id <= 0) {
         throw new Exception($iblockElement->LAST_ERROR);
     }
     /* Attaching files from the disk to the iblock element */
     if (!empty($listId)) {
         $fields = array();
         foreach ($listId as $propertyCode => $attachedData) {
             $attachedId = array();
             foreach ($attachedData as $fileId) {
                 $attachId = self::attachFileDisk($arFields["IBLOCK_ID"], $id, $fileId, array());
                 if (!empty($attachId)) {
                     $attachedId["VALUE"][] = $attachId;
                 }
             }
             $fields["PROPERTY_VALUES"][$propertyCode] = $attachedId;
         }
         if (!empty($fields["PROPERTY_VALUES"])) {
             $iblockElement->SetPropertyValuesEx($id, $arFields["IBLOCK_ID"], $fields["PROPERTY_VALUES"]);
         }
     }
     return $id;
 }