BxDolEmbedQuery.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 getLocalUnprocessed ()
  36. {
  37. return $this->getAll("SELECT * FROM `" . $this->_sTableData . "` WHERE `data` = ''");
  38. }
  39. public function insertLocal ($sUrl, $sTheme, $sData = '')
  40. {
  41. return (int)$this->query("INSERT INTO `" . $this->_sTableData . "` (`url`, `theme`, `data`, `added`) VALUES (:url, :theme, :data, :added)", [
  42. 'url' => $sUrl,
  43. 'theme' => $sTheme,
  44. 'data' => $sData,
  45. 'added' => time(),
  46. ]) > 0 ? $this->lastId() : false;
  47. }
  48. public function updateLocal($aParamsSet, $aParamsWhere)
  49. {
  50. if(empty($aParamsSet) || empty($aParamsWhere))
  51. return false;
  52. return $this->query("UPDATE `{$this->_sTableData}` SET " . $this->arrayToSQL($aParamsSet) . " WHERE " . $this->arrayToSQL($aParamsWhere, " AND "));
  53. }
  54. }
  55. /** @} */