BxBaseModProfileDb.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 BaseProfile Base classes for profile modules
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxBaseModGeneralDb');
  12. /*
  13. * Profile based module database queries
  14. */
  15. class BxBaseModProfileDb extends BxBaseModGeneralDb
  16. {
  17. public function __construct(&$oConfig)
  18. {
  19. parent::__construct($oConfig);
  20. }
  21. public function getContentInfoById ($iContentId)
  22. {
  23. $sQuery = $this->prepare ("SELECT `c`.*, `p`.`account_id`, `p`.`id` AS `profile_id`, `p`.`status` AS `profile_status` FROM `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` AS `c` INNER JOIN `sys_profiles` AS `p` ON (`p`.`content_id` = `c`.`id` AND `p`.`type` = ?) WHERE `c`.`id` = ?", $this->_oConfig->getName(), $iContentId);
  24. return $this->getRow($sQuery);
  25. }
  26. public function updateContentPictureById($iContentId, $iProfileId, $iPictureId, $sFieldPicture)
  27. {
  28. $sWhere = '';
  29. if ($iProfileId)
  30. $sWhere = $this->prepare (" AND `author` = ? ", $iProfileId);
  31. $sQuery = $this->prepare ("UPDATE `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` SET `" . $sFieldPicture . "` = ? WHERE `id` = ?", $iPictureId, $iContentId);
  32. return $this->res($sQuery . $sWhere);
  33. }
  34. public function searchByTerm($sTerm, $iLimit)
  35. {
  36. if (!$this->_oConfig->CNF['FIELDS_QUICK_SEARCH'])
  37. return array();
  38. $sWhere = '';
  39. foreach ($this->_oConfig->CNF['FIELDS_QUICK_SEARCH'] as $sField)
  40. $sWhere .= $this->prepare(" OR `c`.`$sField` LIKE ? ", '%' . $sTerm . '%');
  41. $sOrderBy = $this->prepare(" ORDER BY `added` DESC LIMIT ?", (int)$iLimit);
  42. $sQuery = $this->prepare("SELECT `c`.`id` AS `content_id`, `p`.`account_id`, `p`.`id` AS `profile_id`, `p`.`status` AS `profile_status` FROM `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` AS `c` INNER JOIN `sys_profiles` AS `p` ON (`p`.`content_id` = `c`.`id` AND `p`.`type` = ?) WHERE `p`.`status` = ?", $this->_oConfig->getName(), BX_PROFILE_STATUS_ACTIVE);
  43. return $this->getAll($sQuery . " AND (0 $sWhere) " . $sOrderBy);
  44. }
  45. }
  46. /** @} */