1
0

BxBaseModGroupsDb.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 BaseGroups Base classes for groups modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /*
  12. * Groups module database queries
  13. */
  14. class BxBaseModGroupsDb extends BxBaseModProfileDb
  15. {
  16. public function __construct(&$oConfig)
  17. {
  18. parent::__construct($oConfig);
  19. }
  20. public function updateAuthorById ($iContentId, $iProfileId)
  21. {
  22. $CNF = &$this->_oConfig->CNF;
  23. $sQuery = "UPDATE `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` SET `" . $CNF['FIELD_AUTHOR'] . "` = :author WHERE `" . $CNF['FIELD_ID'] . "` = :id";
  24. return $this->query($sQuery, array(
  25. 'id' => $iContentId,
  26. 'author' => $iProfileId,
  27. ));
  28. }
  29. public function toAdmins ($iGroupProfileId, $mixedFansIds)
  30. {
  31. if (is_array($mixedFansIds)) {
  32. foreach ($mixedFansIds as $iFanId)
  33. $this->toAdmins ($iFanId);
  34. return true;
  35. }
  36. $iFanId = (int)$mixedFansIds;
  37. $sQuery = $this->prepare("INSERT IGNORE INTO `" . $this->_oConfig->CNF['TABLE_ADMINS'] . "` SET `group_profile_id` = ?, `fan_id` = ?", $iGroupProfileId, $iFanId);
  38. if (!$this->res($sQuery))
  39. return false;
  40. $oModule = BxDolModule::getInstance($this->_oConfig->getName());
  41. if ($oModule && method_exists($oModule, 'onFanAddedToAdmins'))
  42. $oModule->onFanAddedToAdmins($iGroupProfileId, $iFanId);
  43. return true;
  44. }
  45. public function fromAdmins ($iGroupProfileId, $mixedFansIds)
  46. {
  47. if (is_array($mixedFansIds)) {
  48. foreach ($mixedFansIds as $iFanId)
  49. $this->fromAdmins ($iGroupProfileId, $iFanId);
  50. return true;
  51. }
  52. $iFanId = (int)$mixedFansIds;
  53. $sQuery = $this->prepare("DELETE FROM `" . $this->_oConfig->CNF['TABLE_ADMINS'] . "` WHERE `group_profile_id` = ? AND `fan_id` = ?", $iGroupProfileId, $iFanId);
  54. if (!$this->res($sQuery))
  55. return false;
  56. $oModule = BxDolModule::getInstance($this->_oConfig->getName());
  57. if ($oModule && method_exists($oModule, 'onFanRemovedFromAdmins'))
  58. $oModule->onFanRemovedFromAdmins($iGroupProfileId, $iFanId);
  59. return true;
  60. }
  61. public function deleteAdminsByGroupId ($iGroupProfileId)
  62. {
  63. $sQuery = $this->prepare("DELETE FROM `" . $this->_oConfig->CNF['TABLE_ADMINS'] . "` WHERE `group_profile_id` = ?", $iGroupProfileId);
  64. return $this->res($sQuery);
  65. }
  66. public function deleteAdminsByProfileId ($iProfileId)
  67. {
  68. $sQuery = $this->prepare("DELETE FROM `" . $this->_oConfig->CNF['TABLE_ADMINS'] . "` WHERE `fan_id` = ?", $iProfileId);
  69. return $this->res($sQuery);
  70. }
  71. public function isAdmin ($iGroupProfileId, $iFanId, $aDataEntry = array())
  72. {
  73. if (isset($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']]) && $iFanId == $aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']])
  74. return true;
  75. if (!isset($this->_oConfig->CNF['TABLE_ADMINS']))
  76. return false;
  77. $sQuery = $this->prepare("SELECT `id` FROM `" . $this->_oConfig->CNF['TABLE_ADMINS'] . "` WHERE `group_profile_id` = ? AND `fan_id` = ?", $iGroupProfileId, $iFanId);
  78. return $this->getOne($sQuery) ? true : false;
  79. }
  80. public function getAdmins ($iGroupProfileId)
  81. {
  82. $sQuery = $this->prepare("SELECT `fan_id` FROM `" . $this->_oConfig->CNF['TABLE_ADMINS'] . "` WHERE `group_profile_id` = ?", $iGroupProfileId);
  83. return $this->getColumn($sQuery);
  84. }
  85. }
  86. /** @} */