BxDolLabelQuery.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. $CNF = &$this->_oConfig->CNF;
  23. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  24. $sSelectClause = "`tl`.*";
  25. $sJoinClause = $sWhereClause = $sGroupClause = "";
  26. $sOrderClause = "`tl`.`order` ASC";
  27. if(isset($aParams['count_only']) && $aParams['count_only'] === true) {
  28. $aMethod['name'] = 'getOne';
  29. $sSelectClause = "COUNT(`tl`.`id`)";
  30. }
  31. switch($aParams['type']) {
  32. case 'id':
  33. $aMethod['name'] = 'getRow';
  34. $aMethod['params'][1] = array(
  35. 'id' => $aParams['id']
  36. );
  37. $sWhereClause = " AND `tl`.`id`=:id";
  38. break;
  39. case 'value':
  40. $aMethod['name'] = 'getRow';
  41. $aMethod['params'][1] = array(
  42. 'value' => mb_strtoupper($aParams['value'])
  43. );
  44. $sWhereClause = " AND UPPER(`tl`.`value`)=:value";
  45. break;
  46. case 'values':
  47. $aMethod['name'] = 'getColumn';
  48. $sSelectClause = "`tl`.`value`";
  49. break;
  50. case 'parent':
  51. $aMethod['params'][1] = array(
  52. 'parent' => $aParams['parent']
  53. );
  54. $sWhereClause = " AND `tl`.`parent`=:parent";
  55. if(!empty($aParams['exclude']) && is_array($aParams['exclude']))
  56. $sWhereClause .= " AND `tl`.`id` NOT IN(" . $this->implode_escape($aParams['exclude']) . ")";
  57. break;
  58. case 'parent_order':
  59. $aMethod['name'] = 'getOne';
  60. $aMethod['params'][1] = array(
  61. 'parent' => $aParams['parent']
  62. );
  63. $sSelectClause = "MAX(`tl`.`order`)";
  64. $sWhereClause = " AND `tl`.`parent`=:parent";
  65. break;
  66. }
  67. if(!empty($sGroupClause))
  68. $sGroupClause = "GROUP BY " . $sGroupClause;
  69. if(!empty($sOrderClause))
  70. $sOrderClause = "ORDER BY " . $sOrderClause;
  71. $aMethod['params'][0] = "SELECT " . $sSelectClause . "
  72. FROM `" . $this->_sTableLabels . "` AS `tl`" . $sJoinClause . "
  73. WHERE 1" . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause;
  74. return call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  75. }
  76. }
  77. /** @} */