BxDolEmbedQuery.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 UnaCore UNA Core
  7. * @{
  8. */
  9. /**
  10. * Database queries for embed objects.
  11. * @see BxDolEmbed
  12. */
  13. class BxDolEmbedQuery extends BxDolFactoryObjectQuery
  14. {
  15. protected $_sTableData;
  16. static public function getObject($sObject)
  17. {
  18. return parent::getObjectFromTable($sObject, 'sys_objects_embeds', true);
  19. }
  20. static public function getObjects ()
  21. {
  22. return parent::getObjectsFromTable('sys_objects_embeds');
  23. }
  24. public function setParams($aParams)
  25. {
  26. $this->_sTableData = $aParams['table_data'] ?? '';
  27. }
  28. public function getLocal ($sUrl, $sTheme)
  29. {
  30. return $this->getOne("SELECT `data` FROM `" . $this->_sTableData . "` WHERE `url` = :url AND `theme` = :theme", [
  31. 'url' => $sUrl,
  32. 'theme' => $sTheme
  33. ]);
  34. }
  35. public function getLocalInfo ($sUrl, $sTheme)
  36. {
  37. return $this->getRow("SELECT * FROM `" . $this->_sTableData . "` WHERE `url` = :url AND `theme` = :theme", [
  38. 'url' => $sUrl,
  39. 'theme' => $sTheme
  40. ]);
  41. }
  42. public function getLocalUnprocessed ()
  43. {
  44. return $this->getAll("SELECT * FROM `" . $this->_sTableData . "` WHERE `data` = ''");
  45. }
  46. public function insertLocal ($sUrl, $sTheme, $sData = '')
  47. {
  48. return (int)$this->query("INSERT INTO `" . $this->_sTableData . "` (`url`, `theme`, `data`, `added`) VALUES (:url, :theme, :data, :added)", [
  49. 'url' => $sUrl,
  50. 'theme' => $sTheme,
  51. 'data' => $sData,
  52. 'added' => time(),
  53. ]) > 0 ? $this->lastId() : false;
  54. }
  55. public function updateLocal($aParamsSet, $aParamsWhere)
  56. {
  57. if(empty($aParamsSet) || empty($aParamsWhere))
  58. return false;
  59. return $this->query("UPDATE `{$this->_sTableData}` SET " . $this->arrayToSQL($aParamsSet) . " WHERE " . $this->arrayToSQL($aParamsWhere, " AND "));
  60. }
  61. public function deleteLocal($aParamsWhere)
  62. {
  63. if(empty($aParamsWhere))
  64. return false;
  65. return $this->query("DELETE FROM `{$this->_sTableData}` WHERE " . $this->arrayToSQL($aParamsWhere, " AND "));
  66. }
  67. }
  68. /** @} */