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