1
0

BxDolLabelQuery.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 UnaCore UNA Core
  7. * @{
  8. */
  9. /**
  10. * @see BxDolLabel
  11. */
  12. class BxDolLabelQuery extends BxDolDb
  13. {
  14. protected $_sTableLabels;
  15. public function __construct()
  16. {
  17. parent::__construct();
  18. $this->_sTableLabels = 'sys_labels';
  19. }
  20. public function getLabels($aParams = array())
  21. {
  22. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  23. $sSelectClause = "`tl`.*";
  24. $sJoinClause = $sWhereClause = $sGroupClause = "";
  25. $sOrderClause = "`tl`.`order` ASC";
  26. if(isset($aParams['count_only']) && $aParams['count_only'] === true) {
  27. $aMethod['name'] = 'getOne';
  28. $sSelectClause = "COUNT(`tl`.`id`)";
  29. }
  30. switch($aParams['type']) {
  31. case 'id':
  32. $aMethod['name'] = 'getRow';
  33. $aMethod['params'][1] = array(
  34. 'id' => $aParams['id']
  35. );
  36. $sWhereClause = " AND `tl`.`id`=:id";
  37. break;
  38. case 'value':
  39. $aMethod['name'] = 'getRow';
  40. $aMethod['params'][1] = array(
  41. 'value' => mb_strtoupper($aParams['value'])
  42. );
  43. $sWhereClause = " AND UPPER(`tl`.`value`)=:value";
  44. break;
  45. case 'values':
  46. $aMethod['name'] = 'getColumn';
  47. $sSelectClause = "`tl`.`value`";
  48. break;
  49. case 'parent':
  50. $aMethod['params'][1] = array(
  51. 'parent' => $aParams['parent']
  52. );
  53. $sWhereClause = " AND `tl`.`parent`=:parent";
  54. if(!empty($aParams['exclude']) && is_array($aParams['exclude']))
  55. $sWhereClause .= " AND `tl`.`id` NOT IN(" . $this->implode_escape($aParams['exclude']) . ")";
  56. break;
  57. case 'parent_order':
  58. $aMethod['name'] = 'getOne';
  59. $aMethod['params'][1] = array(
  60. 'parent' => $aParams['parent']
  61. );
  62. $sSelectClause = "MAX(`tl`.`order`)";
  63. $sWhereClause = " AND `tl`.`parent`=:parent";
  64. break;
  65. }
  66. if(!empty($sGroupClause))
  67. $sGroupClause = "GROUP BY " . $sGroupClause;
  68. if(!empty($sOrderClause))
  69. $sOrderClause = "ORDER BY " . $sOrderClause;
  70. $aMethod['params'][0] = "SELECT " . $sSelectClause . "
  71. FROM `" . $this->_sTableLabels . "` AS `tl`" . $sJoinClause . "
  72. WHERE 1" . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause;
  73. return call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  74. }
  75. }
  76. /** @} */