| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup BaseGroups Base classes for groups modules
- * @ingroup UnaModules
- *
- * @{
- */
- /*
- * Groups module database queries
- */
- class BxBaseModGroupsDb extends BxBaseModProfileDb
- {
- public function __construct(&$oConfig)
- {
- parent::__construct($oConfig);
- }
- public function updateAuthorById ($iContentId, $iProfileId)
- {
- $CNF = &$this->_oConfig->CNF;
- $sQuery = "UPDATE `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` SET `" . $CNF['FIELD_AUTHOR'] . "` = :author WHERE `" . $CNF['FIELD_ID'] . "` = :id";
- return $this->query($sQuery, array(
- 'id' => $iContentId,
- 'author' => $iProfileId,
- ));
- }
- public function toAdmins ($iGroupProfileId, $mixedFansIds)
- {
- if (is_array($mixedFansIds)) {
- foreach ($mixedFansIds as $iFanId)
- $this->toAdmins ($iFanId);
- return true;
- }
- $iFanId = (int)$mixedFansIds;
- $sQuery = $this->prepare("INSERT IGNORE INTO `" . $this->_oConfig->CNF['TABLE_ADMINS'] . "` SET `group_profile_id` = ?, `fan_id` = ?", $iGroupProfileId, $iFanId);
- if (!$this->res($sQuery))
- return false;
- $oModule = BxDolModule::getInstance($this->_oConfig->getName());
- if ($oModule && method_exists($oModule, 'onFanAddedToAdmins'))
- $oModule->onFanAddedToAdmins($iGroupProfileId, $iFanId);
- return true;
- }
- public function fromAdmins ($iGroupProfileId, $mixedFansIds)
- {
- if (is_array($mixedFansIds)) {
- foreach ($mixedFansIds as $iFanId)
- $this->fromAdmins ($iFanId);
- return true;
- }
- $iFanId = (int)$mixedFansIds;
- $sQuery = $this->prepare("DELETE FROM `" . $this->_oConfig->CNF['TABLE_ADMINS'] . "` WHERE `group_profile_id` = ? AND `fan_id` = ?", $iGroupProfileId, $iFanId);
- if (!$this->res($sQuery))
- return false;
- $oModule = BxDolModule::getInstance($this->_oConfig->getName());
- if ($oModule && method_exists($oModule, 'onFanRemovedFromAdmins'))
- $oModule->onFanRemovedFromAdmins($iGroupProfileId, $iFanId);
-
- return true;
- }
- public function deleteAdminsByGroupId ($iGroupProfileId)
- {
- $sQuery = $this->prepare("DELETE FROM `" . $this->_oConfig->CNF['TABLE_ADMINS'] . "` WHERE `group_profile_id` = ?", $iGroupProfileId);
- return $this->res($sQuery);
- }
- public function deleteAdminsByProfileId ($iProfileId)
- {
- $sQuery = $this->prepare("DELETE FROM `" . $this->_oConfig->CNF['TABLE_ADMINS'] . "` WHERE `fan_id` = ?", $iProfileId);
- return $this->res($sQuery);
- }
- public function isAdmin ($iGroupProfileId, $iFanId, $aDataEntry = array())
- {
- if (isset($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']]) && $iFanId == $aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']])
- return true;
- $sQuery = $this->prepare("SELECT `id` FROM `" . $this->_oConfig->CNF['TABLE_ADMINS'] . "` WHERE `group_profile_id` = ? AND `fan_id` = ?", $iGroupProfileId, $iFanId);
- return $this->getOne($sQuery) ? true : false;
- }
- public function getAdmins ($iGroupProfileId)
- {
- $sQuery = $this->prepare("SELECT `fan_id` FROM `" . $this->_oConfig->CNF['TABLE_ADMINS'] . "` WHERE `group_profile_id` = ?", $iGroupProfileId);
- return $this->getColumn($sQuery);
- }
- }
- /** @} */
|