Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
spacecompositiontable.php
1<?php
3
11
40{
44 public static function getTableName(): string
45 {
46 return 'b_sonet_space_composition';
47 }
48
52 public static function getMap(): array
53 {
54 return [
55 (new IntegerField('ID'))
56 ->configurePrimary()
57 ->configureAutocomplete(),
58 (new IntegerField('USER_ID'))
59 ->configureRequired(),
60 (new IntegerField('SPACE_ID'))
61 ->configureRequired(),
62 (new ArrayField('SETTINGS'))
63 ->configureRequired()
64 ->configureSerializationJson(),
65 ];
66 }
67
68 public static function getObjectClass(): string
69 {
70 return SpaceCompositionObject::class;
71 }
72
73 public static function getCollectionClass(): string
74 {
75 return SpaceCompositionCollection::class;
76 }
77
83 public static function isDataFilled(int $userId, int $spaceId): bool
84 {
85 $composition = static::getByIds($userId, $spaceId);
86
87 return !is_null($composition);
88 }
89
90 public static function fill(int $userId, int $spaceId, array $settings): Result
91 {
92 $composition = (new SpaceCompositionObject())
93 ->setUserId($userId)
94 ->setSpaceId($spaceId)
95 ->setSettings($settings);
96
97 return $composition->save();
98 }
99
105 public static function getByIds(int $userId, int $spaceId = 0): ?SpaceCompositionObject
106 {
107 $query = static::query();
108 $query
109 ->setSelect(['*'])
110 ->where('USER_ID', $userId)
111 ->where('SPACE_ID', $spaceId)
112 ->setLimit(1);
113
114 return $query->exec()->fetchObject();
115 }
116}