BxBaseModTextDb.php 1.4 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 getContentInfoById ($iContentId)
  21. {
  22. $sQuery = $this->prepare ("SELECT * FROM `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` WHERE `" . $this->_oConfig->CNF['FIELD_ID'] . "` = ?", $iContentId);
  23. return $this->getRow($sQuery);
  24. }
  25. public function searchByAuthorTerm($iAuthor, $sTerm, $iLimit)
  26. {
  27. $CNF = &$this->_oConfig->CNF;
  28. if (empty($CNF['FIELDS_QUICK_SEARCH']))
  29. return array();
  30. $aBindings = array(
  31. 'author' => $iAuthor
  32. );
  33. $sWhere = '';
  34. foreach ($CNF['FIELDS_QUICK_SEARCH'] as $sField) {
  35. $aBindings[$sField] = '%' . $sTerm . '%';
  36. $sWhere .= " OR `c`.`$sField` LIKE :" . $sField;
  37. }
  38. $sOrderBy = $this->prepareAsString(" ORDER BY `c`.`added` DESC LIMIT ?", (int)$iLimit);
  39. $sQuery = "SELECT `c`.* FROM `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` AS `c` WHERE `c`.`" . $CNF['FIELD_AUTHOR'] . "`=:author AND (0 $sWhere)" . $sOrderBy;
  40. return $this->getAll($sQuery, $aBindings);
  41. }
  42. }
  43. /** @} */