BxDolStudioPageQuery.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaStudio UNA Studio
  7. * @{
  8. */
  9. class BxDolStudioPageQuery extends BxDolDb implements iBxDolSingleton
  10. {
  11. public function __construct()
  12. {
  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. {
  22. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  23. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  24. }
  25. /**
  26. * Get singleton instance of the class
  27. */
  28. public static function getInstance()
  29. {
  30. $sClass = __CLASS__;
  31. if (!isset($GLOBALS['bxDolClasses'][__CLASS__]))
  32. $GLOBALS['bxDolClasses'][__CLASS__] = new $sClass();
  33. return $GLOBALS['bxDolClasses'][__CLASS__];
  34. }
  35. function getPages($aParams)
  36. {
  37. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  38. $sSelectClause = $sJoinClause = $sWhereClause = $sOrderClause = $sLimitClause = "";
  39. if(!isset($aParams['order']) || empty($aParams['order']))
  40. $sOrderClause = "ORDER BY `tp`.`id` ASC";
  41. switch($aParams['type']) {
  42. case 'all':
  43. break;
  44. case 'by_page_id':
  45. $aMethod['name'] = 'getRow';
  46. $aMethod['params'][1] = array(
  47. 'id' => $aParams['value']
  48. );
  49. $sWhereClause .= "AND `tp`.`id`=:id";
  50. $sOrderClause = "";
  51. $sLimitClause = "LIMIT 1";
  52. break;
  53. case 'by_page_id_full':
  54. $aMethod['name'] = 'getRow';
  55. $aMethod['params'][1] = array(
  56. 'id' => $aParams['value']
  57. );
  58. $sSelectClause .= ", `tw`.`id` AS `wid_id`, `tw`.`module` AS `wid_module`, `tw`.`type` AS `wid_type`, `tw`.`url` AS `wid_url`, `tw`.`click` AS `wid_click`, `tw`.`icon` AS `wid_icon`, `tw`.`caption` AS `wid_caption`, `tw`.`cnt_notices` AS `wid_cnt_notices`, `tw`.`cnt_actions` AS `wid_cnt_actions` ";
  59. $sJoinClause .= "LEFT JOIN `sys_std_widgets` AS `tw` ON `tp`.`id`=`tw`.`page_id` ";
  60. $sWhereClause .= "AND `tp`.`id`=:id";
  61. $sLimitClause = "LIMIT 1";
  62. break;
  63. case 'by_page_name':
  64. $aMethod['name'] = 'getRow';
  65. $aMethod['params'][1] = array(
  66. 'name' => $aParams['value']
  67. );
  68. $sWhereClause .= "AND `tp`.`name`=:name";
  69. $sLimitClause = "LIMIT 1";
  70. break;
  71. case 'by_page_name_full':
  72. $aMethod['name'] = 'getRow';
  73. $aMethod['params'][1] = array(
  74. 'name' => $aParams['value'],
  75. );
  76. $sSelectClause .= ", `tw`.`id` AS `wid_id`, `tw`.`module` AS `wid_module`, `tw`.`type` AS `wid_type`, `tw`.`url` AS `wid_url`, `tw`.`click` AS `wid_click`, `tw`.`icon` AS `wid_icon`, `tw`.`caption` AS `wid_caption`, `tw`.`cnt_notices` AS `wid_cnt_notices`, `tw`.`cnt_actions` AS `wid_cnt_actions` ";
  77. $sJoinClause .= "LEFT JOIN `sys_std_widgets` AS `tw` ON `tp`.`id`=`tw`.`page_id` ";
  78. $sWhereClause .= "AND `tp`.`name`=:name";
  79. $sLimitClause = "LIMIT 1";
  80. break;
  81. case 'by_page_names_full':
  82. $aMethod['name'] = 'getAll';
  83. $aMethod['params'][1] = array();
  84. $sSelectClause .= ", `tw`.`id` AS `wid_id`, `tw`.`module` AS `wid_module`, `tw`.`url` AS `wid_url`, `tw`.`click` AS `wid_click`, `tw`.`icon` AS `wid_icon`, `tw`.`caption` AS `wid_caption`, `tw`.`cnt_notices` AS `wid_cnt_notices`, `tw`.`cnt_actions` AS `wid_cnt_actions` ";
  85. $sJoinClause .= "LEFT JOIN `sys_std_widgets` AS `tw` ON `tp`.`id`=`tw`.`page_id` ";
  86. $sWhereClause = "AND `tp`.`name` IN (" . $this->implode_escape($aParams['value']) . ")";
  87. break;
  88. }
  89. $aMethod['params'][0] = "SELECT
  90. `tp`.`id` AS `id`,
  91. `tp`.`index` AS `index`,
  92. `tp`.`name` AS `name`,
  93. `tp`.`header` AS `header`,
  94. `tp`.`caption` AS `caption`,
  95. `tp`.`icon` AS `icon`" . $sSelectClause . "
  96. FROM `sys_std_pages` AS `tp` " . $sJoinClause . "
  97. WHERE 1 " . $sWhereClause . " " . $sOrderClause . " " . $sLimitClause;
  98. return call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  99. }
  100. function isFeatured($aPage)
  101. {
  102. if(empty($aPage['wid_id']))
  103. return false;
  104. if((int)$this->getOne("SELECT `featured` FROM `sys_std_widgets` WHERE `id`=:id LIMIT 1", array('id' => $aPage['wid_id'])) == 0)
  105. return false;
  106. return true;
  107. }
  108. function featured(&$aPage)
  109. {
  110. if(empty($aPage['wid_id']))
  111. return false;
  112. $bResult = (int)$this->query("UPDATE `sys_std_widgets` SET `featured`=:featured WHERE `id`=:id", array(
  113. 'featured' => $aPage['featured'] ? 0 : 1,
  114. 'id' => $aPage['wid_id']
  115. )) > 0;
  116. if($bResult)
  117. $aPage['featured'] = !$aPage['featured'];
  118. return $bResult;
  119. }
  120. function isBookmarked($aPage, $iProfileId)
  121. {
  122. if(empty($aPage['wid_id']))
  123. return false;
  124. $iBookmark = (int)$this->getOne("SELECT `bookmark` FROM `sys_std_widgets_bookmarks` WHERE `widget_id`=:widget_id AND `profile_id`=:profile_id LIMIT 1", array(
  125. 'widget_id' => $aPage['wid_id'],
  126. 'profile_id' => $iProfileId
  127. ));
  128. return $iBookmark != 0;
  129. }
  130. function bookmark(&$aPage, $iProfileId)
  131. {
  132. if(empty($aPage['wid_id']))
  133. return false;
  134. $bResult = (int)$this->query("REPLACE INTO `sys_std_widgets_bookmarks` SET `widget_id`=:widget_id, `profile_id`=:profile_id, `bookmark`=:bookmark", array(
  135. 'widget_id' => $aPage['wid_id'],
  136. 'profile_id' => $iProfileId,
  137. 'bookmark' => $aPage['bookmark'] ? 0 : 1
  138. )) > 0;
  139. if($bResult)
  140. $aPage['bookmark'] = !$aPage['bookmark'];
  141. return $bResult;
  142. }
  143. }
  144. /** @} */