Exemple #1
0
 function InstallUserFields($id = "all")
 {
     global $APPLICATION;
     $errors = null;
     $id = in_array($id, array("all", "webdav", "disk")) ? $id : false;
     if (!!$id && IsModuleInstalled("webdav")) {
         $arFields = array("ENTITY_ID" => "FORUM_MESSAGE", "FIELD_NAME" => "UF_FORUM_MESSAGE_DOC", "XML_ID" => "UF_FORUM_MESSAGE_DOC", "USER_TYPE_ID" => "webdav_element", "SORT" => 100, "MULTIPLE" => "Y", "MANDATORY" => "N", "SHOW_FILTER" => "N", "SHOW_IN_LIST" => "N", "EDIT_IN_LIST" => "Y", "IS_SEARCHABLE" => "N");
         $rsData = CUserTypeEntity::GetList(array("ID" => "ASC"), array("ENTITY_ID" => "FORUM_MESSAGE", "FIELD_NAME" => "UF_FORUM_MESSAGE_DOCUMENT"));
         if (!($rsData && ($arRes = $rsData->Fetch()))) {
             $obUserField = new CUserTypeEntity();
             $intID = $obUserField->Add($arFields, false);
             if (false == $intID) {
                 if ($strEx = $GLOBALS['APPLICATION']->GetException()) {
                     $errors = $strEx->GetString();
                 }
             }
         }
     }
     if (($id == 'all' || $id == 'disk') && IsModuleInstalled("disk")) {
         $props = array(array("ENTITY_ID" => "FORUM_MESSAGE", "FIELD_NAME" => "UF_FORUM_MESSAGE_DOC", "USER_TYPE_ID" => "disk_file"), array("ENTITY_ID" => "FORUM_MESSAGE", "FIELD_NAME" => "UF_FORUM_MESSAGE_VER", "USER_TYPE_ID" => "disk_version"));
         $uf = new CUserTypeEntity();
         foreach ($props as $prop) {
             $rsData = CUserTypeEntity::getList(array("ID" => "ASC"), array("ENTITY_ID" => $prop["ENTITY_ID"], "FIELD_NAME" => $prop["FIELD_NAME"]));
             if (!($rsData && ($arRes = $rsData->Fetch()))) {
                 $intID = $uf->add(array("ENTITY_ID" => $prop["ENTITY_ID"], "FIELD_NAME" => $prop["FIELD_NAME"], "XML_ID" => $prop["FIELD_NAME"], "USER_TYPE_ID" => $prop["USER_TYPE_ID"], "SORT" => 100, "MULTIPLE" => $prop["USER_TYPE_ID"] == "disk_version" ? "N" : "Y", "MANDATORY" => "N", "SHOW_FILTER" => "N", "SHOW_IN_LIST" => "N", "EDIT_IN_LIST" => "Y", "IS_SEARCHABLE" => $prop["USER_TYPE_ID"] == "disk_file" ? "Y" : "N"), false);
                 if (false == $intID && ($strEx = $APPLICATION->getException())) {
                     $errors = $strEx->getString();
                 }
             }
         }
     }
     return $errors;
 }
Exemple #2
0
 function InstallUserFields($id = "all")
 {
     global $APPLICATION;
     $errors = null;
     if (($id == 'all' || $id == 'disk') && IsModuleInstalled('disk')) {
         $uf = new CUserTypeEntity();
         $rsData = CUserTypeEntity::getList(array("ID" => "ASC"), array("ENTITY_ID" => 'CALENDAR_EVENT', "FIELD_NAME" => 'UF_WEBDAV_CAL_EVENT'));
         if (!($rsData && ($arRes = $rsData->Fetch()))) {
             $intID = $uf->add(array("ENTITY_ID" => 'CALENDAR_EVENT', "FIELD_NAME" => 'UF_WEBDAV_CAL_EVENT', "XML_ID" => 'UF_WEBDAV_CAL_EVENT', "USER_TYPE_ID" => 'disk_file', "SORT" => 100, "MULTIPLE" => "Y", "MANDATORY" => "N", "SHOW_FILTER" => "N", "SHOW_IN_LIST" => "N", "EDIT_IN_LIST" => "Y", "IS_SEARCHABLE" => "Y"), false);
             if (false == $intID && ($strEx = $APPLICATION->getException())) {
                 $errors[] = $strEx->getString();
             }
         }
     }
     if (($id == 'all' || $id == 'webdav') && IsModuleInstalled('webdav')) {
         $ENTITY_ID = 'CALENDAR_EVENT';
         $FIELD_NAME = 'UF_WEBDAV_CAL_EVENT';
         $arElement = $GLOBALS['USER_FIELD_MANAGER']->GetUserFields($ENTITY_ID, 0);
         if (empty($arElement) || $arElement == array() || $arElement == false || !isset($arElement[$FIELD_NAME])) {
             $arFields = array("ENTITY_ID" => $ENTITY_ID, "FIELD_NAME" => $FIELD_NAME, "XML_ID" => $FIELD_NAME, "USER_TYPE_ID" => "webdav_element", "SORT" => 100, "MULTIPLE" => "Y", "MANDATORY" => "N", "SHOW_FILTER" => "N", "SHOW_IN_LIST" => "N", "EDIT_IN_LIST" => "Y", "IS_SEARCHABLE" => "N");
             $obUserField = new CUserTypeEntity();
             $intID = $obUserField->Add($arFields, false);
             if (false == $intID) {
                 if ($strEx = $APPLICATION->GetException()) {
                     $errors[] = $strEx->GetString();
                 }
             }
         }
     }
     return $errors;
 }
 public static function addDocumentField($documentType, $fields)
 {
     $storageId = self::getStorageIdByType($documentType);
     if (!$storageId) {
         throw new CBPArgumentNullException('documentType');
     }
     if (strpos($fields['type'], static::getPrefixForCustomType()) === 0) {
         $fields['type'] = substr($fields['type'], 3);
     }
     $fieldsTmp = array('USER_TYPE_ID' => $fields['type'], 'FIELD_NAME' => 'UF_' . strtoupper($fields['code']), 'ENTITY_ID' => 'DISK_FILE_' . $storageId, 'SORT' => 150, 'MULTIPLE' => $fields['multiple'] == 'Y' ? 'Y' : 'N', 'MANDATORY' => $fields['required'] == 'Y' ? 'Y' : 'N', 'SHOW_FILTER' => 'E');
     $fieldsTmp['EDIT_FORM_LABEL'][LANGUAGE_ID] = $fields['name'];
     $fieldsTmp['LIST_COLUMN_LABEL'][LANGUAGE_ID] = $fields['name'];
     $fieldsTmp['LIST_FILTER_LABEL'][LANGUAGE_ID] = $fields['name'];
     switch ($fields['type']) {
         case 'select':
         case 'enumeration':
             $fieldsTmp['USER_TYPE_ID'] = 'enumeration';
             if (!is_array($fieldsTmp['LIST'])) {
                 $fieldsTmp['LIST'] = array();
             }
             $options = isset($fields['options']) && is_array($fields['options']) ? $fields['options'] : array();
             if (!empty($options)) {
                 $i = 10;
                 foreach ($options as $k => $v) {
                     $fieldsTmp['LIST']['n' . $i] = array('XML_ID' => $k, 'VALUE' => $v, 'DEF' => 'N', 'SORT' => $i);
                     $i = $i + 10;
                 }
             }
             break;
         case 'text':
             $fieldsTmp['USER_TYPE_ID'] = 'string';
             break;
     }
     $userField = new \CUserTypeEntity();
     $id = $userField->add($fieldsTmp);
     if ($id > 0) {
         if ($fieldsTmp['USER_TYPE_ID'] == 'enumeration' && is_array($fieldsTmp['LIST'])) {
             $enum = new \CUserFieldEnum();
             $res = $enum->setEnumValues($id, $fieldsTmp['LIST']);
         }
     }
     return $fieldsTmp['FIELD_NAME'];
 }
 protected function migrateCustomElementProperties($iblockId, $entityNewName)
 {
     $iblockId = (int) $iblockId;
     $VERSION = \CIBlockElement::GetIBVersion($iblockId);
     if ($VERSION == 2) {
         $strTable = "b_iblock_element_prop_m" . $iblockId;
     } else {
         $strTable = "b_iblock_element_property";
     }
     $tableNameUf = "b_utm_" . strtolower($entityNewName);
     $tableNameSingleUf = "b_uts_" . strtolower($entityNewName);
     $sqlHelper = $this->connection->getSqlHelper();
     $listElementAll = array();
     $objectQuery = $this->connection->query("\n\t\t\tSELECT obj.ID, prop.VALUE, prop.IBLOCK_PROPERTY_ID\n\t\t\tFROM b_disk_object obj\n\t\t\tINNER JOIN {$strTable} prop ON obj.WEBDAV_ELEMENT_ID = prop.IBLOCK_ELEMENT_ID\n\t\t\tWHERE obj.WEBDAV_IBLOCK_ID = {$iblockId} AND obj.TYPE = 3\n\t\t");
     while ($listObject = $objectQuery->fetch()) {
         $listElementAll[$listObject['ID']][$listObject['IBLOCK_PROPERTY_ID']]['FIELD_VALUE'][] = $listObject['VALUE'];
     }
     $listElement = array();
     foreach ($this->getIblockProperties($iblockId) as $prop) {
         $propId = $prop['ID'];
         $mappedUfType = $this->mapTypeElementPropertyToUfType($prop);
         if (!$mappedUfType) {
             $this->log(array('Unknown property of element', $prop));
             continue;
         }
         $userTypeEntity = new \CUserTypeEntity();
         $symbolicName = empty($prop['CODE']) ? $propId : strtoupper($prop['CODE']);
         $xmlId = empty($prop['CODE']) ? $propId : $prop['CODE'];
         $fieldName = substr('UF_' . $symbolicName, 0, 20);
         if ($mappedUfType == 'iblock_section' || $mappedUfType == 'iblock_element') {
             $settingsArray = array('IBLOCK_ID' => $prop['LINK_IBLOCK_ID'], 'DISPLAY' => 'LIST');
         } else {
             $settingsArray = array();
         }
         $id = $userTypeEntity->add(array('ENTITY_ID' => $entityNewName, 'FIELD_NAME' => $fieldName, 'USER_TYPE_ID' => $mappedUfType, 'XML_ID' => 'PROPERTY_' . $xmlId, 'MULTIPLE' => $prop['MULTIPLE'], 'MANDATORY' => $prop['IS_REQUIRED'], 'SHOW_FILTER' => 'N', 'SHOW_IN_LIST' => null, 'EDIT_IN_LIST' => null, 'IS_SEARCHABLE' => $prop['SEARCHABLE'], 'SETTINGS' => $settingsArray, 'EDIT_FORM_LABEL' => array('en' => $prop['NAME'], 'ru' => $prop['NAME'], 'de' => $prop['NAME'])));
         if ($id) {
             if ($mappedUfType == 'enumeration') {
                 $i = 0;
                 $enumValues = array();
                 $queryEnum = \CIBlockPropertyEnum::getlist(array("SORT" => "ASC", "VALUE" => "ASC"), array('PROPERTY_ID' => $propId));
                 while ($queryEnum && ($rowEnum = $queryEnum->fetch())) {
                     $enumValues['n' . $i] = array('SORT' => $rowEnum['SORT'], 'VALUE' => $rowEnum['VALUE'], 'XML_ID' => $rowEnum['XML_ID'], 'DEF' => $rowEnum['DEF']);
                     $i++;
                 }
                 $userTypeEnum = new \CUserFieldEnum();
                 $userTypeEnum->setEnumValues($id, $enumValues);
             }
             foreach ($listElementAll as $newId => $propArray) {
                 if (array_key_exists($propId, $propArray)) {
                     $listElement[$newId][$propId]['FIELD_VALUE'] = $listElementAll[$newId][$propId]['FIELD_VALUE'];
                     $listElement[$newId][$propId]['FIELD_NAME'] = $fieldName;
                     if ($prop['MULTIPLE'] == 'Y') {
                         $listElement[$newId][$propId]['FIELD_ID'] = $id;
                         $listElement[$newId][$propId]['PROPERTY_TYPE'] = $mappedUfType;
                     }
                 }
             }
         }
     }
     if (!empty($listElement)) {
         foreach ($listElement as $newId => $propArray) {
             $fieldArray = array();
             $valueArray = array();
             foreach ($propArray as $prop) {
                 $fieldArray[] = $prop['FIELD_NAME'];
                 if (count($prop['FIELD_VALUE']) > 1) {
                     $valueArray[] = "'" . $sqlHelper->forSql(serialize($prop['FIELD_VALUE'])) . "'";
                     foreach ($prop['FIELD_VALUE'] as $utmValue) {
                         if ($prop['PROPERTY_TYPE'] == 'integer') {
                             $utmValue = (int) $utmValue;
                             $this->connection->queryExecute("\n\t\t\t\t\t\t\t\t\tINSERT INTO {$tableNameUf} (VALUE_ID, FIELD_ID, VALUE_INT)\n\t\t\t\t\t\t\t\t\tVALUES ({$newId}, {$prop['FIELD_ID']}, {$utmValue})\n\t\t\t\t\t\t\t\t");
                         } else {
                             $utmValueStr = "'" . $sqlHelper->forSql($utmValue) . "'";
                             $this->connection->queryExecute("\n\t\t\t\t\t\t\t\t\tINSERT INTO {$tableNameUf} (VALUE_ID, FIELD_ID, VALUE)\n\t\t\t\t\t\t\t\t\tVALUES ({$newId}, {$prop['FIELD_ID']}, {$utmValueStr})\n\t\t\t\t\t\t\t\t");
                         }
                     }
                 } else {
                     $valueArray[] = "'" . $sqlHelper->forSql($prop['FIELD_VALUE'][0]) . "'";
                 }
             }
             if (!empty($fieldArray)) {
                 if ($this->isMysql) {
                     $sql = "\n\t\t\t\t\t\t\tINSERT IGNORE INTO {$tableNameSingleUf} (VALUE_ID, " . implode(', ', $fieldArray) . ")\n\t\t\t\t\t\t\tVALUES ({$newId}, " . implode(', ', $valueArray) . ")\n\t\t\t\t\t\t";
                 } elseif ($this->isOracle) {
                     $sql = "\n\t\t\t\t\t\t\tINSERT INTO {$tableNameSingleUf} (VALUE_ID, " . implode(', ', $fieldArray) . ")\n\t\t\t\t\t\t\tSELECT {$newId}, " . implode(', ', $valueArray) . " FROM dual\n\t\t\t\t\t\t\tWHERE NOT EXISTS(SELECT 'x' FROM {$tableNameSingleUf} WHERE VALUE_ID = {$newId})\n\t\t\t\t\t\t";
                 } elseif ($this->isMssql) {
                     $sql = "\n\t\t\t\t\t\t\tINSERT INTO {$tableNameSingleUf} (VALUE_ID, " . implode(', ', $fieldArray) . ")\n\t\t\t\t\t\t\tSELECT * FROM (SELECT {$newId}, " . implode(', ', $valueArray) . ") AS tmp\n\t\t\t\t\t\t\tWHERE NOT EXISTS(SELECT 'x' FROM {$tableNameSingleUf} WHERE VALUE_ID = {$newId})\n\t\t\t\t\t\t";
                 }
                 $this->connection->queryExecute($sql);
             }
         }
     }
 }
Exemple #5
0
 public static function installDiskUserFields()
 {
     global $APPLICATION;
     $errors = null;
     if (!IsModuleInstalled('disk')) {
         return $errors;
     }
     $uf = new CUserTypeEntity();
     $rsData = CUserTypeEntity::getList(array("ID" => "ASC"), array("ENTITY_ID" => 'TASKS_TASK', "FIELD_NAME" => 'UF_TASK_WEBDAV_FILES'));
     if (!($rsData && ($arRes = $rsData->Fetch()))) {
         $intID = $uf->add(array('ENTITY_ID' => 'TASKS_TASK', 'FIELD_NAME' => 'UF_TASK_WEBDAV_FILES', 'USER_TYPE_ID' => 'disk_file', 'XML_ID' => 'TASK_WEBDAV_FILES', 'MULTIPLE' => 'Y', 'MANDATORY' => null, 'SHOW_FILTER' => 'N', 'SHOW_IN_LIST' => null, 'EDIT_IN_LIST' => null, 'IS_SEARCHABLE' => 'Y', 'EDIT_FORM_LABEL' => array('en' => 'Load files', 'ru' => 'Load files', 'de' => 'Load files')), false);
         if (false == $intID && ($strEx = $APPLICATION->getException())) {
             $errors[] = $strEx->getString();
         }
     }
     return $errors;
 }
Exemple #6
-1
	public static function installDiskUserFields()
	{
		global $APPLICATION;
		$errors = null;

		if(!IsModuleInstalled('disk'))
		{
			return;
		}

		$props = array(
			array(
				"ENTITY_ID" => "BLOG_POST",
				"FIELD_NAME" => "UF_BLOG_POST_FILE",
				"USER_TYPE_ID" => "disk_file"
			),
			array(
				"ENTITY_ID" => "BLOG_COMMENT",
				"FIELD_NAME" => "UF_BLOG_COMMENT_FILE",
				"USER_TYPE_ID" => "disk_file"
			),
			array(
				"ENTITY_ID" => "BLOG_COMMENT",
				"FIELD_NAME" => "UF_BLOG_COMMENT_FH",
				"USER_TYPE_ID" => "disk_version"
			),
		);
		$uf = new CUserTypeEntity;
		foreach ($props as $prop)
		{
			$rsData = CUserTypeEntity::getList(array("ID" => "ASC"), array("ENTITY_ID" => $prop["ENTITY_ID"], "FIELD_NAME" => $prop["FIELD_NAME"]));
			if (!($rsData && ($arRes = $rsData->Fetch())))
			{
				$intID = $uf->add(array(
					"ENTITY_ID" => $prop["ENTITY_ID"],
					"FIELD_NAME" => $prop["FIELD_NAME"],
					"XML_ID" => $prop["FIELD_NAME"],
					"USER_TYPE_ID" => $prop["USER_TYPE_ID"],
					"SORT" => 100,
					"MULTIPLE" => ($prop["USER_TYPE_ID"] == "disk_version" ? "N" : "Y"),
					"MANDATORY" => "N",
					"SHOW_FILTER" => "N",
					"SHOW_IN_LIST" => "N",
					"EDIT_IN_LIST" => "Y",
					"IS_SEARCHABLE" => "N"
				), false);

				if (false == $intID && ($strEx = $APPLICATION->getException()))
				{
					$errors[] = $strEx->getString();
				}
			}
		}

		return $errors;
	}