BxBaseModGeneralDb.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup BaseGeneral Base classes for modules
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. /*
  12. * Module database queries
  13. */
  14. class BxBaseModGeneralDb extends BxDolModuleDb
  15. {
  16. protected $_oConfig;
  17. public function __construct(&$oConfig)
  18. {
  19. parent::__construct($oConfig);
  20. $this->_oConfig = $oConfig;
  21. }
  22. public function getEntriesByAuthor ($iProfileId)
  23. {
  24. $sQuery = $this->prepare ("SELECT * FROM `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` WHERE `" . $this->_oConfig->CNF['FIELD_AUTHOR'] . "` = ?", $iProfileId);
  25. return $this->getAll($sQuery);
  26. }
  27. public function getEntriesNumByAuthor ($iProfileId)
  28. {
  29. $sQuery = $this->prepare ("SELECT COUNT(*) FROM `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` WHERE `" . $this->_oConfig->CNF['FIELD_AUTHOR'] . "` = ?", $iProfileId);
  30. return $this->getOne($sQuery);
  31. }
  32. public function alterFulltextIndex ()
  33. {
  34. $CNF = $this->_oConfig->CNF;
  35. $bFulltextIndex = false;
  36. $aIndexes = $this->getAll("SHOW INDEXES FROM `bx_persons_data`");
  37. foreach ($aIndexes as $r) {
  38. if ($CNF['TABLE_ENTRIES_FULLTEXT'] == $r['Key_name']) {
  39. $bFulltextIndex = true;
  40. break;
  41. }
  42. }
  43. if ($bFulltextIndex)
  44. $this->pdoExec("ALTER TABLE `" . $CNF['TABLE_ENTRIES'] . "` DROP INDEX `" . $CNF['TABLE_ENTRIES_FULLTEXT'] . "`");
  45. if (!($aFields = explode(',', getParam($CNF['PARAM_SEARCHABLE_FIELDS']))))
  46. return true;
  47. $sFields = '';
  48. foreach ($aFields as $s)
  49. $sFields .= "`$s`,";
  50. return $this->pdoExec("ALTER TABLE `" . $CNF['TABLE_ENTRIES'] . "` ADD FULLTEXT `" . $CNF['TABLE_ENTRIES_FULLTEXT'] . "` (" . trim($sFields, ', ') . ")");
  51. }
  52. }
  53. /** @} */