BxDolStudioWidgetsQuery.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 BxDolStudioWidgetsQuery extends BxDolStudioPageQuery implements iBxDolSingleton {
  12. function __construct() {
  13. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  14. trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  15. parent::__construct();
  16. }
  17. /**
  18. * Prevent cloning the instance
  19. */
  20. public function __clone() {
  21. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  22. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  23. }
  24. /**
  25. * Get singleton instance of the class
  26. */
  27. public static function getInstance() {
  28. $sClass = __CLASS__;
  29. if (!isset($GLOBALS['bxDolClasses'][__CLASS__]))
  30. $GLOBALS['bxDolClasses'][__CLASS__] = new $sClass();
  31. return $GLOBALS['bxDolClasses'][__CLASS__];
  32. }
  33. function reorder($sPage, $aItems) {
  34. $iResult = 0;
  35. foreach($aItems as $iKey => $iWidgetId) {
  36. $sSql = $this->prepare("UPDATE `sys_std_pages_widgets` AS `tpw`
  37. LEFT JOIN `sys_std_pages` AS `tp` ON `tpw`.`page_id`=`tp`.`id`
  38. SET `tpw`.`order`=?
  39. WHERE `tpw`.`widget_id`=?", $iKey + 1, $iWidgetId);
  40. $iResult += (int)$this->query($sSql);
  41. }
  42. return $iResult;
  43. }
  44. function getWidgets($aParams, &$aItems, $bReturnCount = true) {
  45. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  46. $sSelectClause = $sJoinClause = $sWhereClause = $sOrderClause = $sLimitClause = "";
  47. if(!isset($aParams['order']) || empty($aParams['order']))
  48. $sOrderClause = "ORDER BY `tw2p`.`order` ASC";
  49. switch($aParams['type']) {
  50. case 'by_id':
  51. $aMethod['name'] = 'getRow';
  52. $sWhereClause .= $this->prepare("AND `tw`.`id`=?", $aParams['value']);
  53. break;
  54. case 'by_page_id':
  55. $sWhereClause .= $this->prepare("AND `tw2p`.`page_id`=?", $aParams['value']);
  56. break;
  57. }
  58. $aMethod['params'][0] = "SELECT " . ($bReturnCount ? "SQL_CALC_FOUND_ROWS" : "") . "
  59. `tw`.`id` AS `id`,
  60. `tw`.`page_id` AS `page_id`,
  61. `tw`.`module` AS `module`,
  62. `tp`.`index` AS `page_index`,
  63. `tp`.`name` AS `page_name`,
  64. `tp`.`header` AS `page_header`,
  65. `tp`.`caption` AS `page_caption`,
  66. `tp`.`icon` AS `page_icon`,
  67. `tw`.`url` AS `url`,
  68. `tw`.`click` AS `click`,
  69. `tw`.`icon` AS `icon`,
  70. `tw`.`caption` AS `caption`,
  71. `tw`.`cnt_notices` AS `cnt_notices`,
  72. `tw`.`cnt_actions` AS `cnt_actions`,
  73. `tw`.`bookmark` AS `bookmark`,
  74. `tw2p`.`order` AS `order` " . $sSelectClause . "
  75. FROM `sys_std_widgets` AS `tw`
  76. LEFT JOIN `sys_std_pages` AS `tp` ON `tw`.`page_id`=`tp`.`id`
  77. LEFT JOIN `sys_std_pages_widgets` AS `tw2p` ON `tw`.`id`=`tw2p`.`widget_id` " . $sJoinClause . "
  78. WHERE 1 " . $sWhereClause . " " . $sOrderClause . " " . $sLimitClause;
  79. $aItems = call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  80. if(!$bReturnCount)
  81. return !empty($aItems);
  82. return (int)$this->getOne("SELECT FOUND_ROWS()");
  83. }
  84. }
  85. /** @} */