BxDolStudioDesignsQuery.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 BxDolStudioDesignsQuery extends BxDolStudioPageQuery {
  12. function __construct() {
  13. parent::__construct();
  14. }
  15. function getTemplatesBy($aParams, &$aItems, $bReturnCount = true) {
  16. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  17. $sSelectClause = $sJoinClause = $sWhereClause = $sOrderClause = $sLimitClause = "";
  18. if(!isset($aParams['order']) || empty($aParams['order']))
  19. $sOrderClause = " `tm`.`id` ASC ";
  20. switch($aParams['type']) {
  21. case 'by_id':
  22. $aMethod['name'] = 'getRow';
  23. $sWhereClause .= $this->prepare(" AND `tm`.`id`=?", $aParams['value']);
  24. break;
  25. case 'by_name':
  26. $aMethod['name'] = 'getRow';
  27. $sWhereClause .= $this->prepare(" AND `tm`.`name`=?", $aParams['value']);
  28. break;
  29. case 'active':
  30. $sWhereClause = " AND `tm`.`enabled`='1'";
  31. break;
  32. case 'all':
  33. $sOrderClause = " `tm`.`uri` ASC ";
  34. break;
  35. case 'all_by_id':
  36. $sWhereClause .= $this->prepare(" AND `tm`.`id`=?", $aParams['value']);
  37. $sOrderClause = " `tm`.`uri` ASC ";
  38. break;
  39. case 'all_key_id':
  40. $aMethod['name'] = 'getAllWithKey';
  41. $aMethod['params'][1] = 'id';
  42. if(isset($aParams['template']) && (int)$aParams['template'] != 0)
  43. $sWhereClause .= $this->prepare(" AND `tm`.`id`=?", $aParams['template']);
  44. break;
  45. }
  46. $aMethod['params'][0] = "SELECT " . ($bReturnCount ? "SQL_CALC_FOUND_ROWS" : "") . "
  47. `tm`.`id` AS `id`,
  48. `tm`.`name` AS `name`,
  49. `tm`.`title` AS `title`,
  50. `tm`.`enabled` AS `enabled`" . $sSelectClause . "
  51. FROM `sys_modules` AS `tm`" . $sJoinClause . "
  52. WHERE 1 AND `tm`.`type`='" . BX_DOL_MODULE_TYPE_TEMPLATE . "'" . $sWhereClause . "
  53. ORDER BY" . $sOrderClause . $sLimitClause;
  54. $aItems = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  55. if(!$bReturnCount)
  56. return !empty($aItems);
  57. return (int)$this->getOne("SELECT FOUND_ROWS()");
  58. }
  59. }
  60. /** @} */