本文整理汇总了PHP中Bitrix\Iblock\PropertyTable::add方法的典型用法代码示例。如果您正苦于以下问题:PHP PropertyTable::add方法的具体用法?PHP PropertyTable::add怎么用?PHP PropertyTable::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bitrix\Iblock\PropertyTable
的用法示例。
在下文中一共展示了PropertyTable::add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createProperty
/**
* Create property.
*
* @param int $iblockID Iblock id.
* @param string $propertyCode Property code.
* @param array $propertyParams Property params.
* @return bool|int
*/
public static function createProperty($iblockID, $propertyCode, $propertyParams = array())
{
self::$errors = array();
$iblockID = (int) $iblockID;
$propertyCode = (string) $propertyCode;
if ($iblockID <= 0 || $propertyCode === '') {
return false;
}
$iblockIterator = Iblock\IblockTable::getList(array('select' => array('ID'), 'filter' => array('ID' => $iblockID)));
if (!($iblock = $iblockIterator->fetch())) {
return false;
}
unset($iblock, $iblockIterator);
$propertyIterator = Iblock\PropertyTable::getList(array('select' => array('ID'), 'filter' => array('IBLOCK_ID' => $iblockID, '=CODE' => $propertyCode)));
if ($property = $propertyIterator->fetch()) {
return (int) $property['ID'];
}
unset($propertyIterator);
$propertyDescription = self::getPropertyDescription($propertyCode, $propertyParams);
if ($propertyDescription === false) {
return false;
}
$propertyDescription['IBLOCK_ID'] = $iblockID;
if (!self::validatePropertyDescription($propertyDescription)) {
return false;
}
$propertyResult = Iblock\PropertyTable::add($propertyDescription);
if ($propertyResult->isSuccess()) {
return $propertyResult->getId();
} else {
self::$errors = $propertyResult->getErrorMessages();
return false;
}
}
示例2: createProperty
/**
* Create property.
*
* @param int $iblockID Iblock id.
* @param string $propertyCode Property code.
* @param array $propertyParams Property params.
* @return bool|int
*/
public static function createProperty($iblockID, $propertyCode, $propertyParams = array())
{
self::$errors = array();
$iblockID = (int) $iblockID;
$propertyCode = (string) $propertyCode;
if ($iblockID <= 0 || $propertyCode === '') {
return false;
}
$iblockIterator = Iblock\IblockTable::getList(array('select' => array('ID'), 'filter' => array('=ID' => $iblockID)));
if (!($iblock = $iblockIterator->fetch())) {
return false;
}
unset($iblock, $iblockIterator);
$propertyDescription = static::getPropertyDescription($propertyCode, $propertyParams);
if ($propertyDescription === false) {
return false;
}
$propertyDescription['IBLOCK_ID'] = $iblockID;
if (!static::validatePropertyDescription($propertyDescription)) {
return false;
}
$propertyId = 0;
$getListParams = array('select' => array('ID'), 'filter' => array('=IBLOCK_ID' => $iblockID, '=CODE' => $propertyCode, '=ACTIVE' => 'Y'));
static::modifyGetListParams($getListParams, $propertyCode, $propertyDescription);
$property = Iblock\PropertyTable::getList($getListParams)->fetch();
if (!empty($property)) {
if (static::validateExistProperty($propertyCode, $property)) {
$propertyId = (int) $property['ID'];
}
}
unset($property);
if (!empty(self::$errors)) {
return false;
}
if ($propertyId > 0) {
return $propertyId;
}
unset($propertyId);
$propertyResult = Iblock\PropertyTable::add($propertyDescription);
if ($propertyResult->isSuccess()) {
return $propertyResult->getId();
} else {
self::$errors = $propertyResult->getErrorMessages();
return false;
}
}
示例3: applySnapshot
/**
* @param $data
* @param null $dbVersion
* @throws \Exception
* @return ApplyResult
*/
public function applySnapshot($data, $dbVersion = null)
{
$data = $this->handleNullValues($data);
$prop = new \CIBlockProperty();
$res = new ApplyResult();
$extId = $data['ID'];
if ($dbVersion) {
$data['IBLOCK_ID'] = $this->getReferenceController()->getCurrentIdByOtherVersion($data['IBLOCK_ID'], ReferenceController::GROUP_IBLOCK, $dbVersion);
$id = $this->getCurrentVersionId($extId, $dbVersion);
} else {
$id = $extId;
}
if (!$dbVersion && !PropertyTable::getById($id)->fetch()) {
unset($data['VERSION']);
$addRes = PropertyTable::add(array('ID' => $id, 'NAME' => $data['NAME'], 'IBLOCK_ID' => $data['IBLOCK_ID']));
if (!$addRes->isSuccess()) {
throw new \Exception('Ќе удалось возобновить свойство текущей версии. ' . implode(', ', $addRes->getErrorMessages()) . "\n" . var_export($data, true));
}
}
if ($id && PropertyTable::getById($id)->fetch()) {
$res->setSuccess((bool) $prop->Update($id, $data));
} else {
$res->setSuccess((bool) ($id = $prop->Add($data)));
$this->registerCurrentVersionId($id, $this->getReferenceValue($extId, $dbVersion));
}
$res->setId($id);
if ($data['PROPERTY_TYPE'] == self::LIST_TYPE_SIGN && !empty($data['~property_list_values'])) {
$this->_applyPropertyListTypeValues($id, $data['~property_list_values']);
}
return $res->setMessage($prop->LAST_ERROR);
}