BxGitHubTemplate.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup GitHub GitHub
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxGitHubTemplate extends BxDolModuleTemplate
  12. {
  13. public function __construct(&$oConfig, &$oDb)
  14. {
  15. parent::__construct($oConfig, $oDb);
  16. }
  17. public function getBlockAuthorize($iAppId, $iProfileId)
  18. {
  19. $CNF = &$this->_oConfig->CNF;
  20. $oApp = $this->_oModule->getObjectApp($iAppId);
  21. if(!$oApp)
  22. return '';
  23. $bAuthorized = $this->_oDb->isAuthorization($iProfileId, $iAppId);
  24. return $this->parseHtmlByName('authorize.html', [
  25. 'bx_if:show_authorize' => [
  26. 'condition' => !$bAuthorized,
  27. 'content' => [
  28. 'authorize_url' => $oApp->getUrlAuthorize()
  29. ]
  30. ],
  31. 'bx_if:show_authorized' => [
  32. 'condition' => $bAuthorized,
  33. 'content' => [
  34. 'manage_url' => BxDolPermalinks::getInstance()->permalink($CNF['URL_SETTINGS'])
  35. ]
  36. ]
  37. ]);
  38. }
  39. public function getBlockSettingsClient($iProfileId)
  40. {
  41. $CNF = &$this->_oConfig->CNF;
  42. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_SETTINGS'], $CNF['OBJECT_FORM_SETTINGS_DISPLAY_EDIT'], $this);
  43. if(!$oForm)
  44. return MsgBox(_t('_sys_txt_error_occured'));
  45. $aSettings = $this->_oDb->getSettings(['sample' => 'profile_id', 'profile_id' => $iProfileId]);
  46. $bSettings = !empty($aSettings) && is_array($aSettings);
  47. $sResultTimer = 0;
  48. $sResultMessage = '';
  49. $oForm->initChecker($aSettings);
  50. if($oForm->isSubmittedAndValid()) {
  51. if((!$bSettings && (int)$oForm->insert(['profile_id' => $iProfileId]) > 0) || ($bSettings && $oForm->update($aSettings['id']) !== false)) {
  52. $sResultTimer = 3;
  53. $sResultMessage = '_bx_github_msg_save_settings';
  54. }
  55. else
  56. $sResultMessage = '_bx_github_err_save_settings';
  57. }
  58. return (!empty($sResultMessage) ? MsgBox(_t($sResultMessage), $sResultTimer) : '') . $oForm->getCode();
  59. }
  60. }
  61. /** @} */