PageRenderTime 45ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/sale/lib/delivery/inputs.php

https://gitlab.com/alexprowars/bitrix
PHP | 508 lines | 474 code | 33 blank | 1 comment | 14 complexity | 4f6570657bdbc771f995f3222b71387a MD5 | raw file
  1. <?php
  2. namespace Bitrix\Sale\Delivery\Inputs;
  3. require_once __DIR__.'/../internals/input.php';
  4. use Bitrix\Main\ArgumentException;
  5. use Bitrix\Main\ArgumentTypeException;
  6. use Bitrix\Sale\Internals\Input;
  7. use Bitrix\Main\Localization\Loc;
  8. Loc::loadMessages(__FILE__);
  9. class Period extends Input\Base
  10. {
  11. public static function getViewHtmlSingle(array $input, $values)
  12. {
  13. if(!is_array($values))
  14. throw new ArgumentTypeException('values', 'array');
  15. self::checkArgs($input, $values);
  16. return $input["ITEMS"]["FROM"]["NAME"].": ".Input\Manager::getViewHtml($input["ITEMS"]["FROM"], $values["FROM"]).
  17. $input["ITEMS"]["TO"]["NAME"].": ".Input\Manager::getViewHtml($input["ITEMS"]["TO"], $values["TO"]).
  18. " ".Input\Manager::getViewHtml($input["ITEMS"]["TYPE"], $values["TYPE"]);
  19. }
  20. public static function getEditHtmlSingle($name, array $input, $values)
  21. {
  22. if(!isset($input["ITEMS"]))
  23. $input["ITEMS"] = array(
  24. "FROM" => array(
  25. "TYPE" => "STRING",
  26. "NAME" => ""
  27. ),
  28. "TO" => array(
  29. "TYPE" => "STRING",
  30. "NAME" => "&nbsp;-&nbsp;"
  31. ),
  32. "TYPE" => array(
  33. "TYPE" => "ENUM",
  34. "OPTIONS" => array(
  35. "H" => "HOURS", //Loc::getMessage("SALE_DLVR_HANDL_CONF_PERIOD_HOUR"),
  36. "D" => "DAYS", //Loc::getMessage("SALE_DLVR_HANDL_CONF_PERIOD_DAY"),
  37. "M" => "MONTHS" ////Loc::getMessage("SALE_DLVR_HANDL_CONF_PERIOD_MONTH")
  38. )
  39. )
  40. );
  41. return $input["ITEMS"]["FROM"]["NAME"].Input\Manager::getEditHtml($name."[FROM]", $input["ITEMS"]["FROM"], $values["FROM"]).
  42. $input["ITEMS"]["TO"]["NAME"].Input\Manager::getEditHtml($name."[TO]", $input["ITEMS"]["TO"], $values["TO"]).
  43. " ".Input\Manager::getEditHtml($name."[TYPE]", $input["ITEMS"]["TYPE"], $values["TYPE"]);
  44. }
  45. public static function getError(array $input, $values)
  46. {
  47. if(!is_array($values))
  48. throw new ArgumentTypeException('values', 'array');
  49. return self::getErrorSingle($input, $values);
  50. }
  51. public static function getErrorSingle(array $input, $values)
  52. {
  53. if(!is_array($values))
  54. throw new ArgumentTypeException('values', 'array');
  55. self::checkArgs($input, $values);
  56. $errors = array();
  57. if ($error = Input\Manager::getError($input["ITEMS"]["FROM"], $values["FROM"]))
  58. $errors = $error;
  59. if ($error = Input\Manager::getError($input["ITEMS"]["TO"], $values["TO"]))
  60. $errors = array_merge($errors, $error);
  61. if ($error = Input\Manager::getError($input["ITEMS"]["TYPE"], $values["TYPE"]))
  62. $errors = array_merge($errors, $error);
  63. return $errors;
  64. }
  65. public static function getValueSingle(array $input, $userValue)
  66. {
  67. return $userValue;
  68. }
  69. public static function getSettings(array $input, $reload)
  70. {
  71. return array();
  72. }
  73. protected static function checkArgs(array $input, array $values)
  74. {
  75. if(!isset($input["ITEMS"]["FROM"]) || !isset($input["ITEMS"]["TO"]) || !isset($input["ITEMS"]["TYPE"]))
  76. throw new ArgumentException("Wrong argument structure!", "input");
  77. if(!isset($values["FROM"]) || !isset($values["TO"]) || !isset($values["TYPE"]))
  78. throw new \Bitrix\Main\ArgumentException("Wrong argument structure!", "values");
  79. return true;
  80. }
  81. }
  82. Input\Manager::register('DELIVERY_PERIOD', array(
  83. 'CLASS' => __NAMESPACE__.'\\Period',
  84. 'NAME' => Loc::getMessage('INPUT_DELIVERY_PERIOD')
  85. ));
  86. class ReadOnlyField extends Input\Base
  87. {
  88. public static function getViewHtmlSingle(array $input, $value)
  89. {
  90. $result = '<span';
  91. if(!empty($input['ID']))
  92. $result .= ' id="'.$input['ID'].'_view"';
  93. $result .= '>';
  94. $result .= isset($input["VALUE_VIEW"]) ? $input["VALUE_VIEW"] : $value;
  95. $result .= '</span>';
  96. return $result;
  97. }
  98. public static function getEditHtmlSingle($name, array $input, $value)
  99. {
  100. $value = str_replace('"', "'", $value);
  101. $res = self::getViewHtml($input, $value).'<input type="hidden" value="'.htmlspecialcharsbx($value).'" name="'.htmlspecialcharsbx($name).'"';
  102. if(!empty($input['ID']))
  103. $res .= ' id="'.$input['ID'].'"';
  104. $res .= '>';
  105. return $res;
  106. }
  107. public static function getError(array $input, $values)
  108. {
  109. return self::getErrorSingle($input, $values);
  110. }
  111. public static function getErrorSingle(array $input, $values)
  112. {
  113. return array();
  114. }
  115. public static function getValueSingle(array $input, $userValue)
  116. {
  117. return $userValue;
  118. }
  119. public static function getSettings(array $input, $reload)
  120. {
  121. return array();
  122. }
  123. }
  124. Input\Manager::register('DELIVERY_READ_ONLY', array(
  125. 'CLASS' => __NAMESPACE__.'\\ReadOnlyField',
  126. 'NAME' => Loc::getMessage('INPUT_DELIVERY_READ_ONLY')
  127. ));
  128. class MultiControlString extends Input\Base
  129. {
  130. protected $items = array();
  131. protected $myParams = array();
  132. protected $myKey = array();
  133. public function addItem($key, array $control)
  134. {
  135. $this->items[$key] = $control;
  136. }
  137. public function setParams($key, array $params)
  138. {
  139. $this->myParams = $params;
  140. $this->setKey($key);
  141. }
  142. public function getParams()
  143. {
  144. $result = $this->myParams;
  145. $result["ITEMS"] = $this->items;
  146. return $result;
  147. }
  148. public function setKey($key)
  149. {
  150. $this->myKey = $key;
  151. }
  152. public function getKey()
  153. {
  154. return $this->myKey;
  155. }
  156. public function isClean()
  157. {
  158. return empty($this->myParams);
  159. }
  160. public function clean()
  161. {
  162. $this->myParams = $this->items = $this->myKey = array();
  163. }
  164. public static function getViewHtmlSingle(array $input, $values)
  165. {
  166. $result = "";
  167. foreach($input["ITEMS"] as $key => $item)
  168. $result .=
  169. isset($item["NAME"]) ? $item["NAME"] : "".
  170. Input\Manager::getViewHtml($item, isset($values[$key]) ? $values[$key] : null).
  171. " ";
  172. return $result;
  173. }
  174. public static function getEditHtmlSingle($name, array $input, $values)
  175. {
  176. $result = "";
  177. foreach($input["ITEMS"] as $key => $item)
  178. $result .=
  179. isset($item["NAME"]) ? $item["NAME"] : "".
  180. Input\Manager::getEditHtml($name."[".$key."]", $item, isset($values[$key]) ? $values[$key] : null).
  181. " ";
  182. return $result;
  183. }
  184. public static function getErrorSingle(array $input, $values)
  185. {
  186. if(!is_array($values))
  187. throw new ArgumentTypeException('values', 'array');
  188. $errors = array();
  189. foreach($input["ITEMS"] as $key => $item)
  190. if ($error = Input\Manager::getError($item, isset($values[$key]) ? $values[$key] : null))
  191. $errors[$key] = $error;
  192. return $errors;
  193. }
  194. public static function getValueSingle(array $input, $userValue)
  195. {
  196. return $userValue;
  197. }
  198. public static function getSettings(array $input, $reload)
  199. {
  200. return array();
  201. }
  202. /** Get single value.
  203. * @param $value
  204. * @return mixed - if value is multiple, get first meaningful value (which is not null)
  205. */
  206. static function asSingle($value)
  207. {
  208. return $value;
  209. }
  210. /**
  211. * @inherit
  212. */
  213. public static function getError(array $input, $value)
  214. {
  215. $errors = [];
  216. foreach($input["ITEMS"] as $key => $item)
  217. {
  218. $errors = array_merge($errors, Input\Manager::getError($item, $value[$key]));
  219. }
  220. return $errors;
  221. }
  222. /**
  223. * @inherit
  224. */
  225. public static function getRequiredError(array $input, $value)
  226. {
  227. $errors = [];
  228. foreach($input["ITEMS"] as $key => $item)
  229. {
  230. $errors = array_merge($errors, Input\Manager::getRequiredError($item, $value[$key]));
  231. }
  232. return $errors;
  233. }
  234. }
  235. Input\Manager::register('DELIVERY_MULTI_CONTROL_STRING', array(
  236. 'CLASS' => __NAMESPACE__.'\\MultiControlString',
  237. 'NAME' => Loc::getMessage('INPUT_DELIVERY_MULTI_CONTROL_STRING')
  238. ));
  239. class LocationMulti extends Input\Base
  240. {
  241. protected static $d2LClass = '\Bitrix\Sale\Delivery\DeliveryLocationTable';
  242. public static function getViewHtml(array $input, $value = null)
  243. {
  244. $result = "";
  245. $class = static::$d2LClass;
  246. $res = $class::getConnectedLocations(
  247. $input["DELIVERY_ID"],
  248. array(
  249. 'select' => array('LNAME' => 'NAME.NAME'),
  250. 'filter' => array('NAME.LANGUAGE_ID' => LANGUAGE_ID)
  251. )
  252. );
  253. while($loc = $res->fetch())
  254. $result .= htmlspecialcharsbx($loc["LNAME"])."<br>\n";
  255. $res = $class::getConnectedGroups(
  256. $input["DELIVERY_ID"],
  257. array(
  258. 'select' => array('LNAME' => 'NAME.NAME'),
  259. 'filter' => array('NAME.LANGUAGE_ID' => LANGUAGE_ID)
  260. )
  261. );
  262. while($loc = $res->fetch())
  263. $result .= htmlspecialcharsbx($loc["LNAME"])."<br>\n";
  264. return $result;
  265. }
  266. public static function getEditHtml($name, array $input, $values = null)
  267. {
  268. global $APPLICATION;
  269. ob_start();
  270. $APPLICATION->IncludeComponent(
  271. "bitrix:sale.location.selector.system",
  272. "",
  273. array(
  274. "ENTITY_PRIMARY" => $input["DELIVERY_ID"],
  275. "LINK_ENTITY_NAME" => mb_substr(static::$d2LClass, 0, -5),
  276. "INPUT_NAME" => $name
  277. ),
  278. false
  279. );
  280. $result = ob_get_contents();
  281. $result = '
  282. <script type="text/javascript">
  283. var bxInputdeliveryLocMultiStep3 = function()
  284. {
  285. BX.loadScript("/bitrix/components/bitrix/sale.location.selector.system/templates/.default/script.js", function(){
  286. BX.onCustomEvent("deliveryGetRestrictionHtmlScriptsReady");
  287. });
  288. };
  289. var bxInputdeliveryLocMultiStep2 = function()
  290. {
  291. BX.load([
  292. "/bitrix/js/sale/core_ui_etc.js",
  293. "/bitrix/js/sale/core_ui_autocomplete.js",
  294. "/bitrix/js/sale/core_ui_itemtree.js"
  295. ],
  296. bxInputdeliveryLocMultiStep3
  297. );
  298. };
  299. BX.loadScript("/bitrix/js/sale/core_ui_widget.js", bxInputdeliveryLocMultiStep2);
  300. //at first we must load some scripts in the right order
  301. window["deliveryGetRestrictionHtmlScriptsLoadingStarted"] = true;
  302. </script>
  303. <link rel="stylesheet" type="text/css" href="/bitrix/panel/main/adminstyles_fixed.css">
  304. <link rel="stylesheet" type="text/css" href="/bitrix/panel/main/admin.css">
  305. <link rel="stylesheet" type="text/css" href="/bitrix/panel/main/admin-public.css">
  306. <link rel="stylesheet" type="text/css" href="/bitrix/components/bitrix/sale.location.selector.system/templates/.default/style.css">
  307. '.
  308. $result;
  309. ob_end_clean();
  310. return $result;
  311. }
  312. public static function getError(array $input, $values)
  313. {
  314. return array();
  315. }
  316. public static function getValueSingle(array $input, $userValue)
  317. {
  318. return $userValue;
  319. }
  320. public static function getSettings(array $input, $reload)
  321. {
  322. return array();
  323. }
  324. }
  325. Input\Manager::register('LOCATION_MULTI', array(
  326. 'CLASS' => __NAMESPACE__.'\\LocationMulti',
  327. 'NAME' => Loc::getMessage('INPUT_DELIVERY_LOCATION_MULTI')
  328. ));
  329. class LocationMultiExclude extends LocationMulti
  330. {
  331. protected static $d2LClass = '\Bitrix\Sale\Delivery\DeliveryLocationExcludeTable';
  332. }
  333. Input\Manager::register('LOCATION_MULTI_EXCLUDE', array(
  334. 'CLASS' => __NAMESPACE__.'\\LocationMultiExclude',
  335. 'NAME' => Loc::getMessage('INPUT_DELIVERY_LOCATION_MULTI_EXCLUDE')
  336. ));
  337. // Deprecated type
  338. Input\Manager::register('DELIVERY_PRODUCT_CATEGORIES', array(
  339. 'CLASS' => \Bitrix\Sale\Internals\Input\ProductCategories::class,
  340. 'NAME' => Loc::getMessage('INPUT_DELIVERY_PRODUCT_CATEGORIES')
  341. ));
  342. class ButtonSelector extends Input\Base
  343. {
  344. public static function getViewHtmlSingle(array $input, $values)
  345. {
  346. if(!is_array($values))
  347. throw new ArgumentTypeException('values', 'array');
  348. $itemName = ($values['NAME'] <> '' ? htmlspecialcharsbx($values['NAME']) : '');
  349. if($itemName == '' && $input['NAME_DEFAULT'] <> '')
  350. {
  351. $itemName = htmlspecialcharsbx($input['NAME_DEFAULT']);
  352. }
  353. return $itemName;
  354. }
  355. public static function getEditHtmlSingle($name, array $input, $values)
  356. {
  357. if(!isset($input["NAME"]))
  358. $input["NAME"] = '';
  359. if(!isset($input["VALUE"]))
  360. $input["VALUE"] = '';
  361. $itemName = ($values['NAME'] <> '' ? htmlspecialcharsbx($values['NAME']) : '');
  362. if($itemName == '' && $input['NAME_DEFAULT'] <> '')
  363. {
  364. $itemName = htmlspecialcharsbx($input['NAME_DEFAULT']);
  365. }
  366. $itemValue = ($values['VALUE'] <> '' ? htmlspecialcharsbx($values['VALUE']) : '');
  367. if($itemName == '' && $input['VALUE_DEFAULT'] <> '')
  368. {
  369. $itemValue = htmlspecialcharsbx($input['VALUE_DEFAULT']);
  370. }
  371. return '<div>'.
  372. '<div id="'.$input['READONLY_NAME_ID'].'">'.htmlspecialcharsbx($itemName).'</div>'.
  373. ' <input type="button" value="'.$input['BUTTON']['NAME'].'" onclick="'.$input['BUTTON']['ONCLICK'].' return false;" style="margin-top: 20px;">'.
  374. '<input type="hidden" name="'.$name.'[NAME]" value="'.$itemName.'">'.
  375. '<input type="hidden" name="'.$name.'[VALUE]" value="'.$itemValue.'">'.
  376. '</div>';
  377. }
  378. public static function getValueSingle(array $input, $userValue)
  379. {
  380. return $userValue;
  381. }
  382. public static function getSettings(array $input, $reload)
  383. {
  384. return array();
  385. }
  386. public static function getError(array $input, $values)
  387. {
  388. return self::getErrorSingle($input, $values);
  389. }
  390. public static function getErrorSingle(array $input, $values)
  391. {
  392. return array();
  393. }
  394. static function asSingle($value)
  395. {
  396. return $value;
  397. }
  398. }
  399. Input\Manager::register('DELIVERY_BUTTON_SELECTOR', array(
  400. 'CLASS' => __NAMESPACE__.'\\ButtonSelector',
  401. 'NAME' => Loc::getMessage('INPUT_DELIVERY_BUTTON_SELECTOR')
  402. ));