52 public static function getList($param, $nav, \CRestServer $server)
54 static::checkPermission($server);
56 $navParams = static::getNavData($nav,
true);
58 $dbRes = PlacementTable::getList(array(
60 '=PLACEMENT' => static::PLACEMENT_UF_TYPE,
61 '=REST_APP.CLIENT_ID' => $server->getClientId(),
64 'USER_TYPE_ID' =>
'ADDITIONAL',
65 'HANDLER' =>
'PLACEMENT_HANDLER',
67 'DESCRIPTION' =>
'COMMENT'
70 'limit' => $navParams[
'limit'],
71 'offset' => $navParams[
'offset'],
72 'count_total' =>
true,
76 while($handler = $dbRes->fetch())
81 return static::setNavData(
84 "count" => $dbRes->getCount(),
85 "offset" => $navParams[
'offset']
105 public static function add($param, $n, \CRestServer $server): bool
107 static::checkPermission($server);
109 $param = array_change_key_case($param, CASE_UPPER);
111 $userTypeId = mb_strtolower($param[
'USER_TYPE_ID']);
112 $placementHandler = $param[
'HANDLER'];
114 if ($userTypeId ==
'')
119 if ($placementHandler ==
'')
128 $placementBind = array(
129 'APP_ID' => $appInfo[
'ID'],
130 'PLACEMENT' => static::PLACEMENT_UF_TYPE,
131 'PLACEMENT_HANDLER' => $placementHandler,
132 'TITLE' => $userTypeId,
133 'ADDITIONAL' => $userTypeId,
134 'OPTIONS' => static::prepareOption($param[
'OPTIONS']),
137 $placementBind = array_merge(
146 'TITLE' => $placementBind[
'TITLE']
151 if ($placementBind[
'LANG_ALL'])
153 $langAll = $placementBind[
'LANG_ALL'];
155 unset($placementBind[
'LANG_ALL']);
157 $result = PlacementTable::add($placementBind);
158 if (!$result->isSuccess())
160 $errorMessage = $result->getErrorMessages();
162 'Unable to set placement handler: '.implode(
', ', $errorMessage),
168 $placementId = $result->getId();
169 foreach ($langAll as $lang => $item)
171 $item[
'PLACEMENT_ID'] = $placementId;
172 $item[
'LANGUAGE_ID'] = $lang;
174 if (!$res->isSuccess())
177 'Error: ' . implode(
', ', $res->getErrorMessages()),
183 'ID' => $placementId,
184 'APP_ID' => $appInfo[
'ID'],
185 'ADDITIONAL' => $userTypeId,
192 public static function update($param, $n, \CRestServer $server)
194 static::checkPermission($server);
196 $param = array_change_key_case($param, CASE_UPPER);
198 $userTypeId = toLower($param[
'USER_TYPE_ID']);
200 if($userTypeId ==
'')
205 $updateFields = array();
206 if(!empty($param[
'HANDLER']))
211 $updateFields[
'PLACEMENT_HANDLER'] = $param[
'HANDLER'];
214 if (array_key_exists(
'OPTIONS', $param))
216 $updateFields[
'OPTIONS'] = static::prepareOption($param[
'OPTIONS']);
219 $updateFields = array_merge(
228 'TITLE' => $updateFields[
'TITLE']
233 if ($updateFields[
'LANG_ALL'])
235 $langAll = $updateFields[
'LANG_ALL'];
237 unset($updateFields[
'LANG_ALL']);
239 if(count($updateFields) > 0)
241 $dbRes = PlacementTable::getList(array(
243 '=REST_APP.CLIENT_ID' => $server->getClientId(),
244 '=ADDITIONAL' => $userTypeId
246 'select' => array(
'ID',
'APP_ID',
'ADDITIONAL')
248 $placementInfo = $dbRes->fetch();
251 $updateResult = PlacementTable::update($placementInfo[
'ID'], $updateFields);
252 if($updateResult->isSuccess())
255 foreach ($langAll as $lang => $item)
257 $item[
'PLACEMENT_ID'] = $placementInfo[
'ID'];
258 $item[
'LANGUAGE_ID'] = $lang;
260 if (!$res->isSuccess())
263 'Error: ' . implode(
', ', $res->getErrorMessages()),
273 $errorMessage = $updateResult->getErrorMessages();
275 'Unable to update User Field Type: '.implode(
', ', $errorMessage),
293 public static function delete($param, $n, \CRestServer $server)
295 static::checkPermission($server);
297 $param = array_change_key_case($param, CASE_UPPER);
299 $userTypeId = toLower($param[
'USER_TYPE_ID']);
301 if($userTypeId ==
'')
306 $dbRes = PlacementTable::getList(array(
308 '=REST_APP.CLIENT_ID' => $server->getClientId(),
309 '=ADDITIONAL' => $userTypeId
311 'select' => array(
'ID',
'APP_ID',
'ADDITIONAL')
313 $placementInfo = $dbRes->fetch();
316 $deleteResult = PlacementTable::delete($placementInfo[
'ID']);
317 if($deleteResult->isSuccess())
323 $errorMessage = $deleteResult->getErrorMessages();
325 'Unable to delete User Field Type: '.implode(
', ', $errorMessage),