BxDolStudioBuilderPageQuery.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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`.`uri` AS `uri`,
  45. `tp`.`title_system` AS `title_system`,
  46. `tp`.`title` AS `title`,
  47. `tp`.`module` AS `module`,
  48. `tp`.`layout_id` AS `layout_id`,
  49. `tp`.`visible_for_levels` AS `visible_for_levels`,
  50. `tp`.`visible_for_levels_editable` AS `visible_for_levels_editable`,
  51. `tp`.`url` AS `url`,
  52. `tp`.`meta_description` AS `meta_description`,
  53. `tp`.`meta_keywords` AS `meta_keywords`,
  54. `tp`.`meta_robots` AS `meta_robots`,
  55. `tp`.`cache_lifetime` AS `cache_lifetime`,
  56. `tp`.`cache_editable` AS `cache_editable`,
  57. `tp`.`deletable` AS `deletable`,
  58. `tp`.`override_class_name` AS `override_class_name`,
  59. `tp`.`override_class_file` AS `override_class_file`" . $sSelectClause . "
  60. FROM `sys_objects_page` AS `tp` " . $sJoinClause . "
  61. WHERE 1 " . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause . " " . $sLimitClause;
  62. $aItems = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  63. if(!$bReturnCount)
  64. return !empty($aItems);
  65. return (int)$this->getOne("SELECT FOUND_ROWS()");
  66. }
  67. function updatePage($iId, $aFields) {
  68. $sSql = "UPDATE `sys_objects_page` SET `" . implode("`=?, `", array_keys($aFields)) . "`=? WHERE `id`=?";
  69. $sSql = call_user_func_array(array($this, 'prepare'), array_merge(array($sSql), array_values($aFields), array($iId)));
  70. return $this->query($sSql);
  71. }
  72. function deletePages($aParams) {
  73. $sWhereClause = "";
  74. switch($aParams['type']) {
  75. case 'by_id':
  76. $sWhereClause = $this->prepare("AND `tp`.`id`=? ", $aParams['value']);
  77. break;
  78. case 'by_object':
  79. $sWhereClause = $this->prepare("AND `tp`.`object`=? ", $aParams['value']);
  80. break;
  81. case 'all':
  82. break;
  83. }
  84. $sSql = "DELETE FROM `tp` USING `sys_objects_page` AS `tp` WHERE 1 " . $sWhereClause;
  85. return (int)$this->query($sSql) > 0;
  86. }
  87. function isUniqUri($sUri) {
  88. $sSql = $this->prepare("SELECT `id` FROM `sys_objects_page` WHERE `uri`=? LIMIT 1", $sUri);
  89. return (int)$this->getOne($sSql) <= 0;
  90. }
  91. function getLayouts($aParams, &$aItems, $bReturnCount = true) {
  92. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  93. $sSelectClause = $sJoinClause = $sWhereClause = $sGroupClause = $sOrderClause = $sLimitClause = "";
  94. if(!isset($aParams['order']) || empty($aParams['order']))
  95. $sOrderClause = "ORDER BY `tpl`.`id` ASC";
  96. switch($aParams['type']) {
  97. case 'by_id':
  98. $aMethod['name'] = 'getRow';
  99. $sWhereClause = $this->prepare("AND `tpl`.`id`=? ", $aParams['value']);
  100. break;
  101. case 'all':
  102. break;
  103. }
  104. $aMethod['params'][0] = "SELECT " . ($bReturnCount ? "SQL_CALC_FOUND_ROWS" : "") . "
  105. `tpl`.`id` AS `id`,
  106. `tpl`.`name` AS `name`,
  107. `tpl`.`icon` AS `icon`,
  108. `tpl`.`title` AS `title`,
  109. `tpl`.`template` AS `template`,
  110. `tpl`.`cells_number` AS `cells_number`" . $sSelectClause . "
  111. FROM `sys_pages_layouts` AS `tpl` " . $sJoinClause . "
  112. WHERE 1 " . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause . " " . $sLimitClause;
  113. $aItems = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  114. if(!$bReturnCount)
  115. return !empty($aItems);
  116. return (int)$this->getOne("SELECT FOUND_ROWS()");
  117. }
  118. function getDesignBoxes($aParams, &$aItems, $bReturnCount = true) {
  119. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  120. $sSelectClause = $sJoinClause = $sWhereClause = $sGroupClause = $sOrderClause = $sLimitClause = "";
  121. if(!isset($aParams['order']) || empty($aParams['order']))
  122. $sOrderClause = "ORDER BY `tpd`.`order` ASC";
  123. switch($aParams['type']) {
  124. case 'by_id':
  125. $aMethod['name'] = 'getRow';
  126. $sWhereClause = $this->prepare("AND `tpd`.`id`=? ", $aParams['value']);
  127. break;
  128. case 'ordered':
  129. $sWhereClause = "AND `tpd`.`order`<>0 ";
  130. break;
  131. case 'all':
  132. break;
  133. }
  134. $aMethod['params'][0] = "SELECT " . ($bReturnCount ? "SQL_CALC_FOUND_ROWS" : "") . "
  135. `tpd`.`id` AS `id`,
  136. `tpd`.`title` AS `title`,
  137. `tpd`.`template` AS `template`" . $sSelectClause . "
  138. FROM `sys_pages_design_boxes` AS `tpd` " . $sJoinClause . "
  139. WHERE 1 " . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause . " " . $sLimitClause;
  140. $aItems = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  141. if(!$bReturnCount)
  142. return !empty($aItems);
  143. return (int)$this->getOne("SELECT FOUND_ROWS()");
  144. }
  145. function getBlocks($aParams, &$aItems, $bReturnCount = true) {
  146. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  147. $sSelectClause = $sJoinClause = $sWhereClause = $sGroupClause = $sOrderClause = $sLimitClause = "";
  148. if(!isset($aParams['order']) || empty($aParams['order']))
  149. $sOrderClause = "ORDER BY `tpb`.`order` ASC";
  150. switch($aParams['type']) {
  151. case 'by_id':
  152. $aMethod['name'] = 'getRow';
  153. $sWhereClause = $this->prepare("AND `tpb`.`id`=? ", $aParams['value']);
  154. break;
  155. case 'skeleton_by_type':
  156. $aMethod['name'] = 'getRow';
  157. $sWhereClause = $this->prepare("AND `tpb`.`object`='' AND `tpb`.`module`=? AND `tpb`.`type`=? ", BX_DOL_STUDIO_BP_SKELETONS, $aParams['value']);
  158. break;
  159. case 'by_ids':
  160. $sWhereClause = "AND `tpb`.`id` IN ('" . implode("','", array_fill(0, count($aParams['value']), '?')) . "')";
  161. $sWhereClause = call_user_func_array(array($this, 'prepare'), array_merge(array($sWhereClause), $aParams['value']));
  162. break;
  163. case 'by_object':
  164. $sWhereClause = $this->prepare("AND `tpb`.`object`=?", $aParams['value']);
  165. break;
  166. case 'by_object_cell':
  167. $sWhereClause = $this->prepare("AND `tpb`.`object`=? AND `tpb`.`cell_id`=?", $aParams['object'], $aParams['cell']);
  168. break;
  169. case 'by_module_to_copy':
  170. $sWhereClause = $this->prepare("AND `tpb`.`module`=? AND `tpb`.`copyable`=1", $aParams['value']);
  171. if($aParams['value'] == BX_DOL_STUDIO_BP_SKELETONS)
  172. $sWhereClause .= " AND `tpb`.`object`=''";
  173. break;
  174. case 'counter_by_pages':
  175. $aMethod['name'] = 'getPairs';
  176. $aMethod['params'][1] = 'object';
  177. $aMethod['params'][2] = 'counter';
  178. $sSelectClause = ", COUNT(*) AS `counter`";
  179. $sGroupClause = "GROUP BY `tpb`.`object`";
  180. break;
  181. case 'all':
  182. break;
  183. }
  184. $aMethod['params'][0] = "SELECT " . ($bReturnCount ? "SQL_CALC_FOUND_ROWS" : "") . "
  185. `tpb`.`id` AS `id`,
  186. `tpb`.`object` AS `object`,
  187. `tpb`.`cell_id` AS `cell_id`,
  188. `tpb`.`module` AS `module`,
  189. `tpb`.`title` AS `title`,
  190. `tpb`.`designbox_id` AS `designbox_id`,
  191. `tpb`.`visible_for_levels` AS `visible_for_levels`,
  192. `tpb`.`type` AS `type`,
  193. `tpb`.`content` AS `content`,
  194. `tpb`.`deletable` AS `deletable`,
  195. `tpb`.`copyable` AS `copyable`,
  196. `tpb`.`order` AS `order`" . $sSelectClause . "
  197. FROM `sys_pages_blocks` AS `tpb` " . $sJoinClause . "
  198. WHERE 1 " . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause . " " . $sLimitClause;
  199. $aItems = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  200. if(!$bReturnCount)
  201. return !empty($aItems);
  202. return (int)$this->getOne("SELECT FOUND_ROWS()");
  203. }
  204. function insertBlock($aFields) {
  205. $aFields['order'] = $this->getBlockOrderMax($aFields['object']) + 1;
  206. $sSql = "INSERT INTO `sys_pages_blocks` SET `" . implode("`=?, `", array_keys($aFields)) . "`=?";
  207. $sSql = call_user_func_array(array($this, 'prepare'), array_merge(array($sSql), array_values($aFields)));
  208. return (int)$this->query($sSql) > 0;
  209. }
  210. function updateBlock($iId, $aFields) {
  211. $sSql = "UPDATE `sys_pages_blocks` SET `" . implode("`=?, `", array_keys($aFields)) . "`=? WHERE `id`=?";
  212. $sSql = call_user_func_array(array($this, 'prepare'), array_merge(array($sSql), array_values($aFields), array($iId)));
  213. return $this->query($sSql);
  214. }
  215. function deleteBlocks($aParams) {
  216. $sWhereClause = "";
  217. switch($aParams['type']) {
  218. case 'by_id':
  219. $sWhereClause = $this->prepare("AND `tpb`.`id`=? ", $aParams['value']);
  220. break;
  221. case 'by_object':
  222. $sWhereClause = $this->prepare("AND `tpb`.`object`=? ", $aParams['value']);
  223. break;
  224. case 'all':
  225. break;
  226. }
  227. $sSql = "DELETE FROM `tpb` USING `sys_pages_blocks` AS `tpb` WHERE 1 " . $sWhereClause;
  228. return (int)$this->query($sSql) > 0;
  229. }
  230. function resetBlocksByPage($sObject, $iCellId) {
  231. $sSql = $this->prepare("UPDATE `sys_pages_blocks` SET `cell_id`=? WHERE `object`=? AND `cell_id`>?", $iCellId, $sObject, $iCellId);
  232. return $this->query($sSql);
  233. }
  234. function getBlockOrderMax($sObject, $iCellId = 1) {
  235. $sSql = $this->prepare("SELECT MAX(`order`) FROM `sys_pages_blocks` WHERE `object`=? AND `cell_id`=? LIMIT 1", $sObject, $iCellId);
  236. return (int)$this->getOne($sSql);
  237. }
  238. function deleteImage($aParams) {
  239. $sWhereClause = "";
  240. switch($aParams['type']) {
  241. case 'by_id':
  242. $sWhereClause = $this->prepare("AND `tpb`.`id`=? ", $aParams['value']);
  243. break;
  244. case 'all':
  245. break;
  246. }
  247. $sSql = "DELETE FROM `tpb` USING `sys_pages_blocks` AS `tpb` WHERE 1 " . $sWhereClause;
  248. return (int)$this->query($sSql) > 0;
  249. }
  250. function getMenus() {
  251. $sSql = "SELECT `object`, `title` FROM `sys_objects_menu` WHERE 1";
  252. return $this->getPairs($sSql, 'object', 'title');
  253. }
  254. }
  255. /** @} */