PageRenderTime 52ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://gitlab.com/alexprowars/bitrix
PHP | 175 lines | 123 code | 21 blank | 31 comment | 11 complexity | d6f1f32f4d6f2d2b9f93df819c24ee75 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. Bitrix\Sale\CrmSiteMaster\Tools\AgentChecker;
  9. Loc::loadMessages(__FILE__);
  10. /**
  11. * Class AgentStep
  12. * Step of check agents
  13. *
  14. * @package Bitrix\Sale\CrmSiteMaster\Steps
  15. */
  16. class AgentStep extends \CWizardStep
  17. {
  18. private $currentStepName = __CLASS__;
  19. /** @var \SaleCrmSiteMaster */
  20. private $component = null;
  21. /**
  22. * Check step errors
  23. */
  24. private function setStepErrors()
  25. {
  26. $errors = $this->component->getWizardStepErrors($this->currentStepName);
  27. if ($errors)
  28. {
  29. foreach ($errors as $error)
  30. {
  31. $this->SetError($error);
  32. }
  33. }
  34. }
  35. /**
  36. * Prepare next/prev buttons
  37. *
  38. * @throws \ReflectionException
  39. */
  40. private function prepareButtons()
  41. {
  42. $steps = $this->component->getSteps($this->currentStepName);
  43. $shortClassName = (new \ReflectionClass($this))->getShortName();
  44. if (isset($steps["NEXT_STEP"]))
  45. {
  46. $this->SetNextStep($steps["NEXT_STEP"]);
  47. $this->SetNextCaption(Loc::getMessage("SALE_CSM_WIZARD_".mb_strtoupper($shortClassName)."_NEXT"));
  48. }
  49. if (isset($steps["PREV_STEP"]))
  50. {
  51. $this->SetPrevStep($steps["PREV_STEP"]);
  52. $this->SetPrevCaption(Loc::getMessage("SALE_CSM_WIZARD_".mb_strtoupper($shortClassName)."_PREV"));
  53. }
  54. }
  55. /**
  56. * Initialization step id and title
  57. *
  58. * @throws \ReflectionException
  59. */
  60. public function initStep()
  61. {
  62. $this->component = $this->GetWizard()->GetVar("component");
  63. $this->SetStepID($this->currentStepName);
  64. $this->SetTitle(Loc::getMessage("SALE_CSM_WIZARD_AGENTSTEP_TITLE"));
  65. $this->prepareButtons();
  66. $this->setStepErrors();
  67. }
  68. /**
  69. * Show step content
  70. *
  71. * @return bool
  72. */
  73. public function showStep()
  74. {
  75. $errorType = $this->GetWizard()->GetVar("errorType");
  76. ob_start();
  77. if ($errorType === AgentChecker::ERROR_CODE_FAIL)
  78. {
  79. $error = $this->GetWizard()->GetVar("error");
  80. ?>
  81. <div class="ui-alert ui-alert-danger ui-alert-icon-danger">
  82. <span class="ui-alert-message"><?=$error?></span>
  83. </div>
  84. <div class="adm-crm-site-master-paragraph">
  85. <?=Loc::getMessage("SALE_CSM_WIZARD_AGENTSTEP_CHECKER_LINK", [
  86. "#LANG#" => LANGUAGE_ID
  87. ])?>
  88. </div>
  89. <?
  90. }
  91. elseif ($errorType === AgentChecker::ERROR_CODE_WARNING)
  92. {
  93. $warning = $this->GetWizard()->GetVar("warning");
  94. ?>
  95. <div class="ui-alert ui-alert-warning ui-alert-icon-warning">
  96. <span class="ui-alert-message"><?=$warning?></span>
  97. </div>
  98. <?
  99. }
  100. $content = ob_get_contents();
  101. ob_end_clean();
  102. $this->content = $content;
  103. return true;
  104. }
  105. /**
  106. * @return bool
  107. */
  108. public function onPostForm()
  109. {
  110. $wizard =& $this->GetWizard();
  111. if ($wizard->IsPrevButtonClick())
  112. {
  113. return false;
  114. }
  115. $errorType = $this->GetWizard()->GetVar("errorType");
  116. if (in_array($this->currentStepName, $this->component->arResult["WIZARD_STEPS"]) && $errorType === AgentChecker::ERROR_CODE_FAIL)
  117. {
  118. $this->GetWizard()->SetCurrentStep($this->currentStepName);
  119. }
  120. return true;
  121. }
  122. /**
  123. * @return array
  124. */
  125. public function showButtons()
  126. {
  127. ob_start();
  128. if ($this->GetPrevStepID() !== null)
  129. {
  130. ?>
  131. <input type="hidden" name="<?=$this->GetWizard()->prevStepHiddenID?>" value="<?=$this->GetPrevStepID()?>">
  132. <button type="submit" class="ui-btn ui-btn-primary" name="<?=$this->GetWizard()->prevButtonID?>">
  133. <?=$this->GetPrevCaption()?>
  134. </button>
  135. <?
  136. }
  137. if ($this->GetNextStepID() !== null)
  138. {
  139. ?>
  140. <input type="hidden" name="<?=$this->GetWizard()->nextStepHiddenID?>" value="<?=$this->GetNextStepID()?>">
  141. <button type="submit" class="ui-btn ui-btn-primary" name="<?=$this->GetWizard()->nextButtonID?>">
  142. <?=$this->GetNextCaption()?>
  143. </button>
  144. <?
  145. }
  146. $content = ob_get_contents();
  147. ob_end_clean();
  148. return [
  149. "CONTENT" => $content,
  150. "NEED_WRAPPER" => true,
  151. "CENTER" => true,
  152. ];
  153. }
  154. }