Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
defaultsitehelper.php
1<?
10
12use Bitrix\Main;
13
14Loc::loadMessages(__FILE__);
15
17{
18 const LIST_PAGE_URL = 'sale_location_default_list.php';
19 const EDIT_PAGE_URL = 'sale_location_default_edit.php';
20
21 #####################################
22 #### Entity settings
23 #####################################
24
29 public static function getEntityRoadMap()
30 {
31 return array(
32 'main' => array(
33 'name' => 'Bitrix\Main\Site',
34 'pages' => array(
35 'list' => array(
36 'includedColumns' => array('SITE_NAME', 'COUNT')
37 ),
38 'detail' => array(
39 'includedColumns' => array()
40 )
41 ),
42 'additional' => array(
43 'SITE_NAME' => array(
44 'data_type' => 'string',
45 'title' => Loc::getMessage('SALE_LOCATION_ADMIN_DEFAULT_SITE_HELPER_ENTITY_SITE_NAME_FIELD')
46 ),
47 'COUNT' => array(
48 'data_type' => 'integer',
49 'title' => Loc::getMessage('SALE_LOCATION_ADMIN_DEFAULT_SITE_HELPER_ENTITY_COUNT_FIELD')
50 ),
51 ),
52 'primaryFieldName' => 'LID'
53 ),
54 'location' => array(
55 'name' => 'Bitrix\Sale\Location\DefaultSite'
56 )
57 );
58 }
59
60 #####################################
61 #### CRUD wrappers
62 #####################################
63
64 public static function proxyUpdateRequest($data)
65 {
66 // strip away empty and removed items
67 foreach($data['LOCATION'] as $id => $item)
68 {
69 if($item['REMOVE'] == 1 || !mb_strlen($item['LOCATION_CODE']))
70 unset($data['LOCATION'][$id]);
71 }
72
73 return $data['LOCATION'];
74 }
75
76 public static function proxyListRequest($page)
77 {
78 $request = array();
79
80 if($page == 'list')
81 {
82 $request['runtime']['DEFAULT_LOCATION'] = array(
83 'data_type' => '\Bitrix\Sale\Location\DefaultSite',
84 'reference' => array(
85 '=this.LID' => 'ref.SITE_ID'
86 ),
87 'join_type' => 'left'
88 );
89
90 $request['runtime']['COUNT'] = array(
91 'data_type' => 'integer',
92 'expression' => array(
93 'count(%s)',
94 'DEFAULT_LOCATION.LOCATION_CODE'
95 )
96 );
97
98 $request['select'] = array(
99 'COUNT',
100 'NAME',
101 'SITE_ID' => 'LID'
102 );
103 }
104 elseif($page == 'detail')
105 {
106 $id = $_REQUEST['id'] <> ''? self::tryParseSiteId($_REQUEST['id']) : false;
107
108 if($id)
109 $request['filter']['=LID'] = $id;
110 }
111
112 return $request;
113 }
114
115 // block add handle, nothing to add
116 public static function add($data)
117 {
118 throw new Main\NotSupportedException(Loc::getMessage('SALE_LOCATION_ADMIN_DEFAULT_SITE_HELPER_ADD_OP_UNSUPPORTED'));
119 }
120
121 public static function update($siteId, $data)
122 {
123 $success = true;
124 $entityClass = static::getEntityClass('location');
125
126 $data = static::proxyUpdateRequest($data);
127 $errors = static::validateUpdateRequest($data);
128
129 unset($data['ID']);
130
131 if(empty($errors))
132 $entityClass::updateMultipleForOwner($siteId, $data); // result is always successfull, unless an exception thrown
133
134 return array(
135 'success' => $success,
136 'errors' => $errors
137 );
138 }
139
140 // block delete handle, nothing to delete
141 public static function delete($primary)
142 {
143 throw new Main\NotSupportedException(Loc::getMessage('SALE_LOCATION_ADMIN_DEFAULT_SITE_HELPER_DELETE_OP_UNSUPPORTED'));
144 }
145
146 // avoid paging here, kz its based on ID which is absent for this table
147 public static function getList($parameters = array(), $tableId = false, $navigation = 20, $params = array())
148 {
149 $entityClass = static::getEntityClass();
150
151 // only active sites to show
152 if(is_array($parameters))
153 {
154 $parameters['filter']['=ACTIVE'] = 'Y';
155 }
156
157 return new \CAdminResult($entityClass::getList($parameters), $tableId);
158 }
159
160 public static function getFormData($id)
161 {
162 $formData = parent::getFormData($id);
163 $formData = array_merge($formData, static::getDefaultLocationList($id));
164
165 return $formData;
166 }
167
168 public static function getNameToDisplay($siteId)
169 {
170 $entityClass = static::getEntityClass('main');
171
172 $site = $entityClass::getById($siteId)->fetch();
173 return $site['SITE_NAME'];
174 }
175
176 #####################################
177 #### Entity-specific
178 #####################################
179
180 public static function tryParseSiteId($sid)
181 {
182 return htmlspecialcharsbx(mb_substr($sid, 0, 2));
183 }
184
185 public static function getDefaultLocationList($siteId)
186 {
187 $entityClass = static::getEntityClass('location');
188
189 $res = $entityClass::getList(array(
190 'filter' => array(
191 '=SITE_ID' => $siteId
192 ),
193 //'order' => array('SORT' => 'asc')
194 ));
195 $index = array();
196 while($item = $res->fetch())
197 $index['LOCATION'][] = $item;
198
199 return $index;
200 }
201}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getList($parameters=array(), $tableId=false, $navigation=20, $params=array())