BxDolQueueQuery.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. * Database queries for BxDolQueue object.
  11. * @see BxDolQueue
  12. */
  13. class BxDolQueueQuery extends BxDolDb
  14. {
  15. protected $_sTable;
  16. public function __construct()
  17. {
  18. parent::__construct();
  19. }
  20. public function getItems($aParams = array())
  21. {
  22. if(empty($this->_sTable))
  23. return array();
  24. $aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
  25. $sSelectClause = '*';
  26. $sWhereClause = '';
  27. $sLimitClause = isset($aParams['start']) && !empty($aParams['per_page']) ? "LIMIT " . $aParams['start'] . ", " . $aParams['per_page'] : "";
  28. if(!empty($aParams['type']))
  29. switch($aParams['type']) {
  30. case 'to_send':
  31. $aMethod['name'] = 'getAllWithKey';
  32. $aMethod['params'][1] = 0;
  33. $aMethod['params'][2] = array();
  34. $aMethod['params'][3] = PDO::FETCH_NUM;
  35. break;
  36. }
  37. $aMethod['params'][0] = "SELECT " . $sSelectClause . " FROM `" . $this->_sTable . "` WHERE 1 " . $sWhereClause . $sLimitClause;
  38. return call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  39. }
  40. public function insertItem($aValues)
  41. {
  42. if(empty($this->_sTable))
  43. return false;
  44. if(empty($aValues) || !is_array($aValues))
  45. return false;
  46. return $this->query("INSERT INTO `" . $this->_sTable . "` SET " . $this->arrayToSQL($aValues));
  47. }
  48. public function updateItem($aValues, $aWhere)
  49. {
  50. if(empty($this->_sTable))
  51. return false;
  52. if(empty($aValues) || !is_array($aValues) || empty($aWhere) || !is_array($aWhere))
  53. return false;
  54. return (int)$this->query("UPDATE `" . $this->_sTable . "` SET " . $this->arrayToSQL($aValues) . " WHERE " . $this->arrayToSQL($aWhere, ' AND ')) > 0;
  55. }
  56. public function deleteItem($mixedId)
  57. {
  58. if(empty($this->_sTable))
  59. return false;
  60. if(!is_array($mixedId))
  61. $mixedId = array($mixedId);
  62. return (int)$this->query("DELETE FROM `" . $this->_sTable . "` WHERE `id` IN (" . $this->implode_escape($mixedId) . ")") > 0;
  63. }
  64. }
  65. /** @} */