BxDolEmbedQuery.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 getLocalInfoById ($iId)
  43. {
  44. return $this->getRow("SELECT * FROM `" . $this->_sTableData . "` WHERE `id` = :id", [
  45. 'id' => $iId
  46. ]);
  47. }
  48. public function getLocalUnprocessed ()
  49. {
  50. return $this->getAll("SELECT * FROM `" . $this->_sTableData . "` WHERE `data` = ''");
  51. }
  52. public function insertLocal ($sUrl, $sTheme, $sData = '')
  53. {
  54. return (int)$this->query("INSERT INTO `" . $this->_sTableData . "` (`url`, `theme`, `data`, `added`) VALUES (:url, :theme, :data, :added)", [
  55. 'url' => $sUrl,
  56. 'theme' => $sTheme,
  57. 'data' => $sData,
  58. 'added' => time(),
  59. ]) > 0 ? $this->lastId() : false;
  60. }
  61. public function updateLocal($aParamsSet, $aParamsWhere)
  62. {
  63. if(empty($aParamsSet) || empty($aParamsWhere))
  64. return false;
  65. return $this->query("UPDATE `{$this->_sTableData}` SET " . $this->arrayToSQL($aParamsSet) . " WHERE " . $this->arrayToSQL($aParamsWhere, " AND "));
  66. }
  67. public function deleteLocal($aParamsWhere)
  68. {
  69. if(empty($aParamsWhere))
  70. return false;
  71. return $this->query("DELETE FROM `{$this->_sTableData}` WHERE " . $this->arrayToSQL($aParamsWhere, " AND "));
  72. }
  73. }
  74. /** @} */