BxBaseModProfileDb.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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`, `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 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. }
  63. /** @} */