BxReviewsDb.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 Reviews Reviews
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /*
  12. * Module database queries
  13. */
  14. class BxReviewsDb extends BxBaseModTextDb
  15. {
  16. function __construct(&$oConfig)
  17. {
  18. parent::__construct($oConfig);
  19. }
  20. public function getVotingOptionLKey($iOptionId) {
  21. return $this->getOne("SELECT `lkey` FROM `bx_reviews_voting_options` WHERE `id` = :id", [
  22. 'id' => $iOptionId,
  23. ]);
  24. }
  25. public function getVotingOptions() {
  26. return $this->getAll("SELECT `id`, `lkey` FROM `bx_reviews_voting_options` ORDER BY `order`");
  27. }
  28. public function getReviewedContent($iLimitFrom, $iLimitNum, $sOrderBy = 'avg_rating') {
  29. $CNF = &$this->_oConfig->CNF;
  30. if ($sOrderBy != 'avg_rating' && $sOrderBy != 'reviews_num') $sOrderBy = 'avg_rating';
  31. return $this->getAll("
  32. SELECT `bx_reviews_reviews`.`{$CNF['FIELD_REVIEWED_PROFILE']}`, AVG(NULLIF(`{$CNF['FIELD_VOTING_AVG']}`, 0)) AS `avg_rating`, COUNT(*) AS `reviews_num`
  33. FROM `bx_reviews_reviews`
  34. JOIN `sys_profiles` ON `sys_profiles`.`id` = `bx_reviews_reviews`.`{$CNF['FIELD_ID']}`
  35. WHERE `{$CNF['FIELD_REVIEWED_PROFILE']}` > 0 AND `sys_profiles`.`status` = 'active'
  36. GROUP BY `{$CNF['FIELD_REVIEWED_PROFILE']}`
  37. ORDER BY `{$sOrderBy}` DESC
  38. LIMIT :from, :num
  39. ", [
  40. 'from' => $iLimitFrom,
  41. 'num' => $iLimitNum,
  42. ]);
  43. }
  44. }
  45. /** @} */