BxBaseModProfileDb.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 BaseProfile Base classes for profile modules
  7. * @ingroup UnaModules
  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`, `a`.`email` AS `profile_email`, `a`.`ip` AS `profile_ip`, `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` = ?) INNER JOIN `sys_accounts` AS `a` ON (`p`.`account_id` = `a`.`id`) WHERE `c`.`id` = ?", $this->_oConfig->getName(), $iContentId);
  23. return $this->getRow($sQuery);
  24. }
  25. public function resetContentPictureByFileId($iFileId, $sFieldPicture)
  26. {
  27. return $this->query("UPDATE `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` SET `" . $sFieldPicture . "` = 0 WHERE `" . $sFieldPicture . "` = :file", [
  28. 'file' => $iFileId,
  29. ]);
  30. }
  31. public function updateContentPictureById($iContentId, $iProfileId, $iPictureId, $sFieldPicture)
  32. {
  33. $aBindings = array(
  34. 'pic' => $iPictureId,
  35. 'id' => $iContentId
  36. );
  37. $sWhere = '';
  38. if ($iProfileId) {
  39. $aBindings['author'] = $iProfileId;
  40. $sWhere = " AND `author` = :author ";
  41. }
  42. $sQuery = "UPDATE `" . $this->_oConfig->CNF['TABLE_ENTRIES'] . "` SET `" . $sFieldPicture . "` = :pic WHERE `id` = :id" . $sWhere;
  43. return $this->query($sQuery, $aBindings);
  44. }
  45. public function searchByTerm($sTerm, $iLimit)
  46. {
  47. if (!$this->_oConfig->CNF['FIELDS_QUICK_SEARCH'])
  48. return array();
  49. $aBindings = array(
  50. 'type' => $this->_oConfig->getName(),
  51. 'status' => BX_PROFILE_STATUS_ACTIVE
  52. );
  53. $sWhere = '';
  54. foreach ($this->_oConfig->CNF['FIELDS_QUICK_SEARCH'] as $sField) {
  55. $aBindings[$sField] = '%' . $sTerm . '%';
  56. $sWhere .= " OR `c`.`$sField` LIKE :" . $sField;
  57. }
  58. $sOrderBy = $this->prepareAsString(" ORDER BY `added` DESC LIMIT ?", (int)$iLimit);
  59. $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;
  60. return $this->getAll($sQuery, $aBindings);
  61. }
  62. protected function _getEntriesBySearchIds($aParams, &$aMethod, &$sSelectClause, &$sJoinClause, &$sWhereClause, &$sOrderClause, &$sLimitClause)
  63. {
  64. $CNF = &$this->_oConfig->CNF;
  65. if(isset($aParams['search_params']['online'])) {
  66. $aMethod['params'][1] = array_merge($aMethod['params'][1], array(
  67. 'online_type' => $this->_oConfig->getName(),
  68. 'online_time' => (int)getParam('sys_account_online_time')
  69. ));
  70. $sJoinClause .= "
  71. LEFT JOIN `sys_profiles` AS `tp` ON `" . $CNF['TABLE_ENTRIES'] . "`.`" . $CNF['FIELD_ID'] . "`=`tp`.`content_id` AND `tp`.`type`=:online_type
  72. INNER JOIN `sys_accounts` AS `ta` ON `tp`.`account_id`=`ta`.`id`
  73. INNER JOIN `sys_sessions` AS `ts` ON `tp`.`account_id`=`ts`.`user_id`
  74. ";
  75. $sWhereClause .= " AND `ta`.`profile_id`=`tp`.`id` AND `ts`.`date` > (UNIX_TIMESTAMP() - 60 * :online_time)";
  76. unset($aParams['search_params']['online']);
  77. }
  78. parent::_getEntriesBySearchIds($aParams, $aMethod, $sSelectClause, $sJoinClause, $sWhereClause, $sOrderClause, $sLimitClause);
  79. }
  80. }
  81. /** @} */