1
0

BxGitHubModule.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 BxGitHubModule extends BxBaseModGeneralModule
  12. {
  13. protected $_iLoggedId;
  14. protected $_oApi;
  15. public function __construct($aModule)
  16. {
  17. parent::__construct($aModule);
  18. $this->_oConfig->init($this->_oDb);
  19. $this->_iLoggedId = bx_get_logged_profile_id();
  20. bx_import('Api', $aModule);
  21. $this->_oApi = new BxGitHubApi($this);
  22. $this->_oApi->init($this->_iLoggedId);
  23. }
  24. /**
  25. * ACTION METHODS
  26. */
  27. /**
  28. * SERVICE METHODS
  29. */
  30. public function serviceGetBlockSettings($iProfileId = 0)
  31. {
  32. if(!$iProfileId || ($iProfileId != $this->_iLoggedId && !$this->_isAdministrator()))
  33. $iProfileId = $this->_iLoggedId;
  34. if(!$iProfileId)
  35. return MsgBox(_t('_sys_txt_access_denied'));
  36. return $this->_oTemplate->getBlockSettings($iProfileId);
  37. }
  38. public function serviceGetRepositories($sUsername, $iProfileId = 0)
  39. {
  40. if($iProfileId && $iProfileId != $this->_iLoggedId)
  41. $this->_oApi->init($iProfileId);
  42. return $this->_oApi->getRepositories($sUsername);
  43. }
  44. public function serviceGetIssues($sUsername, $sRepository, $sState = 'open')
  45. {
  46. return $this->_oApi->getIssues($sUsername, $sRepository, $sState);
  47. }
  48. public function serviceGetIssue($sUsername, $sRepository, $iIssue)
  49. {
  50. return $this->_oApi->getIssue($sUsername, $sRepository, $iIssue);
  51. }
  52. public function serviceCreateIssue($sUsername, $sRepository, $sTitle, $sText = '', $aParams = [], $iProfileId = 0)
  53. {
  54. if($iProfileId && $iProfileId != $this->_iLoggedId)
  55. $this->_oApi->init($iProfileId);
  56. return $this->_oApi->createIssue($sUsername, $sRepository, $sTitle, $sText, $aParams);
  57. }
  58. public function serviceUpdateIssue($sUsername, $sRepository, $iIssue, $aParams, $iProfileId = 0)
  59. {
  60. if($iProfileId && $iProfileId != $this->_iLoggedId)
  61. $this->_oApi->init($iProfileId);
  62. return $this->_oApi->updateIssue($sUsername, $sRepository, $iIssue, $aParams);
  63. }
  64. public function serviceCloseIssue($sUsername, $sRepository, $iIssue, $iProfileId = 0)
  65. {
  66. if($iProfileId && $iProfileId != $this->_iLoggedId)
  67. $this->_oApi->init($iProfileId);
  68. return $this->_oApi->updateIssue($sUsername, $sRepository, $iIssue, ['state' => 'closed']);
  69. }
  70. public function serviceReopenIssue($sUsername, $sRepository, $iIssue, $iProfileId = 0)
  71. {
  72. if($iProfileId && $iProfileId != $this->_iLoggedId)
  73. $this->_oApi->init($iProfileId);
  74. return $this->_oApi->updateIssue($sUsername, $sRepository, $iIssue, ['state' => 'open']);
  75. }
  76. public function serviceCreateLabel($sUsername, $sRepository, $mixedLabel, $iProfileId = 0)
  77. {
  78. if($iProfileId && $iProfileId != $this->_iLoggedId)
  79. $this->_oApi->init($iProfileId);
  80. return $this->_oApi->createLabel($sUsername, $sRepository, $mixedLabel);
  81. }
  82. public function serviceAddLabel($sUsername, $sRepository, $iIssue, $mixedLabel, $iProfileId = 0)
  83. {
  84. if($iProfileId && $iProfileId != $this->_iLoggedId)
  85. $this->_oApi->init($iProfileId);
  86. return $this->_oApi->addLabel($sUsername, $sRepository, $iIssue, $mixedLabel);
  87. }
  88. /*
  89. * COMMON METHODS
  90. */
  91. }
  92. /** @} */