PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

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