PageRenderTime 28ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/components/bitrix/sale.bsm.site.master/wizard/modulestep.php

https://gitlab.com/alexprowars/bitrix
PHP | 342 lines | 259 code | 38 blank | 45 comment | 15 complexity | c389b153dbeee9a9995664495c002902 MD5 | raw file
  1. <?php
  2. namespace Bitrix\Sale\BsmSiteMaster\Steps;
  3. use Bitrix\Main\Localization\Loc;
  4. Loc::loadMessages(__FILE__);
  5. /**
  6. * Class ModuleStep
  7. * Show list of required modules
  8. *
  9. * @package Bitrix\Sale\BsmSiteMaster\Steps
  10. */
  11. class ModuleStep extends \CWizardStep
  12. {
  13. private $currentStepName = __CLASS__;
  14. /** @var \SaleBsmSiteMaster */
  15. private $component = null;
  16. private $modulesChecked = [
  17. "NOT_INSTALLED_MODULES" => [],
  18. "MIN_VERSION_MODULES" => [],
  19. ];
  20. /**
  21. * Check step errors
  22. */
  23. private function setStepErrors()
  24. {
  25. $errors = $this->component->getWizardStepErrors($this->currentStepName);
  26. if ($errors)
  27. {
  28. foreach ($errors as $error)
  29. {
  30. $this->SetError($error);
  31. }
  32. }
  33. }
  34. /**
  35. * Prepare next/prev buttons
  36. *
  37. * @throws \ReflectionException
  38. */
  39. private function prepareButtons()
  40. {
  41. $steps = $this->component->getSteps($this->currentStepName);
  42. $shortClassName = (new \ReflectionClass($this))->getShortName();
  43. if (isset($steps["NEXT_STEP"]))
  44. {
  45. $this->SetNextStep($steps["NEXT_STEP"]);
  46. $this->SetNextCaption(Loc::getMessage("SALE_BSM_WIZARD_".mb_strtoupper($shortClassName)."_NEXT"));
  47. }
  48. if (isset($steps["PREV_STEP"]))
  49. {
  50. $this->SetPrevStep($steps["PREV_STEP"]);
  51. $this->SetPrevCaption(Loc::getMessage("SALE_BSM_WIZARD_".mb_strtoupper($shortClassName)."_PREV"));
  52. }
  53. }
  54. /**
  55. * Initialization step id, title and next/prev step
  56. *
  57. * @throws \ReflectionException
  58. */
  59. public function initStep()
  60. {
  61. $this->component = $this->GetWizard()->GetVar("component");
  62. $this->SetStepID($this->currentStepName);
  63. $this->SetTitle(Loc::getMessage("SALE_BSM_WIZARD_MODULESTEP_TITLE"));
  64. $this->prepareButtons();
  65. $this->setStepErrors();
  66. $this->modulesChecked["NOT_INSTALLED_MODULES"] = $this->GetWizard()->GetVar("not_installed_modules");
  67. $this->modulesChecked["MIN_VERSION_MODULES"] = $this->GetWizard()->GetVar("min_version_modules");
  68. }
  69. /**
  70. * Show step content
  71. *
  72. * @return bool
  73. */
  74. public function showStep()
  75. {
  76. if ($this->GetErrors())
  77. {
  78. return false;
  79. }
  80. if ($this->modulesChecked["NOT_INSTALLED_MODULES"])
  81. {
  82. $this->SetNextStep("Bitrix\Sale\BsmSiteMaster\Steps\ModuleInstallStep");
  83. $this->installModulesHtml();
  84. }
  85. elseif ($this->modulesChecked["MIN_VERSION_MODULES"])
  86. {
  87. $this->SetNextCaption(Loc::getMessage("SALE_BSM_WIZARD_MODULESTEP_NEXT_BUTTON"));
  88. $this->minModulesHtml();
  89. }
  90. else
  91. {
  92. $this->SetNextCaption(Loc::getMessage("SALE_BSM_WIZARD_MODULESTEP_NEXT_BUTTON"));
  93. ob_start();
  94. ?>
  95. <div class="adm-bsm-site-master-paragraph-wrapper">
  96. <div class="adm-bsm-site-master-paragraph"><?=Loc::getMessage("SALE_BSM_WIZARD_MODULESTEP_CHECK_SUCCESS")?></div>
  97. </div>
  98. <?
  99. $content = ob_get_contents();
  100. ob_end_clean();
  101. $this->content .= $content;
  102. }
  103. return true;
  104. }
  105. /**
  106. * @return array
  107. */
  108. public function showButtons()
  109. {
  110. if ($this->GetErrors())
  111. {
  112. return [
  113. "CONTENT" => ""
  114. ];
  115. }
  116. ob_start();
  117. if ($this->GetPrevStepID() !== null)
  118. {
  119. ?>
  120. <input type="hidden" name="<?=$this->GetWizard()->prevStepHiddenID?>" value="<?=$this->GetPrevStepID()?>">
  121. <button type="submit" class="ui-btn ui-btn-primary" name="<?=$this->GetWizard()->prevButtonID?>">
  122. <?=$this->GetPrevCaption()?>
  123. </button>
  124. <?
  125. }
  126. if ($this->GetNextStepID() !== null)
  127. {
  128. ?>
  129. <input type="hidden" name="<?=$this->GetWizard()->nextStepHiddenID?>" value="<?=$this->GetNextStepID()?>">
  130. <button type="submit" class="ui-btn ui-btn-primary" name="<?=$this->GetWizard()->nextButtonID?>">
  131. <?=$this->GetNextCaption()?>
  132. </button>
  133. <?
  134. }
  135. $content = ob_get_contents();
  136. ob_end_clean();
  137. return [
  138. "CONTENT" => $content,
  139. "NEED_WRAPPER" => true,
  140. "CENTER" => true,
  141. ];
  142. }
  143. /**
  144. * @return bool
  145. * @throws \Bitrix\Main\ArgumentNullException
  146. */
  147. public function onPostForm()
  148. {
  149. $wizard =& $this->GetWizard();
  150. if ($wizard->IsPrevButtonClick())
  151. {
  152. return false;
  153. }
  154. if ($this->modulesChecked["NOT_INSTALLED_MODULES"])
  155. {
  156. $wizard->SetVar("modules", $this->modulesChecked["NOT_INSTALLED_MODULES"]);
  157. $wizard->SetVar("modulesCount", count($this->modulesChecked["NOT_INSTALLED_MODULES"]));
  158. return false;
  159. }
  160. if (!$this->modulesChecked["NOT_INSTALLED_MODULES"] && !$this->modulesChecked["MIN_VERSION_MODULES"])
  161. {
  162. $this->GetWizard()->SetCurrentStep("Bitrix\Sale\BsmSiteMaster\Steps\SiteInstructionStep");
  163. $this->component->getModuleChecker()->deleteInstallStatus();
  164. }
  165. return true;
  166. }
  167. /**
  168. * Prepare html content with modules to be installed
  169. */
  170. private function installModulesHtml()
  171. {
  172. $rows = [];
  173. foreach ($this->modulesChecked["NOT_INSTALLED_MODULES"] as $module)
  174. {
  175. $rows[]["data"] = [
  176. "MODULE" => $module["name"],
  177. ];
  178. };
  179. $columns = [
  180. [
  181. 'id' => 'MODULE',
  182. 'name' => Loc::getMessage("SALE_BSM_WIZARD_MODULESTEP_INSTALL_COLUMN"),
  183. 'sort' => 'MODULE',
  184. 'default' => true,
  185. 'resizeable' => false,
  186. ],
  187. ];
  188. $this->content .= $this->includeGridComponent("module_install_list", $columns, $rows);
  189. }
  190. /**
  191. * Prepare html content with modules to be updated
  192. */
  193. private function minModulesHtml()
  194. {
  195. $rows = [];
  196. $isMarketPlace = false;
  197. $isUpdateSystem = false;
  198. foreach ($this->modulesChecked["MIN_VERSION_MODULES"] as $moduleName => $moduleValue)
  199. {
  200. $rows[]["data"] = [
  201. "MODULE" => $moduleValue["NAME"],
  202. "CURRENT_VERSION" => $moduleValue["CURRENT_VERSION"],
  203. "REQUIRED_VERSION" => $moduleValue["REQUIRED_VERSION"],
  204. ];
  205. if (mb_strpos($moduleName, ".") !== false)
  206. {
  207. $isMarketPlace = true;
  208. }
  209. else
  210. {
  211. $isUpdateSystem = true;
  212. }
  213. };
  214. $columns = [
  215. [
  216. 'id' => 'MODULE',
  217. 'name' => Loc::getMessage("SALE_BSM_WIZARD_MODULESTEP_UPDATE_COLUMN"),
  218. 'sort' => 'MODULE',
  219. 'default' => true,
  220. 'resizeable' => false,
  221. ],
  222. [
  223. 'id' => 'CURRENT_VERSION',
  224. 'name' => Loc::getMessage("SALE_BSM_WIZARD_MODULESTEP_UPDATE_CURRENT_VERSION"),
  225. 'sort' => 'CURRENT_VERSION',
  226. 'default' => true,
  227. 'resizeable' => false,
  228. ],
  229. [
  230. 'id' => 'REQUIRED_VERSION',
  231. 'name' => Loc::getMessage("SALE_BSM_WIZARD_MODULESTEP_UPDATE_REQUIRED_VERSION"),
  232. 'sort' => 'REQUIRED_VERSION',
  233. 'default' => true,
  234. 'resizeable' => false,
  235. ],
  236. ];
  237. $this->content .= $this->includeGridComponent("module_update_list", $columns, $rows);
  238. ob_start();
  239. ?>
  240. <div class="adm-bsm-site-master-paragraph-wrapper">
  241. <?php if ($isMarketPlace && $isUpdateSystem):?>
  242. <div class="adm-bsm-site-master-paragraph"><?=Loc::getMessage("SALE_BSM_WIZARD_MODULESTEP_ALL_DESCR", [
  243. "#MARKET_PLACE_LINK#" => "/bitrix/admin/update_system_market.php?module=bitrix.eshop&lang=".LANGUAGE_ID,
  244. "#UPDATE_SYSTEM_LINK#" => "/bitrix/admin/update_system.php?lang=".LANGUAGE_ID,
  245. ])?>
  246. </div>
  247. <?php elseif ($isMarketPlace):?>
  248. <div class="adm-bsm-site-master-paragraph"><?=Loc::getMessage("SALE_BSM_WIZARD_MODULESTEP_MARKET_PLACE_DESCR", [
  249. "#MARKET_PLACE_LINK#" => "/bitrix/admin/update_system_market.php?module=bitrix.eshop&lang=".LANGUAGE_ID,
  250. ])?>
  251. </div>
  252. <?php elseif ($isUpdateSystem):?>
  253. <div class="adm-bsm-site-master-paragraph"><?=Loc::getMessage("SALE_BSM_WIZARD_MODULESTEP_UPDATE_SYSTEM_DESCR", [
  254. "#UPDATE_SYSTEM_LINK#" => "/bitrix/admin/update_system.php?lang=".LANGUAGE_ID,
  255. ])?>
  256. </div>
  257. <?php endif;?>
  258. <div class="adm-bsm-site-master-paragraph"><?=Loc::getMessage("SALE_BSM_WIZARD_MODULESTEP_CONTINUE_DESCR")?></div>
  259. </div>
  260. <?
  261. $content = ob_get_contents();
  262. ob_end_clean();
  263. $this->content .= $content;
  264. }
  265. /**
  266. * @param $id
  267. * @param $columns
  268. * @param $rows
  269. * @return false|string
  270. */
  271. private function includeGridComponent($id, $columns, $rows)
  272. {
  273. /** @noinspection PhpVariableNamingConventionInspection */
  274. global $APPLICATION;
  275. ob_start();
  276. $APPLICATION->IncludeComponent('bitrix:main.ui.grid', '', [
  277. 'GRID_ID' => $id,
  278. 'COLUMNS' => $columns,
  279. 'ROWS' => $rows,
  280. 'SHOW_ROW_CHECKBOXES' => false,
  281. 'AJAX_MODE' => 'N',
  282. 'AJAX_OPTION_JUMP' => 'N',
  283. 'SHOW_CHECK_ALL_CHECKBOXES' => false,
  284. 'SHOW_ROW_ACTIONS_MENU' => false,
  285. 'SHOW_GRID_SETTINGS_MENU' => false,
  286. 'SHOW_NAVIGATION_PANEL' => false,
  287. 'SHOW_PAGINATION' => false,
  288. 'SHOW_SELECTED_COUNTER' => false,
  289. 'SHOW_TOTAL_COUNTER' => false,
  290. 'SHOW_PAGESIZE' => false,
  291. 'SHOW_ACTION_PANEL' => false,
  292. 'ACTION_PANEL' => [],
  293. 'ALLOW_COLUMNS_SORT' => false,
  294. 'ALLOW_COLUMNS_RESIZE' => false,
  295. 'ALLOW_HORIZONTAL_SCROLL' => false,
  296. 'ALLOW_SORT' => false,
  297. 'ALLOW_PIN_HEADER' => false,
  298. 'AJAX_OPTION_HISTORY' => 'N'
  299. ]);
  300. $content = ob_get_contents();
  301. ob_end_clean();
  302. return $content;
  303. }
  304. }