Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Добавляет в 1С-Битрикс тип свойства инфоблока "Привязка к группе пользователя"
<?php
AddEventHandler("iblock", "OnIBlockPropertyBuildList", Array("CIBlockPropertyUserGroup", "GetUserTypeDescription"));
class CIBlockPropertyUserGroup
{
public static function GetUserTypeDescription()
{
return array(
"PROPERTY_TYPE" => "N",
"USER_TYPE" => "USER_GROUP",
"DESCRIPTION" => "Привязка к группе пользователей",
"CheckFields" => array(__CLASS__, "CheckFields"),
"GetLength" => array(__CLASS__, "GetLength"),
"GetPropertyFieldHtml" => array(__CLASS__, "GetPropertyFieldHtml"),
"GetAdminListViewHTML" => array(__CLASS__, "GetAdminListViewHTML"),
"GetPublicViewHTML" => array(__CLASS__, "GetPublicViewHTML"),
"GetSearchContent" => array(__CLASS__, "GetSearchContent"),
);
}
public static function CheckFields(array $arProperty, array $value)
{
$arResult = array();
if(intval($value["VALUE"]))
{
$by = "c_sort";
$order = "asc";
$groups = CGroup::GetList($by, $order, array("ACTIVE" => "Y"));
$bFound = false;
while($arGroup = $groups->Fetch())
{
if($arGroup["ID"] == $value["VALUE"])
$bFound = true;
}
if(!$bFound)
$arResult[] = "Группа пользователей не найдена";
}
return $arResult;
}
public static function GetLength($arProperty, $value)
{
if(is_array($value) && array_key_exists("VALUE", $value))
return strLen(trim($value["VALUE"]));
else
return 0;
}
public static function GetPropertyFieldHtml($arProperty, $value, $strHTMLControlName)
{
$rsGroups = CGroup::GetList($by, $order, array("ACTIVE" => "Y"));
ob_start();
?>
<select name="<?=$strHTMLControlName["VALUE"]?>">
<option value="">Выбрать</option>
<?while($arGroup = $rsGroups->Fetch()):?>
<option value="<?=$arGroup["ID"]?>"<?=($value["VALUE"] == $arGroup["ID"]?" selected=\"selected\"":"")?>>[<?=$arGroup["ID"]?>] <?=$arGroup["NAME"]?></option>
<?endwhile;?>
?>
</select>
<?
$result = ob_get_clean();
return $result;
}
public static function GetAdminListViewHTML($arProperty, $value, $strHTMLControlName)
{
$group_id = intval($value["VALUE"]);
if($group_id){
$arGroup = CGroup::GetByID($value["VALUE"])->Fetch();
return "[{$arGroup["ID"]}] ".htmlspecialcharsex($arGroup["NAME"]);
}
return "&nbsp;";
}
public static function GetPublicViewHTML($arProperty, $value, $strHTMLControlName)
{
$group_id = intval($value["VALUE"]);
if($group_id){
$arGroup = CGroup::GetByID($value["VALUE"])->Fetch();
return "[{$arGroup["ID"]}] ".htmlspecialcharsex($arGroup["NAME"]);
}
return "&nbsp;";
}
public static function GetSearchContent($arProperty, $value, $strHTMLControlName)
{
if(strlen($value["VALUE"])>0)
return $value["VALUE"];
else
return '';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.