BxBaseScoreServices.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * System services related to Score.
  11. */
  12. class BxBaseScoreServices extends BxDol
  13. {
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. }
  18. /**
  19. * @page service Service Calls
  20. * @section bx_system_general System Services
  21. * @subsection bx_system_general-score Score
  22. * @subsubsection bx_system_general-do do
  23. *
  24. * @code bx_srv('system', 'do', [[...]], 'TemplScoreServices'); @endcode
  25. * @code {{~system:do:TemplScoreServices[[...]]~}} @endcode
  26. *
  27. * Performs Do (Up/Down) action
  28. * @param $aParams an array with necessary parameters
  29. *
  30. * @see BxBaseScoreServices::serviceDo
  31. */
  32. /**
  33. * @ref bx_system_general-do "do"
  34. * @api @ref bx_system_general-do "do"
  35. */
  36. public function serviceDo($aParams)
  37. {
  38. if(is_string($aParams))
  39. $aParams = json_decode($aParams, true);
  40. if(!$aParams['s'] || !$aParams['o'] || !$aParams['a'])
  41. return ['code' => BX_DOL_OBJECT_ERR_NOT_AVAILABLE];
  42. $oScore = BxDolScore::getObjectInstance($aParams['s'], $aParams['o']);
  43. if(!$oScore || !$oScore->isEnabled())
  44. return ['code' => BX_DOL_OBJECT_ERR_NOT_AVAILABLE];
  45. $aResult = $oScore->vote(['type' => $aParams['a']]);
  46. return (int)$aResult['code'] != 0 ? $aResult : $aResult['api'];
  47. }
  48. /**
  49. * @page service Service Calls
  50. * @section bx_system_general System Services
  51. * @subsection bx_system_general-score Score
  52. * @subsubsection bx_system_general-get_performed_by get_performed_by
  53. *
  54. * @code bx_srv('system', 'get_performed_by', [[...]], 'TemplScoreServices'); @endcode
  55. * @code {{~system:get_performed_by:TemplScoreServices[[...]]~}} @endcode
  56. *
  57. * Gets a list of PerformedBy users.
  58. * @param $aParams an array with necessary parameters
  59. *
  60. * @see BxBaseScoreServices::serviceGetPerformedBy
  61. */
  62. /**
  63. * @ref bx_system_general-get_performed_by "get_performed_by"
  64. * @api @ref bx_system_general-get_performed_by "get_performed_by"
  65. */
  66. public function serviceGetPerformedBy($aParams)
  67. {
  68. if(is_string($aParams))
  69. $aParams = json_decode($aParams, true);
  70. if(!$aParams['s'] || !$aParams['o'])
  71. return ['code' => BX_DOL_OBJECT_ERR_NOT_AVAILABLE];
  72. $oScore = BxDolScore::getObjectInstance($aParams['s'], $aParams['o']);
  73. if(!$oScore || !$oScore->isEnabled())
  74. return ['code' => BX_DOL_OBJECT_ERR_NOT_AVAILABLE];
  75. $aValues = $oScore->getQueryObject()->getPerformedBy($oScore->getId());
  76. $aTmplUsers = [];
  77. foreach($aValues as $aValue)
  78. $aTmplUsers[] = [
  79. 'author_data' => BxDolProfile::getData($aValue['id']),
  80. 'vote_type' => $aValue['vote_type'],
  81. 'vote_date' => $aValue['vote_date']
  82. ];
  83. return [
  84. 'performed_by' => $aTmplUsers
  85. ];
  86. }
  87. }
  88. /** @} */