BxBaseVoteServices.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 Votes.
  11. */
  12. class BxBaseVoteServices extends BxDol
  13. {
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. }
  18. public function serviceDo($aParams)
  19. {
  20. if(is_string($aParams))
  21. $aParams = json_decode($aParams, true);
  22. if(!$aParams['s'] || !$aParams['o'])
  23. return ['code' => 1];
  24. $oVote = BxDolVote::getObjectInstance($aParams['s'], $aParams['o']);
  25. if(!$oVote)
  26. return ['code' => BX_DOL_OBJECT_ERR_NOT_AVAILABLE];
  27. $aResult = $oVote->vote($aParams);
  28. if((int)$aResult['code'] != 0)
  29. return $aResult;
  30. return [
  31. 'reaction' => $aResult['reaction'],
  32. 'icon' => !empty($aResult['label_emoji']) ? $aResult['label_emoji'] : '',
  33. 'counter' => $oVote->getVote()
  34. ];
  35. }
  36. }
  37. /** @} */