BxDolPageQuery.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 pages.
  11. * @see BxDolPage
  12. */
  13. class BxDolPageQuery extends BxDolDb
  14. {
  15. protected $_aObject;
  16. public function __construct($aObject)
  17. {
  18. parent::__construct();
  19. $this->_aObject = $aObject;
  20. }
  21. static public function getPageObject ($sObject)
  22. {
  23. $oDb = BxDolDb::getInstance();
  24. $sQuery = $oDb->prepare("SELECT `o`.*, `l`.`template`, `l`.`cells_number` FROM `sys_objects_page` AS `o` INNER JOIN `sys_pages_layouts` AS `l` ON (`l`.`id` = `o`.`layout_id`) WHERE `o`.`object` = ?", $sObject);
  25. $aObject = $oDb->getRow($sQuery);
  26. if (!$aObject || !is_array($aObject))
  27. return false;
  28. return $aObject;
  29. }
  30. static public function getPageObjectNameByURI($sURI, $sModule = false)
  31. {
  32. $oDb = BxDolDb::getInstance();
  33. $a = array('uri' => $sURI);
  34. $sQuery = "SELECT `object` FROM `sys_objects_page` WHERE `uri` = :uri";
  35. if ($sModule) {
  36. $a['module'] = $sModule;
  37. $sQuery .= " AND `module` = :module";
  38. }
  39. return $oDb->getOne($sQuery, $a);
  40. }
  41. static public function getPageTriggers($sTriggerName)
  42. {
  43. $oDb = BxDolDb::getInstance();
  44. $sQuery = $oDb->prepare("SELECT * FROM `sys_pages_blocks` WHERE `object` = ? ORDER BY `id` ASC", $sTriggerName);
  45. return $oDb->getAll($sQuery);
  46. }
  47. static public function addPageBlockToPage($aPageBlock)
  48. {
  49. $oDb = BxDolDb::getInstance();
  50. if (empty($aPageBlock['object']))
  51. return false;
  52. // check if block already exists,
  53. // so the block position will not reset when it's unnecessary
  54. $sQuery = $oDb->prepare("SELECT `id` FROM `sys_pages_blocks` WHERE `object` = ? AND `type` = ? AND `title` = ?", $aPageBlock['object'], $aPageBlock['type'], $aPageBlock['title']);
  55. if ($oDb->getOne($sQuery))
  56. return true;
  57. // get order
  58. if (empty($aPageBlock['order'])) {
  59. $iCellId = !empty($aPageBlock['cell_id']) ? (int)$aPageBlock['cell_id'] : 1;
  60. $sQuery = $oDb->prepare("SELECT `order` FROM `sys_pages_blocks` WHERE `object` = ? AND `cell_id` = ? AND `active` = 1 ORDER BY `order` DESC LIMIT 1", $aPageBlock['object'], $iCellId);
  61. $aPageBlock['order'] = (int)$oDb->getOne($sQuery) + 1;
  62. }
  63. // add new block
  64. unset($aPageBlock['id']);
  65. return $oDb->query("INSERT INTO `sys_pages_blocks` SET " . $oDb->arrayToSQL($aPageBlock));
  66. }
  67. static public function getPageType($iId)
  68. {
  69. return BxDolDb::getInstance()->getRow("SELECT * FROM `sys_pages_types` WHERE `id`=:id LIMIT 1", array(
  70. 'id' => $iId
  71. ));
  72. }
  73. public function getPageBlocks()
  74. {
  75. $aRet = array ();
  76. for ($i = 1 ; $i <= $this->_aObject['cells_number'] ; ++$i) {
  77. $sQuery = $this->prepare("SELECT * FROM `sys_pages_blocks` WHERE `object` = ? AND `cell_id` = ? AND `active` = 1 ORDER BY `order` ASC", $this->_aObject['object'], $i);
  78. $aRet['cell_'.$i] = $this->getAll($sQuery);
  79. }
  80. return $aRet;
  81. }
  82. public function getPageBlock($iBlockId)
  83. {
  84. $sQuery = $this->prepare("SELECT * FROM `sys_pages_blocks` WHERE `object` = ? AND `id` = ?", $this->_aObject['object'], $iBlockId);
  85. return $this->getRow($sQuery);
  86. }
  87. public function getPageBlockContent($iId)
  88. {
  89. $sQuery = $this->prepare("SELECT `content` FROM `sys_pages_blocks` WHERE `id` = ?", $iId);
  90. return $this->getOne($sQuery);
  91. }
  92. public function getPageBlockContentPlaceholder($iId)
  93. {
  94. $sQuery = $this->prepare("SELECT `id`, `module`, `template` FROM `sys_pages_content_placeholders` WHERE `id` = ?", $iId);
  95. return $this->getRow($sQuery);
  96. }
  97. }
  98. /** @} */