BxDolStudioBuilderPageQuery.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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 ('" . implode("','", array_fill(0, count($aParams['value']), '?')) . "')";
  209. $sWhereClause = call_user_func_array(array($this, 'prepare'), array_merge(array($sWhereClause), $aParams['value']));
  210. break;
  211. case 'by_object':
  212. $aMethod['params'][1] = array(
  213. 'object' => $aParams['value']
  214. );
  215. $sWhereClause = "AND `tpb`.`object`=?";
  216. break;
  217. case 'by_object_cell':
  218. $aMethod['params'][1] = array(
  219. 'object' => $aParams['object'],
  220. 'cell_id' => $aParams['cell']
  221. );
  222. $sWhereClause = "AND `tpb`.`object`=:object AND `tpb`.`cell_id`=:cell_id";
  223. break;
  224. case 'by_module_to_copy':
  225. $aMethod['params'][1] = array(
  226. 'module' => $aParams['value']
  227. );
  228. $sWhereClause = "AND `tpb`.`module`=:module AND `tpb`.`copyable`=1";
  229. if($aParams['value'] == BX_DOL_STUDIO_BP_SKELETONS)
  230. $sWhereClause .= " AND `tpb`.`object`=''";
  231. break;
  232. case 'counter_by_pages':
  233. $aMethod['name'] = 'getPairs';
  234. $aMethod['params'][1] = 'object';
  235. $aMethod['params'][2] = 'counter';
  236. $sSelectClause = ", COUNT(*) AS `counter`";
  237. $sGroupClause = "GROUP BY `tpb`.`object`";
  238. break;
  239. case 'all':
  240. break;
  241. }
  242. $aMethod['params'][0] = "SELECT " . ($bReturnCount ? "SQL_CALC_FOUND_ROWS" : "") . "
  243. `tpb`.`id` AS `id`,
  244. `tpb`.`object` AS `object`,
  245. `tpb`.`cell_id` AS `cell_id`,
  246. `tpb`.`module` AS `module`,
  247. `tpb`.`title_system` AS `title_system`,
  248. `tpb`.`title` AS `title`,
  249. `tpb`.`designbox_id` AS `designbox_id`,
  250. `tpb`.`hidden_on` AS `hidden_on`,
  251. `tpb`.`visible_for_levels` AS `visible_for_levels`,
  252. `tpb`.`type` AS `type`,
  253. `tpb`.`content` AS `content`,
  254. `tpb`.`deletable` AS `deletable`,
  255. `tpb`.`copyable` AS `copyable`,
  256. `tpb`.`active` AS `active`,
  257. `tpb`.`order` AS `order`" . $sSelectClause . "
  258. FROM `sys_pages_blocks` AS `tpb` " . $sJoinClause . "
  259. WHERE 1 " . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause . " " . $sLimitClause;
  260. $aItems = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  261. if(!$bReturnCount)
  262. return !empty($aItems);
  263. return (int)$this->getOne("SELECT FOUND_ROWS()");
  264. }
  265. function insertBlock($aFields)
  266. {
  267. $aFields['order'] = $this->getBlockOrderMax($aFields['object']) + 1;
  268. $sSql = "INSERT INTO `sys_pages_blocks` SET `" . implode("`=?, `", array_keys($aFields)) . "`=?";
  269. $sSql = call_user_func_array(array($this, 'prepare'), array_merge(array($sSql), array_values($aFields)));
  270. return (int)$this->query($sSql) > 0;
  271. }
  272. function updateBlock($iId, $aFields)
  273. {
  274. $sSql = "UPDATE `sys_pages_blocks` SET `" . implode("`=?, `", array_keys($aFields)) . "`=? WHERE `id`=?";
  275. $sSql = call_user_func_array(array($this, 'prepare'), array_merge(array($sSql), array_values($aFields), array($iId)));
  276. return $this->query($sSql);
  277. }
  278. function deleteBlocks($aParams)
  279. {
  280. $sWhereClause = "";
  281. switch($aParams['type']) {
  282. case 'by_id':
  283. $aMethod['params'][1] = array(
  284. 'id' => $aParams['value']
  285. );
  286. $sWhereClause = "AND `tpb`.`id`=:id ";
  287. break;
  288. case 'by_object':
  289. $aMethod['params'][1] = array(
  290. 'object' => $aParams['value']
  291. );
  292. $sWhereClause = "AND `tpb`.`object`=:object ";
  293. break;
  294. case 'all':
  295. break;
  296. }
  297. $sSql = "DELETE FROM `tpb` USING `sys_pages_blocks` AS `tpb` WHERE 1 " . $sWhereClause;
  298. return (int)$this->query($sSql) > 0;
  299. }
  300. function resetBlocksByPage($sObject, $iCellId)
  301. {
  302. $sSql = $this->prepare("UPDATE `sys_pages_blocks` SET `cell_id`=? WHERE `object`=? AND `cell_id`>?", $iCellId, $sObject, $iCellId);
  303. return $this->query($sSql);
  304. }
  305. function getBlockOrderMax($sObject, $iCellId = 1)
  306. {
  307. $sSql = $this->prepare("SELECT MAX(`order`) FROM `sys_pages_blocks` WHERE `object`=? AND `cell_id`=? LIMIT 1", $sObject, $iCellId);
  308. return (int)$this->getOne($sSql);
  309. }
  310. function deleteImage($aParams)
  311. {
  312. $sWhereClause = "";
  313. switch($aParams['type']) {
  314. case 'by_id':
  315. $aMethod['params'][1] = array(
  316. 'id' => $aParams['value']
  317. );
  318. $sWhereClause = "AND `tpb`.`id`=:id ";
  319. break;
  320. case 'all':
  321. break;
  322. }
  323. $sSql = "DELETE FROM `tpb` USING `sys_pages_blocks` AS `tpb` WHERE 1 " . $sWhereClause;
  324. return (int)$this->query($sSql) > 0;
  325. }
  326. function getMenus()
  327. {
  328. $sSql = "SELECT `object`, `title` FROM `sys_objects_menu` WHERE 1";
  329. return $this->getPairs($sSql, 'object', 'title');
  330. }
  331. }
  332. /** @} */