1
0

BxDolModuleProxy.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 UnaCore UNA Core
  7. * @{
  8. */
  9. /**
  10. * Proxy class for module classes, now only module template class is proxied.
  11. * It's possible to override any module template method call by making a response
  12. * for 'module_template_method_call' alert.
  13. */
  14. class BxDolModuleProxy
  15. {
  16. private $_oProxifiedObject;
  17. private $_sObjectType;
  18. function __construct($sObjectType, $oProxifiedObject)
  19. {
  20. $this->_sObjectType = $sObjectType;
  21. $this->_oProxifiedObject = $oProxifiedObject;
  22. }
  23. public function __call($sMethodName, $aArguments)
  24. {
  25. if (is_callable(array($this->_oProxifiedObject, $sMethodName))) {
  26. // check if we need to include css&js files
  27. if ('module_template' == $this->_sObjectType && !empty($this->_oProxifiedObject->aMethodsToCallAddJsCss)) {
  28. foreach ($this->_oProxifiedObject->aMethodsToCallAddJsCss as $s) {
  29. if (0 === strpos($sMethodName, $s)) {
  30. $this->_oProxifiedObject->addCssJs();
  31. break;
  32. }
  33. }
  34. }
  35. $oModule = ('module_template' == $this->_sObjectType ? $this->_oProxifiedObject->getModule() : null);
  36. // make it possible to override the call or arguments
  37. $res = null;
  38. bx_alert($this->_sObjectType . '_method_call', $sMethodName, 0, 0, array('module' => $oModule, 'args' => &$aArguments, 'override_result' => &$res));
  39. if (null !== $res)
  40. return $res;
  41. // call original method
  42. return call_user_func_array(array($this->_oProxifiedObject, $sMethodName), $aArguments);
  43. }
  44. else {
  45. $sClass = get_class($this->_oProxifiedObject);
  46. trigger_error('Method ' . $sMethodName . ' was not found for the class ' . $sClass, E_USER_ERROR);
  47. }
  48. }
  49. public function getClassName()
  50. {
  51. return get_class($this->_oProxifiedObject);
  52. }
  53. public function isMethodExists($s)
  54. {
  55. return method_exists($this->_oProxifiedObject, $s);
  56. }
  57. /**
  58. * Dirty fix for pass by reference to BxTimelineTemplate::getData
  59. */
  60. public function getData(&$aEvent, $aBrowseParams = array())
  61. {
  62. return $this->_oProxifiedObject->getData($aEvent, $aBrowseParams);
  63. }
  64. /**
  65. * Dirty fix for pass by reference to BxNtfsTemplate::getPost
  66. */
  67. public function getPost(&$aEvent, $aBrowseParams = array())
  68. {
  69. return $this->_oProxifiedObject->getPost($aEvent, $aBrowseParams);
  70. }
  71. /**
  72. * Dirty fix for pass by reference to BxNtfsTemplate::getNotificationEmail
  73. */
  74. public function getNotificationEmail($iRecipient, &$aEvent)
  75. {
  76. return $this->_oProxifiedObject->getNotificationEmail($iRecipient, $aEvent);
  77. }
  78. /**
  79. * Dirty fix for pass by reference to BxNtfsTemplate::getNotificationPush
  80. */
  81. public function getNotificationPush($iRecipient, &$aEvent)
  82. {
  83. return $this->_oProxifiedObject->getNotificationPush($iRecipient, $aEvent);
  84. }
  85. }
  86. /** @} */