BxDolLabelQuery.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 'term':
  58. $aMethod['params'][1] = array(
  59. 'term' => '%' . $aParams['term'] . '%'
  60. );
  61. $sWhereClause = " AND `tl`.`value` LIKE :term";
  62. break;
  63. case 'parent_order':
  64. $aMethod['name'] = 'getOne';
  65. $aMethod['params'][1] = array(
  66. 'parent' => $aParams['parent']
  67. );
  68. $sSelectClause = "MAX(`tl`.`order`)";
  69. $sWhereClause = " AND `tl`.`parent`=:parent";
  70. break;
  71. }
  72. if(!empty($sGroupClause))
  73. $sGroupClause = "GROUP BY " . $sGroupClause;
  74. if(!empty($sOrderClause))
  75. $sOrderClause = "ORDER BY " . $sOrderClause;
  76. $aMethod['params'][0] = "SELECT " . $sSelectClause . "
  77. FROM `" . $this->_sTableLabels . "` AS `tl`" . $sJoinClause . "
  78. WHERE 1" . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause;
  79. return call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  80. }
  81. }
  82. /** @} */