BxBaseModProfileDb.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. $aBindings = array(
  28. $sFieldPicture => $iPictureId,
  29. 'id' => $iContentId
  30. );
  31. $sWhere = '';
  32. if ($iProfileId) {
  33. $aBindings['author'] = $iProfileId;
  34. $sWhere = " AND `author` = :author ";
  35. }
  36. $sQuery = "UPDATE `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` SET `" . $sFieldPicture . "` = :" . $sFieldPicture . " WHERE `id` = :id" . $sWhere;
  37. return $this->query($sQuery, $aBindings);
  38. }
  39. public function searchByTerm($sTerm, $iLimit)
  40. {
  41. if (!$this->_oConfig->CNF['FIELDS_QUICK_SEARCH'])
  42. return array();
  43. $aBindings = array(
  44. 'type' => $this->_oConfig->getName(),
  45. 'status' => BX_PROFILE_STATUS_ACTIVE
  46. );
  47. $sWhere = '';
  48. foreach ($this->_oConfig->CNF['FIELDS_QUICK_SEARCH'] as $sField) {
  49. $aBindings[$sField] = '%' . $sTerm . '%';
  50. $sWhere .= " OR `c`.`$sField` LIKE :" . $sField;
  51. }
  52. $sOrderBy = $this->prepareAsString(" ORDER BY `added` DESC LIMIT ?", (int)$iLimit);
  53. $sQuery = "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` = :type) WHERE `p`.`status` = :status AND (0 $sWhere)" . $sOrderBy;
  54. return $this->getAll($sQuery, $aBindings);
  55. }
  56. }
  57. /** @} */