BxDolStudioBuilderPageQuery.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <?php
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinStudio Dolphin Studio
  7. * @{
  8. */
  9. defined('BX_DOL') or die('hack attempt');
  10. bx_import('BxDolStudioPageQuery');
  11. class BxDolStudioBuilderPageQuery extends BxDolStudioPageQuery {
  12. function __construct() {
  13. parent::BxDolStudioPageQuery();
  14. }
  15. function getPages($aParams, &$aItems, $bReturnCount = true) {
  16. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  17. $sSelectClause = $sJoinClause = $sWhereClause = $sGroupClause = $sOrderClause = $sLimitClause = "";
  18. if(!isset($aParams['order']) || empty($aParams['order']))
  19. $sOrderClause = "ORDER BY `tp`.`object` ASC";
  20. switch($aParams['type']) {
  21. case 'by_id':
  22. $aMethod['name'] = 'getRow';
  23. $sWhereClause = $this->prepare(" AND `tp`.`id`=? ", $aParams['value']);
  24. break;
  25. case 'by_object':
  26. $aMethod['name'] = 'getRow';
  27. $sWhereClause = $this->prepare(" AND `tp`.`object`=? ", $aParams['value']);
  28. break;
  29. case 'by_object_full':
  30. $aMethod['name'] = 'getRow';
  31. $sSelectClause = ", `tpl`.`name` AS `layout_name`, `tpl`.`icon` AS `layout_icon`, `tpl`.`title` AS `layout_title`, `tpl`.`template` AS `layout_template`, `tpl`.`cells_number` AS `layout_cells_number`";
  32. $sJoinClause = "LEFT JOIN `sys_pages_layouts` AS `tpl` ON `tp`.`layout_id`=`tpl`.`id`";
  33. $sWhereClause = $this->prepare(" AND `tp`.`object`=? ", $aParams['value']);
  34. break;
  35. case 'by_module':
  36. $sWhereClause = $this->prepare(" AND `tp`.`module`=? ", $aParams['value']);
  37. break;
  38. case 'all':
  39. break;
  40. }
  41. $aMethod['params'][0] = "SELECT " . ($bReturnCount ? "SQL_CALC_FOUND_ROWS" : "") . "
  42. `tp`.`id` AS `id`,
  43. `tp`.`object` AS `object`,
  44. `tp`.`title_system` AS `title_system`,
  45. `tp`.`title` AS `title`,
  46. `tp`.`module` AS `module`,
  47. `tp`.`layout_id` AS `layout_id`,
  48. `tp`.`visible_for_levels` AS `visible_for_levels`,
  49. `tp`.`visible_for_levels_editable` AS `visible_for_levels_editable`,
  50. `tp`.`url` AS `url`,
  51. `tp`.`meta_description` AS `meta_description`,
  52. `tp`.`meta_keywords` AS `meta_keywords`,
  53. `tp`.`meta_robots` AS `meta_robots`,
  54. `tp`.`cache_lifetime` AS `cache_lifetime`,
  55. `tp`.`cache_editable` AS `cache_editable`,
  56. `tp`.`deletable` AS `deletable`,
  57. `tp`.`override_class_name` AS `override_class_name`,
  58. `tp`.`override_class_file` AS `override_class_file`" . $sSelectClause . "
  59. FROM `sys_objects_page` AS `tp` " . $sJoinClause . "
  60. WHERE 1 " . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause . " " . $sLimitClause;
  61. $aItems = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  62. if(!$bReturnCount)
  63. return !empty($aItems);
  64. return (int)$this->getOne("SELECT FOUND_ROWS()");
  65. }
  66. function updatePage($iId, $aFields) {
  67. $sSql = "UPDATE `sys_objects_page` SET `" . implode("`=?, `", array_keys($aFields)) . "`=? WHERE `id`=?";
  68. $sSql = call_user_func_array(array($this, 'prepare'), array_merge(array($sSql), array_values($aFields), array($iId)));
  69. return $this->query($sSql);
  70. }
  71. function deletePages($aParams) {
  72. $sWhereClause = "";
  73. switch($aParams['type']) {
  74. case 'by_id':
  75. $sWhereClause = $this->prepare("AND `tp`.`id`=? ", $aParams['value']);
  76. break;
  77. case 'by_object':
  78. $sWhereClause = $this->prepare("AND `tp`.`object`=? ", $aParams['value']);
  79. break;
  80. case 'all':
  81. break;
  82. }
  83. $sSql = "DELETE FROM `tp` USING `sys_objects_page` AS `tp` WHERE 1 " . $sWhereClause;
  84. return (int)$this->query($sSql) > 0;
  85. }
  86. function isUniqUri($sUri) {
  87. $sSql = $this->prepare("SELECT `id` FROM `sys_objects_page` WHERE `uri`=? LIMIT 1", $sUri);
  88. return (int)$this->getOne($sSql) <= 0;
  89. }
  90. function getLayouts($aParams, &$aItems, $bReturnCount = true) {
  91. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  92. $sSelectClause = $sJoinClause = $sWhereClause = $sGroupClause = $sOrderClause = $sLimitClause = "";
  93. if(!isset($aParams['order']) || empty($aParams['order']))
  94. $sOrderClause = "ORDER BY `tpl`.`id` ASC";
  95. switch($aParams['type']) {
  96. case 'by_id':
  97. $aMethod['name'] = 'getRow';
  98. $sWhereClause = $this->prepare("AND `tpl`.`id`=? ", $aParams['value']);
  99. break;
  100. case 'all':
  101. break;
  102. }
  103. $aMethod['params'][0] = "SELECT " . ($bReturnCount ? "SQL_CALC_FOUND_ROWS" : "") . "
  104. `tpl`.`id` AS `id`,
  105. `tpl`.`name` AS `name`,
  106. `tpl`.`icon` AS `icon`,
  107. `tpl`.`title` AS `title`,
  108. `tpl`.`template` AS `template`,
  109. `tpl`.`cells_number` AS `cells_number`" . $sSelectClause . "
  110. FROM `sys_pages_layouts` AS `tpl` " . $sJoinClause . "
  111. WHERE 1 " . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause . " " . $sLimitClause;
  112. $aItems = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  113. if(!$bReturnCount)
  114. return !empty($aItems);
  115. return (int)$this->getOne("SELECT FOUND_ROWS()");
  116. }
  117. function getDesignBoxes($aParams, &$aItems, $bReturnCount = true) {
  118. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  119. $sSelectClause = $sJoinClause = $sWhereClause = $sGroupClause = $sOrderClause = $sLimitClause = "";
  120. if(!isset($aParams['order']) || empty($aParams['order']))
  121. $sOrderClause = "ORDER BY `tpd`.`order` ASC";
  122. switch($aParams['type']) {
  123. case 'by_id':
  124. $aMethod['name'] = 'getRow';
  125. $sWhereClause = $this->prepare("AND `tpd`.`id`=? ", $aParams['value']);
  126. break;
  127. case 'ordered':
  128. $sWhereClause = "AND `tpd`.`order`<>0 ";
  129. break;
  130. case 'all':
  131. break;
  132. }
  133. $aMethod['params'][0] = "SELECT " . ($bReturnCount ? "SQL_CALC_FOUND_ROWS" : "") . "
  134. `tpd`.`id` AS `id`,
  135. `tpd`.`title` AS `title`,
  136. `tpd`.`template` AS `template`" . $sSelectClause . "
  137. FROM `sys_pages_design_boxes` AS `tpd` " . $sJoinClause . "
  138. WHERE 1 " . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause . " " . $sLimitClause;
  139. $aItems = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  140. if(!$bReturnCount)
  141. return !empty($aItems);
  142. return (int)$this->getOne("SELECT FOUND_ROWS()");
  143. }
  144. function getBlocks($aParams, &$aItems, $bReturnCount = true) {
  145. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  146. $sSelectClause = $sJoinClause = $sWhereClause = $sGroupClause = $sOrderClause = $sLimitClause = "";
  147. if(!isset($aParams['order']) || empty($aParams['order']))
  148. $sOrderClause = "ORDER BY `tpb`.`order` ASC";
  149. switch($aParams['type']) {
  150. case 'by_id':
  151. $aMethod['name'] = 'getRow';
  152. $sWhereClause = $this->prepare("AND `tpb`.`id`=? ", $aParams['value']);
  153. break;
  154. case 'skeleton_by_type':
  155. $aMethod['name'] = 'getRow';
  156. $sWhereClause = $this->prepare("AND `tpb`.`object`='' AND `tpb`.`module`=? AND `tpb`.`type`=? ", BX_DOL_STUDIO_BP_SKELETONS, $aParams['value']);
  157. break;
  158. case 'by_ids':
  159. $sWhereClause = "AND `tpb`.`id` IN ('" . implode("','", array_fill(0, count($aParams['value']), '?')) . "')";
  160. $sWhereClause = call_user_func_array(array($this, 'prepare'), array_merge(array($sWhereClause), $aParams['value']));
  161. break;
  162. case 'by_object':
  163. $sWhereClause = $this->prepare("AND `tpb`.`object`=?", $aParams['value']);
  164. break;
  165. case 'by_object_cell':
  166. $sWhereClause = $this->prepare("AND `tpb`.`object`=? AND `tpb`.`cell_id`=?", $aParams['object'], $aParams['cell']);
  167. break;
  168. case 'by_module_to_copy':
  169. $sWhereClause = $this->prepare("AND `tpb`.`module`=? AND `tpb`.`copyable`=1", $aParams['value']);
  170. if($aParams['value'] == BX_DOL_STUDIO_BP_SKELETONS)
  171. $sWhereClause .= " AND `tpb`.`object`=''";
  172. break;
  173. case 'counter_by_pages':
  174. $aMethod['name'] = 'getPairs';
  175. $aMethod['params'][1] = 'object';
  176. $aMethod['params'][2] = 'counter';
  177. $sSelectClause = ", COUNT(*) AS `counter`";
  178. $sGroupClause = "GROUP BY `tpb`.`object`";
  179. break;
  180. case 'all':
  181. break;
  182. }
  183. $aMethod['params'][0] = "SELECT " . ($bReturnCount ? "SQL_CALC_FOUND_ROWS" : "") . "
  184. `tpb`.`id` AS `id`,
  185. `tpb`.`object` AS `object`,
  186. `tpb`.`cell_id` AS `cell_id`,
  187. `tpb`.`module` AS `module`,
  188. `tpb`.`title` AS `title`,
  189. `tpb`.`designbox_id` AS `designbox_id`,
  190. `tpb`.`visible_for_levels` AS `visible_for_levels`,
  191. `tpb`.`type` AS `type`,
  192. `tpb`.`content` AS `content`,
  193. `tpb`.`deletable` AS `deletable`,
  194. `tpb`.`copyable` AS `copyable`,
  195. `tpb`.`order` AS `order`" . $sSelectClause . "
  196. FROM `sys_pages_blocks` AS `tpb` " . $sJoinClause . "
  197. WHERE 1 " . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause . " " . $sLimitClause;
  198. $aItems = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  199. if(!$bReturnCount)
  200. return !empty($aItems);
  201. return (int)$this->getOne("SELECT FOUND_ROWS()");
  202. }
  203. function insertBlock($aFields) {
  204. $aFields['order'] = $this->getBlockOrderMax($aFields['object']) + 1;
  205. $sSql = "INSERT INTO `sys_pages_blocks` SET `" . implode("`=?, `", array_keys($aFields)) . "`=?";
  206. $sSql = call_user_func_array(array($this, 'prepare'), array_merge(array($sSql), array_values($aFields)));
  207. return (int)$this->query($sSql) > 0;
  208. }
  209. function updateBlock($iId, $aFields) {
  210. $sSql = "UPDATE `sys_pages_blocks` SET `" . implode("`=?, `", array_keys($aFields)) . "`=? WHERE `id`=?";
  211. $sSql = call_user_func_array(array($this, 'prepare'), array_merge(array($sSql), array_values($aFields), array($iId)));
  212. return $this->query($sSql);
  213. }
  214. function deleteBlocks($aParams) {
  215. $sWhereClause = "";
  216. switch($aParams['type']) {
  217. case 'by_id':
  218. $sWhereClause = $this->prepare("AND `tpb`.`id`=? ", $aParams['value']);
  219. break;
  220. case 'by_object':
  221. $sWhereClause = $this->prepare("AND `tpb`.`object`=? ", $aParams['value']);
  222. break;
  223. case 'all':
  224. break;
  225. }
  226. $sSql = "DELETE FROM `tpb` USING `sys_pages_blocks` AS `tpb` WHERE 1 " . $sWhereClause;
  227. return (int)$this->query($sSql) > 0;
  228. }
  229. function resetBlocksByPage($sObject, $iCellId) {
  230. $sSql = $this->prepare("UPDATE `sys_pages_blocks` SET `cell_id`=? WHERE `object`=? AND `cell_id`>?", $iCellId, $sObject, $iCellId);
  231. return $this->query($sSql);
  232. }
  233. function getBlockOrderMax($sObject, $iCellId = 1) {
  234. $sSql = $this->prepare("SELECT MAX(`order`) FROM `sys_pages_blocks` WHERE `object`=? AND `cell_id`=? LIMIT 1", $sObject, $iCellId);
  235. return (int)$this->getOne($sSql);
  236. }
  237. function deleteImage($aParams) {
  238. $sWhereClause = "";
  239. switch($aParams['type']) {
  240. case 'by_id':
  241. $sWhereClause = $this->prepare("AND `tpb`.`id`=? ", $aParams['value']);
  242. break;
  243. case 'all':
  244. break;
  245. }
  246. $sSql = "DELETE FROM `tpb` USING `sys_pages_blocks` AS `tpb` WHERE 1 " . $sWhereClause;
  247. return (int)$this->query($sSql) > 0;
  248. }
  249. function getMenus() {
  250. $sSql = "SELECT `object`, `title` FROM `sys_objects_menu` WHERE 1";
  251. return $this->getPairs($sSql, 'object', 'title');
  252. }
  253. }
  254. /** @} */