BxBaseModProfileDb.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. /*
  12. * Profile based module database queries
  13. */
  14. class BxBaseModProfileDb 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 `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);
  23. return $this->getRow($sQuery);
  24. }
  25. public function updateContentPictureById($iContentId, $iProfileId, $iPictureId, $sFieldPicture)
  26. {
  27. $sWhere = '';
  28. if ($iProfileId)
  29. $sWhere = $this->prepare (" AND `author` = ? ", $iProfileId);
  30. $sQuery = $this->prepare ("UPDATE `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` SET `" . $sFieldPicture . "` = ? WHERE `id` = ?", $iPictureId, $iContentId);
  31. return $this->res($sQuery . $sWhere);
  32. }
  33. public function searchByTerm($sTerm, $iLimit)
  34. {
  35. if (!$this->_oConfig->CNF['FIELDS_QUICK_SEARCH'])
  36. return array();
  37. $sWhere = '';
  38. foreach ($this->_oConfig->CNF['FIELDS_QUICK_SEARCH'] as $sField)
  39. $sWhere .= $this->prepare(" OR `c`.`$sField` LIKE ? ", '%' . $sTerm . '%');
  40. $sOrderBy = $this->prepare(" ORDER BY `added` DESC LIMIT ?", (int)$iLimit);
  41. $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);
  42. return $this->getAll($sQuery . " AND (0 $sWhere) " . $sOrderBy);
  43. }
  44. }
  45. /** @} */