BxBaseModProfileDb.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 DolphinModules
  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. $sQuery = $this->prepare ("UPDATE `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` SET `" . $sFieldPicture . "` = ? WHERE `id` = ? AND `author` = ?", $iPictureId, $iContentId, $iProfileId);
  29. return $this->res($sQuery);
  30. }
  31. public function searchByTerm($sTerm, $iLimit)
  32. {
  33. if (!$this->_oConfig->CNF['FIELDS_QUICK_SEARCH'])
  34. return array();
  35. $sWhere = '';
  36. foreach ($this->_oConfig->CNF['FIELDS_QUICK_SEARCH'] as $sField)
  37. $sWhere .= $this->prepare(" OR `c`.`$sField` LIKE ? ", '%' . $sTerm . '%');
  38. $sOrderBy = $this->prepare(" ORDER BY `added` DESC LIMIT ?", (int)$iLimit);
  39. $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);
  40. return $this->getAll($sQuery . " AND (0 $sWhere) " . $sOrderBy);
  41. }
  42. }
  43. /** @} */