BxDolModuleProxy.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 isMethodExists($s)
  50. {
  51. return method_exists($this->_oProxifiedObject, $s);
  52. }
  53. /**
  54. * Dirty fix for pass by reference to BxTimelineTemplate::getData
  55. */
  56. public function getData(&$aEvent, $aBrowseParams = array())
  57. {
  58. return $this->_oProxifiedObject->getData($aEvent, $aBrowseParams);
  59. }
  60. /**
  61. * Dirty fix for pass by reference to BxNtfsTemplate::getPost
  62. */
  63. public function getPost(&$aEvent, $aBrowseParams = array())
  64. {
  65. return $this->_oProxifiedObject->getPost($aEvent, $aBrowseParams);
  66. }
  67. /**
  68. * Dirty fix for pass by reference to BxNtfsTemplate::getNotificationEmail
  69. */
  70. public function getNotificationEmail(&$aEvent)
  71. {
  72. return $this->_oProxifiedObject->getNotificationEmail($aEvent);
  73. }
  74. /**
  75. * Dirty fix for pass by reference to BxNtfsTemplate::getNotificationPush
  76. */
  77. public function getNotificationPush(&$aEvent)
  78. {
  79. return $this->_oProxifiedObject->getNotificationPush($aEvent);
  80. }
  81. }
  82. /** @} */