BxAdsSource.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 Ads Ads
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxAdsSource extends BxDol
  12. {
  13. protected $_oModule;
  14. protected $_iProfile;
  15. protected $_iId;
  16. protected $_sName;
  17. protected $_sCaption;
  18. protected $_sPrefix;
  19. protected $_aOptions;
  20. public function __construct($iProfile, $aSource, &$oModule)
  21. {
  22. parent::__construct();
  23. $this->_oModule = $oModule;
  24. $this->_iProfile = $iProfile;
  25. if(empty($aSource) || !is_array($aSource) || strcmp($aSource['name'], $this->_sName) != 0)
  26. $this->_log("Unexpected value provided for the credentials");
  27. $this->_iId = (int)$aSource['id'];
  28. $this->_sName = $aSource['name'];
  29. $this->_sCaption = _t($aSource['caption']);
  30. $this->_sPrefix = $aSource['option_prefix'];
  31. $this->_aOptions = [];
  32. if(!empty($aSource['options']) && is_array($aSource['options']))
  33. $this->initOptions($aSource['options']);
  34. }
  35. public function initOptions($aOptions)
  36. {
  37. $this->_aOptions = $aOptions;
  38. }
  39. public function initOptionsByAuthor($iProfileId)
  40. {
  41. $this->_iProfileId = (int)$iProfileId;
  42. $aOptions = $this->_oModule->_oDb->getSourcesOptions($this->_iProfileId, $this->_iId);
  43. if(!empty($aOptions) && is_array($aOptions))
  44. $this->initOptions($aOptions);
  45. }
  46. public function getOption($sName)
  47. {
  48. if(substr($sName, 0, strlen($this->_sPrefix)) != $this->_sPrefix)
  49. $sName = $this->_sPrefix . $sName;
  50. return isset($this->_aOptions[$sName]) ? $this->_aOptions[$sName]['value'] : '';
  51. }
  52. public function getEntry($sId)
  53. {
  54. return [];
  55. }
  56. public function getOrders($aParams)
  57. {
  58. return [];
  59. }
  60. /**
  61. * Internal methods.
  62. */
  63. protected function _call($sRequest, $aParams, $sMethod = 'post-json', $aHeaders = [])
  64. {}
  65. protected function _log($sMessage, $bUseLog = false)
  66. {
  67. if($bUseLog) {
  68. //TODO: Use bx_log here with ERROR level
  69. }
  70. else
  71. throw new Exception($sMessage);
  72. return false;
  73. }
  74. }