BxSpacesDb.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. * @defdroup Spaces Spaces
  7. * @indroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Spaces module database queries
  13. */
  14. class BxSpacesDb extends BxBaseModGroupsDb
  15. {
  16. public function __construct(&$oConfig)
  17. {
  18. parent::__construct($oConfig);
  19. }
  20. public function searchByTermForParentSpace($iProfileId, $iContentId, $iLevelsLimit, $sTerm, $iLimit)
  21. {
  22. $CNF = &$this->_oConfig->CNF;
  23. if (!$CNF['FIELDS_QUICK_SEARCH'])
  24. return array();
  25. $aBindings = array(
  26. 'type' => $this->_oConfig->getName(),
  27. 'status' => BX_PROFILE_STATUS_ACTIVE,
  28. 'profile_id' => $iProfileId,
  29. 'content_id' => $iContentId
  30. );
  31. $sWhereClause = "";
  32. //--- Add levels limit
  33. if($iLevelsLimit > 0) {
  34. $aBindings['levels_limit'] = $iLevelsLimit;
  35. $sWhereClause .= "AND `c`.`" . $CNF['FIELD_LEVEL'] . "` < :levels_limit ";
  36. }
  37. //--- Add search by term
  38. $sWhereClauseTerm = "";
  39. foreach ($CNF['FIELDS_QUICK_SEARCH'] as $sField) {
  40. $aBindings[$sField] = '%' . $sTerm . '%';
  41. $sWhereClauseTerm .= " OR `c`.`$sField` LIKE :" . $sField;
  42. }
  43. $sWhereClause .= "AND (0 " . $sWhereClauseTerm . ") ";
  44. $sOrderByClause = $this->prepareAsString("ORDER BY `added` DESC LIMIT ?", (int)$iLimit);
  45. $sQuery = "SELECT `c`.`id` AS `content_id`, `p`.`account_id`, `p`.`id` AS `profile_id`, `p`.`status` AS `profile_status` FROM `" . $CNF['TABLE_ENTRIES'] . "` AS `c` INNER JOIN `sys_profiles` AS `p` ON (`p`.`content_id` = `c`.`id` AND `p`.`type` = :type) WHERE `p`.`status` = :status AND (`c`.`" . $CNF['FIELD_ALLOW_VIEW_TO'] . "` = 3 OR `c`.`" . $CNF['FIELD_AUTHOR'] . "` = :profile_id) AND `c`.`" . $CNF['FIELD_ID'] . "` <> :content_id " . $sWhereClause . $sOrderByClause;
  46. return $this->getAll($sQuery, $aBindings);
  47. }
  48. public function getCountEntriesByParent ($iParent)
  49. {
  50. $aBindings = array(
  51. 'content_id' => $iParent,
  52. 'type' => $this->_oConfig->getName()
  53. );
  54. $sQuery = "SELECT COUNT(*) FROM `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` WHERE `" . $this->_oConfig->CNF['FIELD_PARENT'] . "` IN (SELECT `id` FROM `sys_profiles` WHERE `content_id` = :content_id AND `type` = :type)";
  55. return $this->getOne($sQuery, $aBindings);
  56. }
  57. public function getLevelById ($iContentId)
  58. {
  59. $CNF = &$this->_oConfig->CNF;
  60. return $this->getOne("SELECT `" . $CNF['FIELD_LEVEL'] . "` FROM `" . $CNF['TABLE_ENTRIES'] . "` WHERE `" . $CNF['FIELD_ID'] . "` = :content_id", array(
  61. 'content_id' => $iContentId
  62. ));
  63. }
  64. public function getChildEntriesIdByProfileId ($iParentPid)
  65. {
  66. $CNF = &$this->_oConfig->CNF;
  67. return $this->getColumn("SELECT `id` FROM `sys_profiles` WHERE `content_id` IN (SELECT `" . $CNF['FIELD_ID'] . "` FROM `" . $CNF['TABLE_ENTRIES'] . "` WHERE `" . $CNF['FIELD_PARENT'] . "` = :parent_pid AND `" . $CNF['FIELD_STATUS'] . "` = 'active' AND `" . $CNF['FIELD_STATUS_ADMIN'] . "` = 'active') AND `type` = :type AND `status`='active'", [
  68. 'parent_pid' => $iParentPid,
  69. 'type' => $this->_oConfig->getName()
  70. ]);
  71. }
  72. }
  73. /** @} */