BxDolLabelQuery.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 'parent':
  47. $aMethod['params'][1] = array(
  48. 'parent' => $aParams['parent']
  49. );
  50. $sWhereClause = " AND `tl`.`parent`=:parent";
  51. break;
  52. case 'parent_order':
  53. $aMethod['name'] = 'getOne';
  54. $aMethod['params'][1] = array(
  55. 'parent' => $aParams['parent']
  56. );
  57. $sSelectClause = "MAX(`tl`.`order`)";
  58. $sWhereClause = " AND `tl`.`parent`=:parent";
  59. break;
  60. }
  61. if(!empty($sGroupClause))
  62. $sGroupClause = "GROUP BY " . $sGroupClause;
  63. if(!empty($sOrderClause))
  64. $sOrderClause = "ORDER BY " . $sOrderClause;
  65. $aMethod['params'][0] = "SELECT " . $sSelectClause . "
  66. FROM `" . $this->_sTableLabels . "` AS `tl`" . $sJoinClause . "
  67. WHERE 1" . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause;
  68. return call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  69. }
  70. }
  71. /** @} */