本文整理汇总了PHP中CIBlockProperty::Add方法的典型用法代码示例。如果您正苦于以下问题:PHP CIBlockProperty::Add方法的具体用法?PHP CIBlockProperty::Add怎么用?PHP CIBlockProperty::Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CIBlockProperty
的用法示例。
在下文中一共展示了CIBlockProperty::Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createProperty
/**
* @param string $name
* @param string $code
* @param array $arFields
*
* @throws MigrationException
*/
protected function createProperty($name, $code, array $arFields = array())
{
$arFields['NAME'] = $name;
$arFields['CODE'] = $code;
$arFields['IBLOCK_ID'] = $this->iBlockId;
$arFields['VERSION'] = $this->storageType;
if (!empty($code) && $this->isIBlockPropertyExists($code)) {
throw new MigrationException(sprintf('IBlock property with code "%s" already exists', $code));
}
if (!$this->iBlockPropertyGateway->Add($arFields)) {
throw new MigrationException($this->iBlockPropertyGateway->LAST_ERROR);
}
}
示例2: Execute
public function Execute()
{
if (!CModule::IncludeModule("forum")) {
return CBPActivityExecutionStatus::Closed;
}
if (!CModule::IncludeModule("iblock")) {
return CBPActivityExecutionStatus::Closed;
}
$forumId = intval($this->ForumId);
if ($forumId <= 0) {
return CBPActivityExecutionStatus::Closed;
}
$rootActivity = $this->GetRootActivity();
$documentId = $rootActivity->GetDocumentId();
$iblockId = $this->IBlockId;
$dbResult = CIBlockElement::GetProperty($iblockId, $documentId[2], false, false, array("CODE" => "FORUM_TOPIC_ID"));
$arResult = $dbResult->Fetch();
if (!$arResult) {
$obProperty = new CIBlockProperty();
$obProperty->Add(array("IBLOCK_ID" => $iblockId, "ACTIVE" => "Y", "PROPERTY_TYPE" => "N", "MULTIPLE" => "N", "NAME" => "Forum topic", "CODE" => "FORUM_TOPIC_ID"));
$obProperty->Add(array("IBLOCK_ID" => $iblockId, "ACTIVE" => "Y", "PROPERTY_TYPE" => "N", "MULTIPLE" => "N", "NAME" => "Forum message count", "CODE" => "FORUM_MESSAGE_CNT"));
$dbResult = CIBlockElement::GetProperty($iblockId, $documentId[2], false, false, array("CODE" => "FORUM_TOPIC_ID"));
$arResult = $dbResult->Fetch();
}
$forumTopicId = intval($arResult["VALUE"]);
$arForumUserTmp = $this->ForumUser;
$arForumUser = CBPHelper::ExtractUsers($arForumUserTmp, $documentId, true);
$forumUserId = 1;
$forumUserName = "Admin";
if ($arForumUser != null) {
$forumUserId = $arForumUser;
$dbResult = CUser::GetByID($forumUserId);
if ($arResult = $dbResult->Fetch()) {
$forumUserName = CUser::FormatName(COption::GetOptionString("bizproc", "name_template", CSite::GetNameFormat(false), SITE_ID), $arResult, true);
}
}
$newTopic = "N";
if ($forumTopicId <= 0) {
$documentService = $this->workflow->GetService("DocumentService");
$document = $documentService->GetDocument($documentId);
$newTopic = "Y";
$arFields = array("TITLE" => $document["NAME"], "FORUM_ID" => $forumId, "USER_START_ID" => $forumUserId, "USER_START_NAME" => $forumUserName, "LAST_POSTER_NAME" => $forumUserName, "APPROVED" => "Y");
$forumTopicId = CForumTopic::Add($arFields);
CIBlockElement::SetPropertyValues($documentId[2], $iblockId, $forumTopicId, "FORUM_TOPIC_ID");
}
$arFields = array("POST_MESSAGE" => $this->ForumPostMessage, "AUTHOR_ID" => $forumUserId, "AUTHOR_NAME" => $forumUserName, "FORUM_ID" => $forumId, "TOPIC_ID" => $forumTopicId, "APPROVED" => "Y", "NEW_TOPIC" => $newTopic, "PARAM2" => $documentId[2]);
$forumMessageId = CForumMessage::Add($arFields, false, array("SKIP_INDEXING" => "Y", "SKIP_STATISTIC" => "N"));
return CBPActivityExecutionStatus::Closed;
}
示例3: array
function __IRM_InitReservation($iblockId)
{
$arResult = array();
$arResult["ALLOWED_FIELDS"] = array("ID" => array("NAME" => GetMessage("INAF_F_ID"), "ORDERABLE" => true, "FILTERABLE" => true, "TYPE" => "int", "IS_FIELD" => true), "NAME" => array("NAME" => GetMessage("INAF_F_NAME"), "ORDERABLE" => true, "FILTERABLE" => true, "TYPE" => "string", "IS_FIELD" => true), "DESCRIPTION" => array("NAME" => GetMessage("INAF_F_DESCRIPTION"), "ORDERABLE" => false, "FILTERABLE" => false, "TYPE" => "text", "IS_FIELD" => true), "UF_FLOOR" => array("NAME" => GetMessage("INAF_F_FLOOR"), "ORDERABLE" => true, "FILTERABLE" => true, "TYPE" => "integer", "IS_FIELD" => false), "UF_PLACE" => array("NAME" => GetMessage("INAF_F_PLACE"), "ORDERABLE" => true, "FILTERABLE" => true, "TYPE" => "integer", "IS_FIELD" => false), "UF_PHONE" => array("NAME" => GetMessage("INAF_F_PHONE"), "ORDERABLE" => false, "FILTERABLE" => false, "TYPE" => "string", "IS_FIELD" => false));
$arUserFields = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFields("IBLOCK_" . $iblockId . "_SECTION", 0, LANGUAGE_ID);
$arKeys = Array_Keys($arResult["ALLOWED_FIELDS"]);
foreach ($arKeys as $key) {
if (!$arResult["ALLOWED_FIELDS"][$key]["IS_FIELD"]) {
if (!Array_Key_Exists($key, $arUserFields)) {
$arFields = array("ENTITY_ID" => "IBLOCK_" . $iblockId . "_SECTION", "FIELD_NAME" => $key, "USER_TYPE_ID" => $arResult["ALLOWED_FIELDS"][$key]["TYPE"]);
$obUserField = new CUserTypeEntity();
$obUserField->Add($arFields);
}
}
}
$arResult["ALLOWED_ITEM_PROPERTIES"] = array("UF_PERSONS" => array("NAME" => GetMessage("INTASK_C29_UF_PERSONS"), "ACTIVE" => "Y", "SORT" => 300, "CODE" => "UF_PERSONS", "PROPERTY_TYPE" => "N", "USER_TYPE" => false, "ROW_COUNT" => 1, "COL_COUNT" => 5, "LINK_IBLOCK_ID" => 0, "WITH_DESCRIPTION" => "N", "FILTRABLE" => "Y", "SEARCHABLE" => "Y", "MULTIPLE" => "N", "MULTIPLE_CNT" => 5, "IS_REQUIRED" => "N", "FILE_TYPE" => "jpg, gif, bmp, png, jpeg", "LIST_TYPE" => "L", "IBLOCK_ID" => $iblockId), "UF_RES_TYPE" => array("NAME" => GetMessage("INTASK_C29_UF_RES_TYPE"), "ACTIVE" => "Y", "SORT" => 200, "CODE" => "UF_RES_TYPE", "PROPERTY_TYPE" => "L", "USER_TYPE" => false, "ROW_COUNT" => 1, "COL_COUNT" => 30, "LINK_IBLOCK_ID" => 0, "WITH_DESCRIPTION" => "N", "FILTRABLE" => "Y", "SEARCHABLE" => "Y", "MULTIPLE" => "N", "MULTIPLE_CNT" => 5, "IS_REQUIRED" => "Y", "FILE_TYPE" => "jpg, gif, bmp, png, jpeg", "LIST_TYPE" => "L", "IBLOCK_ID" => $iblockId, "VALUES" => array(array("VALUE" => GetMessage("INTASK_C29_UF_RES_TYPEA"), "DEF" => "Y", "SORT" => 100, "XML_ID" => "A"), array("VALUE" => GetMessage("INTASK_C29_UF_RES_TYPEB"), "DEF" => "N", "SORT" => 200, "XML_ID" => "B"), array("VALUE" => GetMessage("INTASK_C29_UF_RES_TYPEC"), "DEF" => "N", "SORT" => 200, "XML_ID" => "C"), array("VALUE" => GetMessage("INTASK_C29_UF_RES_TYPED"), "DEF" => "N", "SORT" => 300, "XML_ID" => "D"))), "UF_PREPARE_ROOM" => array("NAME" => GetMessage("INTASK_C29_UF_PREPARE_ROOM"), "ACTIVE" => "Y", "SORT" => 500, "CODE" => "UF_PREPARE_ROOM", "PROPERTY_TYPE" => "S", "USER_TYPE" => false, "DEFAULT_VALUE" => "Y", "ROW_COUNT" => 1, "COL_COUNT" => 30, "LINK_IBLOCK_ID" => 0, "WITH_DESCRIPTION" => "N", "FILTRABLE" => "N", "SEARCHABLE" => "N", "MULTIPLE" => "N", "MULTIPLE_CNT" => 5, "IS_REQUIRED" => "N", "FILE_TYPE" => "jpg, gif, bmp, png, jpeg", "LIST_TYPE" => "L", "IBLOCK_ID" => $iblockId), "PERIOD_TYPE" => array("NAME" => GetMessage("INTASK_C29_PERIOD_TYPE"), "ACTIVE" => "Y", "SORT" => 500, "CODE" => "PERIOD_TYPE", "PROPERTY_TYPE" => "S", "USER_TYPE" => false, "DEFAULT_VALUE" => "NONE", "ROW_COUNT" => 1, "COL_COUNT" => 30, "LINK_IBLOCK_ID" => 0, "WITH_DESCRIPTION" => "N", "FILTRABLE" => "N", "SEARCHABLE" => "N", "MULTIPLE" => "N", "MULTIPLE_CNT" => 5, "IS_REQUIRED" => "N", "FILE_TYPE" => "jpg, gif, bmp, png, jpeg", "LIST_TYPE" => "L", "IBLOCK_ID" => $iblockId), "PERIOD_COUNT" => array("NAME" => GetMessage("INTASK_C29_PERIOD_COUNT"), "ACTIVE" => "Y", "SORT" => 500, "CODE" => "PERIOD_COUNT", "PROPERTY_TYPE" => "N", "USER_TYPE" => false, "DEFAULT_VALUE" => "", "ROW_COUNT" => 1, "COL_COUNT" => 30, "LINK_IBLOCK_ID" => 0, "WITH_DESCRIPTION" => "N", "FILTRABLE" => "N", "SEARCHABLE" => "N", "MULTIPLE" => "N", "MULTIPLE_CNT" => 5, "IS_REQUIRED" => "N", "FILE_TYPE" => "jpg, gif, bmp, png, jpeg", "LIST_TYPE" => "L", "IBLOCK_ID" => $iblockId), "EVENT_LENGTH" => array("NAME" => GetMessage("INTASK_C29_EVENT_LENGTH"), "ACTIVE" => "Y", "SORT" => 500, "CODE" => "EVENT_LENGTH", "PROPERTY_TYPE" => "N", "USER_TYPE" => false, "DEFAULT_VALUE" => "", "ROW_COUNT" => 1, "COL_COUNT" => 30, "LINK_IBLOCK_ID" => 0, "WITH_DESCRIPTION" => "N", "FILTRABLE" => "N", "SEARCHABLE" => "N", "MULTIPLE" => "N", "MULTIPLE_CNT" => 5, "IS_REQUIRED" => "N", "FILE_TYPE" => "jpg, gif, bmp, png, jpeg", "LIST_TYPE" => "L", "IBLOCK_ID" => $iblockId), "PERIOD_ADDITIONAL" => array("NAME" => GetMessage("INTASK_C29_PERIOD_ADDITIONAL"), "ACTIVE" => "Y", "SORT" => 500, "CODE" => "PERIOD_ADDITIONAL", "PROPERTY_TYPE" => "S", "USER_TYPE" => false, "DEFAULT_VALUE" => "", "ROW_COUNT" => 1, "COL_COUNT" => 30, "LINK_IBLOCK_ID" => 0, "WITH_DESCRIPTION" => "N", "FILTRABLE" => "N", "SEARCHABLE" => "N", "MULTIPLE" => "N", "MULTIPLE_CNT" => 5, "IS_REQUIRED" => "N", "FILE_TYPE" => "jpg, gif, bmp, png, jpeg", "LIST_TYPE" => "L", "IBLOCK_ID" => $iblockId));
$dbIBlockProps = CIBlock::GetProperties($iblockId);
while ($arIBlockProps = $dbIBlockProps->Fetch()) {
if (Array_Key_Exists($arIBlockProps["CODE"], $arResult["ALLOWED_ITEM_PROPERTIES"])) {
$arResult["ALLOWED_ITEM_PROPERTIES"][$arIBlockProps["CODE"]]["ID"] = $arIBlockProps["ID"];
}
}
$keys = Array_Keys($arResult["ALLOWED_ITEM_PROPERTIES"]);
foreach ($keys as $key) {
if (IntVal($arResult["ALLOWED_ITEM_PROPERTIES"][$key]["ID"]) <= 0) {
$ibp = new CIBlockProperty();
$arResult["ALLOWED_ITEM_PROPERTIES"][$key]["ID"] = $ibp->Add($arResult["ALLOWED_ITEM_PROPERTIES"][$key]);
}
}
return $arResult;
}
示例4: testAdd
public function testAdd()
{
$this->_injectDutyCollector();
$ibType = \CIBlockType::GetList()->Fetch();
$ib = new \CIBlock();
$ibId = $ib->Add(array('IBLOCK_TYPE_ID' => $ibType['ID'], 'NAME' => 'New Iblock', 'SITE_ID' => 's1'));
$this->assertNotEmpty($ibId, $this->errorMessage('not create iblock id', array(':lastError' => $ib->LAST_ERROR)));
$prop = new \CIBlockProperty();
$propId = $prop->Add(array('IBLOCK_ID' => $ibId, 'CODE' => 'propCode', 'NAME' => 'Property NAME'));
$this->assertNotEmpty($propId, $this->errorMessage('not create property iblock id', array(':lastError' => $ib->LAST_ERROR)));
$sec = new \CIBlockSection();
$secId = $sec->Add(array('IBLOCK_ID' => $ibId, 'NAME' => 'Iblock Section'));
$this->assertNotEmpty($secId, $this->errorMessage('not create section iblock id', array(':lastError' => $ib->LAST_ERROR)));
// ¬ итоге должны получитс¤
// данные по добавлению »Ѕ
$this->assertNotEmpty($this->_getCollectorFixes(AddProcess::className(), IblockHandler::className()));
// данные по добавлению свойства
$this->assertNotEmpty($this->_getCollectorFixes(AddProcess::className(), IblockPropertyHandler::className()));
// данные по добавлению секции
$this->assertNotEmpty($this->_getCollectorFixes(AddProcess::className(), IblockSectionHandler::className()));
$refFixes = $this->_getCollectorFixes('reference');
// фиксаци¤ изменений
Module::getInstance()->commitDutyChanges();
// добавлены записи журнала обновлений (в базу)
/** @var $logRecords AppliedChangesLogModel[] */
$logRecords = AppliedChangesLogModel::find(array('order' => array('id' => 'desc'), 'limit' => 10));
$this->assertTrue(count($logRecords) > 3);
$iterationsCount = 0;
foreach ($logRecords as $logRecord) {
if ($logRecord->processName == Module::SPECIAL_PROCESS_FIX_REFERENCE) {
continue;
}
if ($logRecord->processName != AddProcess::className()) {
$this->throwError($this->errorMessage('last log records need been update process'), $logRecord->processName);
}
if (++$iterationsCount > 3) {
break;
}
$data = $logRecord->updateData;
switch ($logRecord->subjectName) {
case IblockHandler::className():
(!$data['iblock'] || $data['iblock']['ID'] != $ibId) && $this->throwError($this->errorMessage('iblock not registered after update', array(':actual' => $data['iblock']['ID'], ':need' => $ibId)));
break;
case IblockPropertyHandler::className():
$data['ID'] != $propId && $this->throwError($this->errorMessage('property iblock not registered after update', array(':original' => $propId, ':actual' => $data['ID'])));
break;
case IblockSectionHandler::className():
$data['ID'] != $secId && $this->throwError($this->errorMessage('section iblock not registered after update', array(':original' => $secId, ':actual' => $data['ID'])));
break;
}
}
// добавлены три вида ссылок в фиксаци¤х
$this->assertEquals(3, count($refFixes), $this->errorMessage('links expected count', array(':count' => 3)));
$this->_iblockId = $ibId;
$this->_propertyId = $propId;
$this->_sectionId = $secId;
}
示例5: internationalize
/**
* @inheritdoc
*
* @throws PropertyAlreadyExistException
*/
public function internationalize($propCodePublicId, $propCodeLang, $defaultLang)
{
$isExistPropPublicId = $this->checkExistProperty($propCodePublicId, PublicIdProperty::USER_TYPE);
$isExistPropLang = $this->checkExistProperty($propCodeLang, LangProperty::USER_TYPE);
$propertyModel = new \CIBlockProperty();
if (!$isExistPropPublicId) {
$addResult = $propertyModel->Add(['NAME' => Loc::getMessage('NOTAMEDIA_I18N_ELEMENT_CONVERTER_PROP_PUBLIC_ID'), 'ACTIVE' => 'Y', 'CODE' => $propCodePublicId, 'PROPERTY_TYPE' => 'S', 'USER_TYPE' => PublicIdProperty::USER_TYPE, 'FILTRABLE' => 'Y', 'IBLOCK_ID' => $this->getIblockId()]);
if (!$addResult) {
throw new InternationalizeException([$propertyModel->LAST_ERROR]);
}
}
if (!$isExistPropLang) {
$addResult = $propertyModel->Add(['NAME' => Loc::getMessage('NOTAMEDIA_I18N_ELEMENT_CONVERTER_PROP_LANG'), 'ACTIVE' => 'Y', 'CODE' => $propCodeLang, 'PROPERTY_TYPE' => 'S', 'USER_TYPE' => LangProperty::USER_TYPE, 'FILTRABLE' => 'Y', 'IS_REQUIRED' => 'Y', 'IBLOCK_ID' => $this->getIblockId()]);
if (!$addResult) {
throw new InternationalizeException([$propertyModel->LAST_ERROR]);
}
}
parent::internationalize($propCodePublicId, $propCodeLang, $defaultLang);
}
示例6: Add
/**
* Add
* @param $arFields
* @return bool
* @throws \Exception
*/
public static function Add($arFields)
{
$iblock = new \CIBlock();
if (isset($arFields['SORT'])) {
if (!is_int($arFields['SORT'])) {
if (intval($arFields['SORT'])) {
$arFields['SORT'] = intval($arFields['SORT']);
} else {
$arFields['SORT'] = 500;
}
}
} else {
$arFields['SORT'] = 500;
}
# default
$arDefaultValues = array('MULTIPLE' => false, 'IS_REQUIRED' => false, 'ACTIVE' => true, 'PROPERTY_TYPE' => 'S', 'USER_TYPE' => false, 'FILE_TYPE' => '', 'LIST_TYPE' => 'L', 'ROW_COUNT' => 1, 'COL_COUNT' => 30, 'LINK_IBLOCK_ID' => null, 'DEFAULT_VALUE' => null, 'WITH_DESCRIPTION' => 'N', 'SEARCHABLE' => 'N', 'FILTRABLE' => 'N', 'MULTIPLE_CNT' => 5, 'HINT' => '', 'SECTION_PROPERTY' => 'Y', 'SMART_FILTER' => 'N', 'USER_TYPE_SETTINGS' => array(), 'VALUES' => array());
if ($arFields['IBLOCK_CODE']) {
unset($arFields['IBLOCK_ID']);
$rsIBlock = $iblock->GetList(array(), array('CODE' => $arFields['IBLOCK_CODE'], 'CHECK_PERMISSIONS' => 'N'));
if ($arIBlock = $rsIBlock->Fetch()) {
$arFields['IBLOCK_ID'] = $arIBlock['ID'];
} else {
throw new BimException(__METHOD__ . ' Not found iblock with code ' . $arFields['IBLOCK_CODE']);
}
}
if (!strlen($arFields['CODE'])) {
throw new BimException(__METHOD__ . ' Not found property code');
}
$iblockPropDbRes = \CIBlockProperty::GetList(array(), array('IBLOCK_ID' => $arFields['IBLOCK_ID'], 'CODE' => $arFields['CODE']));
if ($iblockPropDbRes !== false && $iblockPropDbRes->SelectedRowsCount()) {
throw new BimException(__METHOD__ . 'Property with code = "' . $arFields['CODE'] . '" ');
}
if ($arFields['LINK_IBLOCK_CODE']) {
unset($arFields['LINK_IBLOCK_ID']);
$rsIBlock = $iblock->GetList(array(), array('CODE' => $arFields['LINK_IBLOCK_CODE'], 'CHECK_PERMISSIONS' => 'N'));
if ($arIBlock = $rsIBlock->Fetch()) {
$arFields['LINK_IBLOCK_ID'] = $arIBlock['ID'];
}
}
foreach ($arDefaultValues as $DefaultName => $DefaultValue) {
if (!isset($arFields[$DefaultName]) || empty($arFields[$DefaultName])) {
$arFields[$DefaultName] = $DefaultValue;
}
}
$objCIBlockProperty = new \CIBlockProperty();
unset($arFields['ID']);
$iId = $objCIBlockProperty->Add($arFields);
if ($iId) {
return $iId;
} else {
throw new BimException(__METHOD__ . ' ' . $objCIBlockProperty->LAST_ERROR);
}
}
示例7: onBeforeUpload
function onBeforeUpload($Params)
{
CModule::IncludeModule("iblock");
$_SESSION['arUploadedPhotos'] = array();
$arParams = $Params['arParams'];
$savedData = CImageUploader::GetSavedData();
$savedData['UPLOADING_START'] = "Y";
CImageUploader::SetSavedData($savedData);
if ($savedData["SECTION_ID"] <= 0) {
$arParams["SECTION_ID"] = GetAlbumId(array('id' => $Params['packageFields']['photo_album_id'], 'name' => $Params['packageFields']['new_album_name'], 'arParams' => $arParams, '~arResult' => $Params['~arResult']));
$savedData = CImageUploader::GetSavedData();
$savedData["SECTION_ID"] = $arParams["SECTION_ID"];
} else {
$arParams["SECTION_ID"] = $savedData["SECTION_ID"];
}
// Check and create properties
if (count($savedData['arError']) == 0) {
$arPropertiesNeed = array();
// Array of properties needed to create
foreach ($arParams['converters'] as $key => $val) {
if ($val['code'] == "real_picture" || $val['code'] == "thumbnail") {
continue;
}
$db_res = CIBlock::GetProperties($arParams["IBLOCK_ID"], array(), array("CODE" => $val['code']));
if (!($db_res && ($res = $db_res->Fetch()))) {
$arPropertiesNeed[] = $val['code'];
}
}
if (count($arPropertiesNeed) > 0) {
$obProperty = new CIBlockProperty();
foreach ($arPropertiesNeed as $key) {
$res = $obProperty->Add(array("IBLOCK_ID" => $arParams["IBLOCK_ID"], "ACTIVE" => "Y", "PROPERTY_TYPE" => "F", "MULTIPLE" => "N", "NAME" => strLen(GetMessage("P_" . strToUpper($key))) > 0 ? GetMessage("P_" . strToUpper($key)) : strToUpper($key), "CODE" => strToUpper($key), "FILE_TYPE" => "jpg, gif, bmp, png, jpeg"));
}
}
// Check Public property
$arPropertiesNeed = array();
foreach (array("PUBLIC_ELEMENT", "APPROVE_ELEMENT") as $key) {
$db_res = CIBlock::GetProperties($arParams["IBLOCK_ID"], array(), array("CODE" => $key));
if (!$db_res || !($res = $db_res->Fetch())) {
$arPropertiesNeed[] = $key;
}
}
if (count($arPropertiesNeed) > 0) {
$obProperty = new CIBlockProperty();
foreach ($arPropertiesNeed as $key) {
$res = $obProperty->Add(array("IBLOCK_ID" => $arParams["IBLOCK_ID"], "ACTIVE" => "Y", "PROPERTY_TYPE" => "S", "MULTIPLE" => "N", "NAME" => strLen(GetMessage("P_" . $key)) > 0 ? GetMessage("P_" . $key) : $key, "DEFAULT_VALUE" => "N", "CODE" => $key));
}
}
}
CImageUploader::SetSavedData($savedData);
return true;
}
示例8: addLinkField
public static function addLinkField($iblock_id) {
$iblock_property = new CIBlockProperty;
return $iblock_property->Add(
array(
'NAME' => 'Ссылка',
'ACTIVE' => 'Y',
'SORT' => 500,
'CODE' => 'LINK',
'PROPERTY_TYPE' => 'S',
'IBLOCK_ID' => $iblock_id,
)
);
}
示例9: addPropertyIfNotExists
public function addPropertyIfNotExists($iblockId, $fields)
{
$this->checkRequiredKeys(__METHOD__, $fields, array('CODE'));
$propId = $this->getPropertyId($iblockId, $fields['CODE']);
if ($propId) {
return $propId;
}
$default = array('IBLOCK_ID' => $iblockId, 'NAME' => '', 'ACTIVE' => 'Y', 'SORT' => '500', 'CODE' => '', 'PROPERTY_TYPE' => 'S', 'ROW_COUNT' => '1', 'COL_COUNT' => '30', 'LIST_TYPE' => 'L', 'MULTIPLE' => 'N', 'USER_TYPE' => '', 'IS_REQUIRED' => 'N', 'FILTRABLE' => 'Y', 'LINK_IBLOCK_ID' => 0);
$fields = array_merge($default, $fields);
if (isset($fields['VALUES'])) {
$fields['PROPERTY_TYPE'] = 'L';
}
$ib = new \CIBlockProperty();
$propId = $ib->Add($fields);
if ($propId) {
return $propId;
}
$this->throwException(__METHOD__, $ib->LAST_ERROR);
}
示例10: array
$db_res = CIBlockSection::GetList(array(), array("IBLOCK_ID" => $arSection["IBLOCK_ID"], "SECTION_ID" => 0, "!LEFT_MARGIN" => $arSection["LEFT_MARGIN"], "!RIGHT_MARGIN" => $arSection["RIGHT_MARGIN"], "!ID" => $arSection["ID"]), false, array("ID", "CODE", "RIGHT_MARGIN", "LEFT_MARGIN"));
if ($db_res) {
$arGallery = $db_res->Fetch();
}
}
}
$arResult["ELEMENT"]["~DETAIL_PAGE_URL"] = CComponentEngine::MakePathFromTemplate($arParams["~DETAIL_URL"], array("USER_ALIAS" => $arGallery["CODE"], "SECTION_ID" => $arResult["ELEMENT"]["IBLOCK_SECTION_ID"], "ELEMENT_ID" => $arResult["ELEMENT"]["ID"]));
$arResult["ELEMENT"]["DETAIL_PAGE_URL"] = htmlspecialcharsbx($arResult["ELEMENT"]["~DETAIL_PAGE_URL"]);
$obProperty = false;
$iCommentID = 0;
/************** BLOG *****************************************************/
$obProperty = new CIBlockProperty();
if (is_set($arResult["ELEMENT"]["PROPERTIES"], "BLOG_POST_ID")) {
$iCommentID = intVal($arResult["ELEMENT"]["PROPERTIES"]["BLOG_POST_ID"]["VALUE"]);
} else {
$res = $obProperty->Add(array("IBLOCK_ID" => $arParams["IBLOCK_ID"], "ACTIVE" => "Y", "PROPERTY_TYPE" => "N", "MULTIPLE" => "N", "NAME" => strLen(GetMessage("P_BLOG_POST_ID")) <= 0 ? "BLOG_POST_ID" : GetMessage("P_BLOG_POST_ID"), "CODE" => "BLOG_POST_ID"));
}
if (!is_set($arResult["ELEMENT"], "PROPERTY_BLOG_COMMENTS_CNT_VALUE")) {
$res = $obProperty->Add(array("IBLOCK_ID" => $arParams["IBLOCK_ID"], "ACTIVE" => "Y", "PROPERTY_TYPE" => "N", "MULTIPLE" => "N", "NAME" => strLen(GetMessage("P_BLOG_COMMENTS_CNT")) <= 0 ? "P_BLOG_COMMENTS_CNT" : GetMessage("P_BLOG_COMMENTS_CNT"), "CODE" => "BLOG_COMMENTS_CNT"));
}
if ($iCommentID > 0) {
$arPost = CBlogPost::GetByID($iCommentID);
if (!$arPost) {
$iCommentID = 0;
} elseif (intVal($arPost["NUM_COMMENTS"]) > 0 && $arPost["NUM_COMMENTS"] != $arResult["ELEMENT"]["PROPERTIES"]["BLOG_COMMENTS_CNT"]["VALUE"]) {
CIBlockElement::SetPropertyValues($arParams["ELEMENT_ID"], $arParams["IBLOCK_ID"], intVal($arPost["NUM_COMMENTS"]), "BLOG_COMMENTS_CNT");
}
}
if (!$iCommentID && isset($_REQUEST["parentId"])) {
$arCategory = array();
$arBlog = CBlog::GetByUrl($arParams["BLOG_URL"]);
示例11: AddDocumentField
public function AddDocumentField($documentType, $arFields)
{
$iblockId = intval(substr($documentType, strlen("type_")));
if ($iblockId <= 0)
throw new CBPArgumentOutOfRangeException("documentType", $documentType);
if (substr($arFields["code"], 0, strlen("PROPERTY_")) == "PROPERTY_")
$arFields["code"] = substr($arFields["code"], strlen("PROPERTY_"));
$arFieldsTmp = array(
"NAME" => $arFields["name"],
"ACTIVE" => "Y",
"SORT" => 150,
"CODE" => $arFields["code"],
"MULTIPLE" => $arFields["multiple"],
"IS_REQUIRED" => $arFields["required"],
"IBLOCK_ID" => $iblockId,
"FILTRABLE" => "Y",
);
if (strpos("0123456789", substr($arFieldsTmp["CODE"], 0, 1))!==false)
unset($arFieldsTmp["CODE"]);
if (array_key_exists("additional_type_info", $arFields))
$arFieldsTmp["LINK_IBLOCK_ID"] = intval($arFields["additional_type_info"]);
if (strstr($arFields["type"], ":") !== false)
{
list($arFieldsTmp["PROPERTY_TYPE"], $arFieldsTmp["USER_TYPE"]) = explode(":", $arFields["type"], 2);
if ($arFields["type"] == "E:EList")
$arFieldsTmp["LINK_IBLOCK_ID"] = $arFields["options"];
}
else
{
$arFieldsTmp["PROPERTY_TYPE"] = $arFields["type"];
$arFieldsTmp["USER_TYPE"] = false;
}
if ($arFieldsTmp["PROPERTY_TYPE"] == "T")
{
$arFieldsTmp["PROPERTY_TYPE"] = "S";
$arFieldsTmp["ROW_COUNT"] = 5;
}
if ($arFields["type"] == "L")
{
if (is_array($arFields["options"]))
{
$i = 10;
foreach ($arFields["options"] as $k => $v)
{
$arFieldsTmp["VALUES"][] = array("XML_ID" => $k, "VALUE" => $v, "DEF" => "N", "SORT" => $i);
$i = $i + 10;
}
}
elseif (is_string($arFields["options"]) && (strlen($arFields["options"]) > 0))
{
$a = explode("\n", $arFields["options"]);
$i = 10;
foreach ($a as $v)
{
$v = trim(trim($v), "\r\n");
$v1 = $v2 = $v;
if (substr($v, 0, 1) == "[" && strpos($v, "]") !== false)
{
$v1 = substr($v, 1, strpos($v, "]") - 1);
$v2 = trim(substr($v, strpos($v, "]") + 1));
}
$arFieldsTmp["VALUES"][] = array("XML_ID" => $v1, "VALUE" => $v2, "DEF" => "N", "SORT" => $i);
$i = $i + 10;
}
}
}
$ibp = new CIBlockProperty;
$propId = $ibp->Add($arFieldsTmp);
if (intval($propId) <= 0)
throw new Exception($ibp->LAST_ERROR);
return "PROPERTY_".$arFields["code"];
}
示例12: ImportProperties
//.........这里部分代码省略.........
if ($arType["VALUE"] == $this->mess["IBLOCK_XML2_TYPE_LIST"]) {
$arProperty["PROPERTY_TYPE"] = "L";
} elseif ($arType["VALUE"] == $this->mess["IBLOCK_XML2_TYPE_NUMBER"]) {
$arProperty["PROPERTY_TYPE"] = "N";
}
} elseif ($arType["NAME"] == $this->mess["IBLOCK_XML2_CHOICE_VALUES"]) {
$XML_ENUM_PARENT = $arType["ID"];
}
}
}
} elseif ($arP["NAME"] == $this->mess["IBLOCK_XML2_BX_USER_TYPE_SETTINGS"]) {
$arProperty["USER_TYPE_SETTINGS"] = unserialize($arP["VALUE"]);
} elseif ($arP["NAME"] == $this->mess["IBLOCK_XML2_EXTERNAL"]) {
$isExternal = $arP["VALUE"] == "true" || intval($arP["VALUE"]) ? true : false;
if ($isExternal) {
$arProperty["PROPERTY_TYPE"] = "S";
$arProperty["USER_TYPE"] = "directory";
}
}
}
if (array_key_exists($arProperty["XML_ID"], $arElementFields)) {
continue;
}
// Skip properties with no choice values
// http://jabber.bx/view.php?id=30476
$arEnumXmlNodes = array();
if ($XML_ENUM_PARENT) {
$rsE = $this->_xml_file->GetList(array("ID" => "asc"), array("PARENT_ID" => $XML_ENUM_PARENT));
while ($arE = $rsE->Fetch()) {
if (isset($arE["VALUE_CLOB"])) {
$arE["VALUE"] = $arE["VALUE_CLOB"];
}
$arEnumXmlNodes[] = $arE;
}
if (empty($arEnumXmlNodes)) {
continue;
}
}
if ($arProperty["SERIALIZED"] == "Y") {
$arProperty["DEFAULT_VALUE"] = unserialize($arProperty["DEFAULT_VALUE"]);
}
$rsProperty = $obProperty->GetList(array(), array("IBLOCK_ID" => $IBLOCK_ID, "XML_ID" => $arProperty["XML_ID"]));
if ($arDBProperty = $rsProperty->Fetch()) {
$bChanged = false;
foreach ($arProperty as $key => $value) {
if ($arDBProperty[$key] !== $value) {
$bChanged = true;
break;
}
}
if (!$bChanged) {
$arProperty["ID"] = $arDBProperty["ID"];
} elseif ($obProperty->Update($arDBProperty["ID"], $arProperty)) {
$arProperty["ID"] = $arDBProperty["ID"];
} else {
return $obProperty->LAST_ERROR;
}
} else {
$arProperty["IBLOCK_ID"] = $IBLOCK_ID;
$arProperty["ACTIVE"] = "Y";
if (!array_key_exists("PROPERTY_TYPE", $arProperty)) {
$arProperty["PROPERTY_TYPE"] = "S";
}
if (!array_key_exists("SORT", $arProperty)) {
$arProperty["SORT"] = $sort;
}
if (!array_key_exists("CODE", $arProperty)) {
$arProperty["CODE"] = $this->safeTranslit($arProperty["NAME"]);
if (preg_match('/^[0-9]/', $arProperty["CODE"])) {
$arProperty["CODE"] = '_' . $arProperty["CODE"];
}
$rsProperty = $obProperty->GetList(array(), array("IBLOCK_ID" => $IBLOCK_ID, "CODE" => $arProperty["CODE"]));
if ($arDBProperty = $rsProperty->Fetch()) {
$suffix = 0;
do {
$suffix++;
$rsProperty = $obProperty->GetList(array(), array("IBLOCK_ID" => $IBLOCK_ID, "CODE" => $arProperty["CODE"] . "_" . $suffix));
} while ($rsProperty->Fetch());
$arProperty["CODE"] .= '_' . $suffix;
}
}
$arProperty["ID"] = $obProperty->Add($arProperty);
if (!$arProperty["ID"]) {
return $obProperty->LAST_ERROR;
}
}
if ($XML_ENUM_PARENT) {
if ($isExternal) {
$result = $this->ImportPropertyDirectory($arProperty, $arEnumXmlNodes);
} else {
$result = $this->ImportPropertyEnum($arProperty, $arEnumXmlNodes);
}
if ($result !== true) {
return $result;
}
}
$sort += 100;
}
return true;
}
示例13: _CreateProperty
protected static function _CreateProperty($arProp)
{
$arProperty = array('IBLOCK_ID' => $arProp['IBLOCK_ID'], 'NAME' => $arProp['NAME'], 'ACTIVE' => 'Y', 'CODE' => $arProp['CODE'], 'PROPERTY_TYPE' => $arProp['TYPE'], 'ROW_COUNT' => 1, 'COL_COUNT' => 30, 'LIST_TYPE' => $arProp['LIST_TYPE'] ? $arProp['LIST_TYPE'] : 'L', 'MULTIPLE' => $arProp['MULTIPLE'], 'USER_TYPE' => $arProp['USER_TYPE'], 'CHECK_PERMISSIONS' => 'N');
if (is_array($arProp['ENUM'])) {
$arProperty['VALUES'] = array();
foreach ($arProp['ENUM'] as $key => $value) {
$arProperty['VALUES'][] = array('VALUE' => $value, 'SORT' => 100 * intval($key + 1), 'DEF' => $value == $arProp['ENUM_DEFAULT'] ? 'Y' : 'N');
}
}
$ibp = new CIBlockProperty();
return $ibp->Add($arProperty);
}
示例14: addProperty
protected function addProperty($arProperty)
{
$properties = \CIBlockProperty::GetList(array("sort" => "asc", "name" => "asc"), array("IBLOCK_ID" => $arProperty['IBLOCK_ID'], "CODE" => $arProperty["CODE"]));
if ($prop_fields = $properties->GetNext()) {
$this->addMessage('<br />Свойство ' . $arProperty["CODE"] . ' уже есть.');
} else {
$ibp = new \CIBlockProperty();
if ($PropID = $ibp->Add($arProperty)) {
$this->addMessage('Свойство ' . $arProperty["CODE"] . ' добавлено.', true);
}
unset($ibp);
}
}
示例15: getTestIBlockProp
/**
* @param int|string $iblockCode
* @param $arPropFields
* @param bool $bFailOnNonExist
* @return array
*/
public function getTestIBlockProp($iblockCode, $arPropFields, $bFailOnNonExist = false)
{
$arTestIBlock = $this->getTestIBlock(array('CODE' => $iblockCode), true);
$this->assertTrue(is_array($arTestIBlock));
$this->assertArrayHasKey('ID', $arTestIBlock);
if (!array_key_exists('CODE', $arPropFields)) {
$this->fail('Error: Infoblock property code is empty');
}
if (array_key_exists($arTestIBlock['CODE'], self::$_arTestIBProps) && array_key_exists($arPropFields['CODE'], self::$_arTestIBProps[$arTestIBlock['CODE']])) {
return self::$_arTestIBProps[$arTestIBlock['CODE']][$arPropFields['CODE']];
}
$rsProperty = \CIBlockProperty::GetList(array(), array('IBLOCK_ID' => $arTestIBlock['ID'], 'CODE' => $arPropFields['CODE']));
$arProperty = $rsProperty->Fetch();
if (!$arProperty) {
if ($bFailOnNonExist) {
$this->fail('Error: Property CODE="' . $arPropFields['CODE'] . '" does not exist');
}
if (!array_key_exists('NAME', $arPropFields) || empty($arPropFields['NAME'])) {
$arPropFields['NAME'] = $arPropFields['CODE'];
}
if (array_key_exists('PROPERTY_TYPE', $arPropFields) && $arPropFields['PROPERTY_TYPE'] == 'L' && (!is_array($arPropFields['VALUES']) || empty($arPropFields['VALUES']))) {
$this->fail('Error: Can\'t create property of type = list without values');
}
$arPropFieldsDef = array('IBLOCK_ID' => $arTestIBlock['ID'], 'PROPERTY_TYPE' => 'S', 'MULTIPLE' => 'N', 'ACTIVE' => 'Y', 'SORT' => '100');
$arPropFields = array_merge($arPropFieldsDef, $arPropFields);
$obProperty = new \CIBlockProperty();
/** @global \CDatabase $DB */
global $DB;
$DB->StartTransaction();
$newPropID = $obProperty->Add($arPropFields);
if ($newPropID > 0) {
$DB->Commit();
$rsProperty = \CIBlockProperty::GetByID($newPropID);
$arProperty = $rsProperty->Fetch();
if (!$arProperty) {
$this->fail('Error: can\'t get just created infoblock property');
}
} else {
$DB->Rollback();
$this->fail('Error: Can\'t create property: ' . $obProperty->LAST_ERROR);
}
}
if (!array_key_exists($arTestIBlock['CODE'], self::$_arTestIBProps)) {
self::$_arTestIBProps[$arTestIBlock['CODE']] = array();
}
self::$_arTestIBProps[$arTestIBlock['CODE']][$arProperty['CODE']] = $arProperty;
return self::$_arTestIBProps[$arTestIBlock['CODE']][$arPropFields['CODE']];
}