BxAccntDb.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 Accounts Accounts
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxAccntDb extends BxBaseModGeneralDb
  12. {
  13. function __construct(&$oConfig)
  14. {
  15. parent::__construct($oConfig);
  16. }
  17. public function getAccountFields()
  18. {
  19. return $this->getFields('sys_accounts');
  20. }
  21. public function getAccountIds()
  22. {
  23. return $this->getColumn("SELECT `id` FROM `sys_accounts` WHERE `name` != 'Robot'", "id");
  24. }
  25. public function updateAccount($aSet, $aWhere)
  26. {
  27. return (int)$this->query("UPDATE `sys_accounts` SET " . $this->arrayToSQL($aSet) . " WHERE " . $this->arrayToSQL($aWhere, ' AND ')) > 0;
  28. }
  29. public function getEntriesNumByParams ($aParams = [])
  30. {
  31. $CNF = &$this->_oConfig->CNF;
  32. $sSql = "SELECT COUNT(*) FROM `sys_accounts` WHERE 1";
  33. foreach($aParams as $aValue){
  34. if (!$this->isValidOperator($aValue['operator'])) {
  35. throw new Exception('Invalid operator in getEntriesNumByParams method');
  36. }
  37. $sSql .= ' AND ' . (isset($aValue['table'])? '`' . $aValue['table'] .'`.' : '') . '`' . $aValue['key'] ."` " . $aValue['operator'] . " '" . $aValue['value'] . "'";
  38. }
  39. $sQuery = $this->prepare($sSql);
  40. return $this->getOne($sQuery);
  41. }
  42. }
  43. /** @} */