30 private const PERMISSION_ALLOWED = 1;
34 return 'b_user_field_permission';
39 return UserFieldPermission::class;
45 new Entity\IntegerField(
'ID', [
46 'autocomplete' =>
true,
49 new Entity\IntegerField(
'ENTITY_TYPE_ID', [
52 new Entity\IntegerField(
'USER_FIELD_ID', [
55 new Entity\StringField(
'ACCESS_CODE', [
58 new Entity\StringField(
'PERMISSION_ID', [
61 new Entity\IntegerField(
'VALUE', [
66 UserFieldTable::class,
67 Join::on(
'this.USER_FIELD_ID',
'ref.ID')
71 UserAccessTable::class,
72 Join::on(
'this.ACCESS_CODE',
'ref.ACCESS_CODE')
88 UPDATE `" . static::getTableName() .
"`
91 USER_FIELD_ID = " . $data[
'USER_FIELD_ID'] .
"
92 AND ACCESS_CODE = " . $data[
'ACCESS_CODE'] .
"
93 AND PERMISSION_ID LIKE '" . $data[
'PERMISSION_ID'] .
".%'
95 static::getEntity()->getConnection()->query($sql);
105 if (!$parentPermissions)
110 $res = self::getRow([
111 'select' => [
'VALUE'],
113 '=USER_FIELD_ID' => (
int)$data[
'USER_FIELD_ID'],
114 '=ACCESS_CODE' => (
int)$data[
'ACCESS_CODE'],
115 '%=PERMISSION_ID' => $parentPermissions,
120 if (is_array($res) && count($res))
134 $query =
new Entity\Query(self::getEntity());
135 $query->addSelect(
'USER_FIELD.FIELD_NAME',
'FIELD_NAME');
136 $query->addSelect(
'ACCESS_CODE');
137 $query->addSelect(
'USER_ACCESS.USER_ID',
'USER_ID');
138 $query->addSelect(
'USER_FIELD_ID');
139 $query->addFilter(
'=ENTITY_TYPE_ID', $entityTypeID);
140 $query->addFilter(
'=VALUE', self::PERMISSION_ALLOWED);
141 $query->whereNotNull(
'FIELD_NAME');
143 $dbResult = $query->exec();
145 return $dbResult->fetchAll();
155 public static function saveEntityConfiguration(
159 string $permissionId,
160 ?
string $entityTypeName =
null
163 if ($userField = self::getUserFieldId($fieldName, $entityTypeName))
165 self::removeEntityConfiguration($userField[
'ID'], $entityTypeId);
166 if (is_array($accessCodes))
168 foreach ($accessCodes as $accessCode)
173 $permission = self::createObject([
174 'ENTITY_TYPE_ID' => $entityTypeId,
175 'USER_FIELD_ID' => $userField[
'ID'],
176 'ACCESS_CODE' => $accessCode[
'ID'],
177 'PERMISSION_ID' => $permissionId,
178 'VALUE' => self::PERMISSION_ALLOWED
190 private static function removeEntityConfiguration(
int $userFieldId,
int $entityTypeId): void
193 '=ENTITY_TYPE_ID' => $entityTypeId,
194 '=USER_FIELD_ID' => $userFieldId
203 private static function getUserFieldId(
string $fieldName, ?
string $entityId =
null): ?array
205 $filter = [
'=FIELD_NAME' => $fieldName];
208 $filter[
'=ENTITY_ID'] = $entityId;
static deleteList(array $filter)
static loadUpdateRow($primary, array $data)
static getRow(array $parameters)
static updateChildPermission($primary, array $data)
static getUserFieldsAccessCodes(int $entityTypeID)
static getParentsPath(string $permissionId)