BxDolStudioBuilderPageQuery.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <?php defined('BX_DOL') or die('hack attempt');
  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 TridentStudio Trident Studio
  7. * @{
  8. */
  9. class BxDolStudioBuilderPageQuery extends BxDolStudioPageQuery
  10. {
  11. function __construct()
  12. {
  13. parent::__construct();
  14. }
  15. function getPages($aParams, &$aItems, $bReturnCount = true)
  16. {
  17. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  18. $sSelectClause = $sJoinClause = $sWhereClause = $sGroupClause = $sOrderClause = $sLimitClause = "";
  19. if(!isset($aParams['order']) || empty($aParams['order']))
  20. $sOrderClause = "ORDER BY `tp`.`object` ASC";
  21. switch($aParams['type']) {
  22. case 'by_id':
  23. $aMethod['name'] = 'getRow';
  24. $aMethod['params'][1] = array(
  25. 'id' => $aParams['value']
  26. );
  27. $sWhereClause = " AND `tp`.`id`=:id ";
  28. break;
  29. case 'by_object':
  30. $aMethod['name'] = 'getRow';
  31. $aMethod['params'][1] = array(
  32. 'object' => $aParams['value']
  33. );
  34. $sWhereClause = " AND `tp`.`object`=:object ";
  35. break;
  36. case 'by_object_full':
  37. $aMethod['name'] = 'getRow';
  38. $aMethod['params'][1] = array(
  39. 'object' => $aParams['value']
  40. );
  41. $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`";
  42. $sJoinClause = "LEFT JOIN `sys_pages_layouts` AS `tpl` ON `tp`.`layout_id`=`tpl`.`id`";
  43. $sWhereClause = " AND `tp`.`object`=:object ";
  44. break;
  45. case 'by_module':
  46. $aMethod['params'][1] = array(
  47. 'module' => $aParams['value']
  48. );
  49. $sWhereClause = " AND `tp`.`module`=:module ";
  50. break;
  51. case 'all':
  52. break;
  53. }
  54. $aMethod['params'][0] = "SELECT " . ($bReturnCount ? "SQL_CALC_FOUND_ROWS" : "") . "
  55. `tp`.`id` AS `id`,
  56. `tp`.`object` AS `object`,
  57. `tp`.`uri` AS `uri`,
  58. `tp`.`title_system` AS `title_system`,
  59. `tp`.`title` AS `title`,
  60. `tp`.`module` AS `module`,
  61. `tp`.`layout_id` AS `layout_id`,
  62. `tp`.`visible_for_levels` AS `visible_for_levels`,
  63. `tp`.`visible_for_levels_editable` AS `visible_for_levels_editable`,
  64. `tp`.`url` AS `url`,
  65. `tp`.`meta_description` AS `meta_description`,
  66. `tp`.`meta_keywords` AS `meta_keywords`,
  67. `tp`.`meta_robots` AS `meta_robots`,
  68. `tp`.`cache_lifetime` AS `cache_lifetime`,
  69. `tp`.`cache_editable` AS `cache_editable`,
  70. `tp`.`deletable` AS `deletable`,
  71. `tp`.`override_class_name` AS `override_class_name`,
  72. `tp`.`override_class_file` AS `override_class_file`" . $sSelectClause . "
  73. FROM `sys_objects_page` AS `tp` " . $sJoinClause . "
  74. WHERE 1 " . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause . " " . $sLimitClause;
  75. $aItems = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  76. if(!$bReturnCount)
  77. return !empty($aItems);
  78. return (int)$this->getOne("SELECT FOUND_ROWS()");
  79. }
  80. function updatePage($iId, $aFields)
  81. {
  82. $sSql = "UPDATE `sys_objects_page` SET `" . implode("`=?, `", array_keys($aFields)) . "`=? WHERE `id`=?";
  83. $sSql = call_user_func_array(array($this, 'prepare'), array_merge(array($sSql), array_values($aFields), array($iId)));
  84. return $this->query($sSql);
  85. }
  86. function deletePages($aParams)
  87. {
  88. $sWhereClause = "";
  89. switch($aParams['type']) {
  90. case 'by_id':
  91. $aMethod['params'][1] = array(
  92. 'id' => $aParams['value']
  93. );
  94. $sWhereClause = "AND `tp`.`id`=:id ";
  95. break;
  96. case 'by_object':
  97. $aMethod['params'][1] = array(
  98. 'object' => $aParams['value']
  99. );
  100. $sWhereClause = "AND `tp`.`object`=? ";
  101. break;
  102. case 'all':
  103. break;
  104. }
  105. $sSql = "DELETE FROM `tp` USING `sys_objects_page` AS `tp` WHERE 1 " . $sWhereClause;
  106. return (int)$this->query($sSql) > 0;
  107. }
  108. function isUniqUri($sUri)
  109. {
  110. $sSql = $this->prepare("SELECT `id` FROM `sys_objects_page` WHERE `uri`=? LIMIT 1", $sUri);
  111. return (int)$this->getOne($sSql) <= 0;
  112. }
  113. function getLayouts($aParams, &$aItems, $bReturnCount = true)
  114. {
  115. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  116. $sSelectClause = $sJoinClause = $sWhereClause = $sGroupClause = $sOrderClause = $sLimitClause = "";
  117. if(!isset($aParams['order']) || empty($aParams['order']))
  118. $sOrderClause = "ORDER BY `tpl`.`id` ASC";
  119. switch($aParams['type']) {
  120. case 'by_id':
  121. $aMethod['name'] = 'getRow';
  122. $aMethod['params'][1] = array(
  123. 'id' => $aParams['value']
  124. );
  125. $sWhereClause = "AND `tpl`.`id`=:id ";
  126. break;
  127. case 'all':
  128. break;
  129. }
  130. $aMethod['params'][0] = "SELECT " . ($bReturnCount ? "SQL_CALC_FOUND_ROWS" : "") . "
  131. `tpl`.`id` AS `id`,
  132. `tpl`.`name` AS `name`,
  133. `tpl`.`icon` AS `icon`,
  134. `tpl`.`title` AS `title`,
  135. `tpl`.`template` AS `template`,
  136. `tpl`.`cells_number` AS `cells_number`" . $sSelectClause . "
  137. FROM `sys_pages_layouts` AS `tpl` " . $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 getDesignBoxes($aParams, &$aItems, $bReturnCount = true)
  145. {
  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 `tpd`.`order` ASC";
  150. switch($aParams['type']) {
  151. case 'by_id':
  152. $aMethod['name'] = 'getRow';
  153. $aMethod['params'][1] = array(
  154. 'id' => $aParams['value']
  155. );
  156. $sWhereClause = "AND `tpd`.`id`=:id ";
  157. break;
  158. case 'ordered':
  159. $sWhereClause = "AND `tpd`.`order`<>0 ";
  160. break;
  161. case 'all':
  162. break;
  163. }
  164. $aMethod['params'][0] = "SELECT " . ($bReturnCount ? "SQL_CALC_FOUND_ROWS" : "") . "
  165. `tpd`.`id` AS `id`,
  166. `tpd`.`title` AS `title`,
  167. `tpd`.`template` AS `template`" . $sSelectClause . "
  168. FROM `sys_pages_design_boxes` AS `tpd` " . $sJoinClause . "
  169. WHERE 1 " . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause . " " . $sLimitClause;
  170. $aItems = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  171. if(!$bReturnCount)
  172. return !empty($aItems);
  173. return (int)$this->getOne("SELECT FOUND_ROWS()");
  174. }
  175. function getModulesWithCopyableBlocks()
  176. {
  177. $sSql = $this->prepare("SELECT
  178. `tm`.`name` AS `module`
  179. FROM `sys_modules` AS `tm`
  180. LEFT JOIN `sys_pages_blocks` AS `tpb` ON `tm`.`name`=`tpb`.`module`
  181. WHERE `tm`.`type`=? AND `tpb`.`copyable`=?
  182. GROUP BY `tm`.`name`", BX_DOL_MODULE_TYPE_MODULE, 1);
  183. return $this->getColumn($sSql);
  184. }
  185. function getBlocks($aParams, &$aItems, $bReturnCount = true)
  186. {
  187. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  188. $sSelectClause = $sJoinClause = $sWhereClause = $sGroupClause = $sOrderClause = $sLimitClause = "";
  189. if(!isset($aParams['order']) || empty($aParams['order']))
  190. $sOrderClause = "ORDER BY `tpb`.`order` ASC";
  191. switch($aParams['type']) {
  192. case 'by_id':
  193. $aMethod['name'] = 'getRow';
  194. $aMethod['params'][1] = array(
  195. 'id' => $aParams['value']
  196. );
  197. $sWhereClause = "AND `tpb`.`id`=:id ";
  198. break;
  199. case 'skeleton_by_type':
  200. $aMethod['name'] = 'getRow';
  201. $aMethod['params'][1] = array(
  202. 'module' => BX_DOL_STUDIO_BP_SKELETONS,
  203. 'type' => $aParams['value']
  204. );
  205. $sWhereClause = "AND `tpb`.`object`='' AND `tpb`.`module`=:module AND `tpb`.`type`=:type ";
  206. break;
  207. case 'by_ids':
  208. $sWhereClause = "AND `tpb`.`id` IN (" . $this->implode_escape($aParams['value']) . ")";
  209. break;
  210. case 'by_object':
  211. $aMethod['params'][1] = array(
  212. 'object' => $aParams['value']
  213. );
  214. $sWhereClause = "AND `tpb`.`object`=:object";
  215. break;
  216. case 'by_object_cell':
  217. $aMethod['params'][1] = array(
  218. 'object' => $aParams['object'],
  219. 'cell_id' => $aParams['cell']
  220. );
  221. $sWhereClause = "AND `tpb`.`object`=:object AND `tpb`.`cell_id`=:cell_id";
  222. break;
  223. case 'by_module_to_copy':
  224. $aMethod['params'][1] = array(
  225. 'module' => $aParams['value']
  226. );
  227. $sWhereClause = "AND `tpb`.`module`=:module AND `tpb`.`copyable`=1";
  228. if($aParams['value'] == BX_DOL_STUDIO_BP_SKELETONS)
  229. $sWhereClause .= " AND `tpb`.`object`=''";
  230. break;
  231. case 'counter_by_pages':
  232. $aMethod['name'] = 'getPairs';
  233. $aMethod['params'][1] = 'object';
  234. $aMethod['params'][2] = 'counter';
  235. $sSelectClause = ", COUNT(*) AS `counter`";
  236. $sGroupClause = "GROUP BY `tpb`.`object`";
  237. break;
  238. case 'all':
  239. break;
  240. }
  241. $aMethod['params'][0] = "SELECT " . ($bReturnCount ? "SQL_CALC_FOUND_ROWS" : "") . "
  242. `tpb`.`id` AS `id`,
  243. `tpb`.`object` AS `object`,
  244. `tpb`.`cell_id` AS `cell_id`,
  245. `tpb`.`module` AS `module`,
  246. `tpb`.`title_system` AS `title_system`,
  247. `tpb`.`title` AS `title`,
  248. `tpb`.`designbox_id` AS `designbox_id`,
  249. `tpb`.`hidden_on` AS `hidden_on`,
  250. `tpb`.`visible_for_levels` AS `visible_for_levels`,
  251. `tpb`.`type` AS `type`,
  252. `tpb`.`content` AS `content`,
  253. `tpb`.`deletable` AS `deletable`,
  254. `tpb`.`copyable` AS `copyable`,
  255. `tpb`.`active` AS `active`,
  256. `tpb`.`order` AS `order`" . $sSelectClause . "
  257. FROM `sys_pages_blocks` AS `tpb` " . $sJoinClause . "
  258. WHERE 1 " . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause . " " . $sLimitClause;
  259. $aItems = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  260. if(!$bReturnCount)
  261. return !empty($aItems);
  262. return (int)$this->getOne("SELECT FOUND_ROWS()");
  263. }
  264. function insertBlock($aFields)
  265. {
  266. $aFields['order'] = $this->getBlockOrderMax($aFields['object']) + 1;
  267. $sSql = "INSERT INTO `sys_pages_blocks` SET " . $this->arrayToSQL($aFields);
  268. return (int)$this->query($sSql) > 0;
  269. }
  270. function updateBlock($iId, $aFields)
  271. {
  272. $sSql = "UPDATE `sys_pages_blocks` SET " . $this->arrayToSQL($aFields) . " WHERE `id`=:id";
  273. return $this->query($sSql, array('id' => $iId));
  274. }
  275. function deleteBlocks($aParams)
  276. {
  277. $aBindings = array();
  278. $sWhereClause = "";
  279. switch($aParams['type']) {
  280. case 'by_id':
  281. $aBindings = array(
  282. 'id' => $aParams['value']
  283. );
  284. $sWhereClause = "AND `tpb`.`id`=:id ";
  285. break;
  286. case 'by_object':
  287. $aBindings = array(
  288. 'object' => $aParams['value']
  289. );
  290. $sWhereClause = "AND `tpb`.`object`=:object ";
  291. break;
  292. case 'all':
  293. break;
  294. }
  295. $sSql = "DELETE FROM `tpb` USING `sys_pages_blocks` AS `tpb` WHERE 1 " . $sWhereClause;
  296. return (int)$this->query($sSql, $aBindings) > 0;
  297. }
  298. function resetBlocksByPage($sObject, $iCellId)
  299. {
  300. $sSql = $this->prepare("UPDATE `sys_pages_blocks` SET `cell_id`=? WHERE `object`=? AND `cell_id`>?", $iCellId, $sObject, $iCellId);
  301. return $this->query($sSql);
  302. }
  303. function getBlockOrderMax($sObject, $iCellId = 1)
  304. {
  305. $sSql = $this->prepare("SELECT MAX(`order`) FROM `sys_pages_blocks` WHERE `object`=? AND `cell_id`=? LIMIT 1", $sObject, $iCellId);
  306. return (int)$this->getOne($sSql);
  307. }
  308. function deleteImage($aParams)
  309. {
  310. $sWhereClause = "";
  311. switch($aParams['type']) {
  312. case 'by_id':
  313. $aMethod['params'][1] = array(
  314. 'id' => $aParams['value']
  315. );
  316. $sWhereClause = "AND `tpb`.`id`=:id ";
  317. break;
  318. case 'all':
  319. break;
  320. }
  321. $sSql = "DELETE FROM `tpb` USING `sys_pages_blocks` AS `tpb` WHERE 1 " . $sWhereClause;
  322. return (int)$this->query($sSql) > 0;
  323. }
  324. function getMenus()
  325. {
  326. $sSql = "SELECT `object`, `title` FROM `sys_objects_menu` WHERE 1";
  327. return $this->getPairs($sSql, 'object', 'title');
  328. }
  329. }
  330. /** @} */