BxBaseModTextDb.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 BaseText Base classes for text modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /*
  12. * Module database queries
  13. */
  14. class BxBaseModTextDb extends BxBaseModGeneralDb
  15. {
  16. public function __construct(&$oConfig)
  17. {
  18. parent::__construct($oConfig);
  19. }
  20. public function searchByAuthorTerm($iAuthor, $sTerm, $iLimit)
  21. {
  22. $CNF = &$this->_oConfig->CNF;
  23. if (empty($CNF['FIELDS_QUICK_SEARCH']))
  24. return array();
  25. $aBindings = array(
  26. 'author' => $iAuthor
  27. );
  28. $sWhere = '';
  29. foreach ($CNF['FIELDS_QUICK_SEARCH'] as $sField) {
  30. $aBindings[$sField] = '%' . $sTerm . '%';
  31. $sWhere .= " OR `c`.`$sField` LIKE :" . $sField;
  32. }
  33. $sOrderBy = $this->prepareAsString(" ORDER BY `c`.`added` DESC LIMIT ?", (int)$iLimit);
  34. $sQuery = "SELECT `c`.* FROM `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` AS `c` WHERE `c`.`" . $CNF['FIELD_AUTHOR'] . "`=:author AND (0 $sWhere)" . $sOrderBy;
  35. return $this->getAll($sQuery, $aBindings);
  36. }
  37. public function getEntriesNumByContext ($iProfileId)
  38. {
  39. $sQuery = $this->prepare ("SELECT COUNT(*) FROM `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` WHERE `" . $this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO'] . "` = ?", - $iProfileId);
  40. return $this->getOne($sQuery);
  41. }
  42. }
  43. /** @} */