Created
August 24, 2015 06:03
-
-
Save putalexey/f1bb84ca9f455e956308 to your computer and use it in GitHub Desktop.
Добавляет в 1С-Битрикс тип свойства инфоблока "Привязка к группе пользователя"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 " "; | |
} | |
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 " "; | |
} | |
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