BxDolAIQuery.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  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. class BxDolAIQuery extends BxDolDb
  10. {
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. }
  15. static public function getModelObject($iId)
  16. {
  17. $oDb = BxDolDb::getInstance();
  18. $aModel = $oDb->getRow("SELECT * FROM `sys_agents_models` WHERE `id` = :id", ['id' => $iId]);
  19. if(!$aModel || !is_array($aModel))
  20. return false;
  21. return $aModel;
  22. }
  23. static public function getProviderObject($iId)
  24. {
  25. $oDb = BxDolDb::getInstance();
  26. $aProvider = $oDb->getRow("SELECT * FROM `sys_agents_providers` WHERE `id` = :id", ['id' => $iId]);
  27. if(!$aProvider || !is_array($aProvider))
  28. return false;
  29. // get type
  30. $aProviderType = $oDb->getRow("SELECT * FROM `sys_agents_provider_types` WHERE `id` = :id", ['id' => $aProvider['type_id']]);
  31. if(!$aProviderType || !is_array($aProviderType))
  32. return false;
  33. $aProvider['type'] = $aProviderType;
  34. // get options
  35. $sQuery = "SELECT
  36. `tpo`.`name` AS `name`,
  37. `tpv`.`value` AS `value`
  38. FROM `sys_agents_provider_options` AS `tpo`
  39. LEFT JOIN `sys_agents_providers_values` AS `tpv` ON `tpo`.`id` = `tpv`.`option_id` AND `tpv`.`provider_id` = :provider_id
  40. WHERE 1 ORDER BY `tpo`.`order`";
  41. $aProvider['options'] = $oDb->getAllWithKey($sQuery, 'name', [
  42. 'provider_id' => $iId
  43. ]);
  44. return $aProvider;
  45. }
  46. static public function getProviderIdByName($sName)
  47. {
  48. return (int)BxDolDb::getInstance()->getOne("SELECT `id` FROM `sys_agents_providers` WHERE `name`=:name LIMIT 1", [
  49. 'name' => $sName
  50. ]);
  51. }
  52. public function getModelsBy($aParams = [])
  53. {
  54. $aMethod = ['name' => 'getAll', 'params' => [0 => 'query']];
  55. $sWhereClause = "";
  56. switch($aParams['sample']) {
  57. case 'id':
  58. $aMethod['name'] = 'getRow';
  59. $aMethod['params'][1] = [
  60. 'id' => $aParams['id']
  61. ];
  62. $sWhereClause .= " AND `id`=:id";
  63. break;
  64. case 'all_pairs':
  65. $aMethod['name'] = 'getPairs';
  66. $aMethod['params'][1] = 'id';
  67. $aMethod['params'][2] = 'title';
  68. if(isset($aParams['for_asst'])) {
  69. $aMethod['params'][3] = [
  70. 'for_asst' => $aParams['for_asst']
  71. ];
  72. $sWhereClause = " AND `for_asst`=:for_asst";
  73. }
  74. if(isset($aParams['active'])) {
  75. $aMethod['params'][3] = [
  76. 'active' => $aParams['active']
  77. ];
  78. $sWhereClause = " AND `active`=:active";
  79. }
  80. break;
  81. }
  82. $aMethod['params'][0] = "SELECT *
  83. FROM `sys_agents_models`
  84. WHERE 1" . $sWhereClause;
  85. return call_user_func_array([$this, $aMethod['name']], $aMethod['params']);
  86. }
  87. public function getAutomatorsBy($aParams = [])
  88. {
  89. $aMethod = ['name' => 'getAll', 'params' => [0 => 'query']];
  90. $sSelectClause = "`taa`.*";
  91. $sJoinClause = $sWhereClause = "";
  92. switch($aParams['sample']) {
  93. case 'id':
  94. $aMethod['name'] = 'getRow';
  95. $aMethod['params'][1] = [
  96. 'id' => $aParams['id']
  97. ];
  98. $sWhereClause .= " AND `taa`.`id`=:id";
  99. break;
  100. case 'id_full':
  101. $aMethod['name'] = 'getRow';
  102. $aMethod['params'][1] = [
  103. 'id' => $aParams['id']
  104. ];
  105. $sSelectClause .= ", `tam`.`name` AS `model_name`, `tam`.`title` AS `model_title`, `tam`.`key` AS `model_key`, `tam`.`params` AS `model_params`";
  106. $sJoinClause .= " LEFT JOIN `sys_agents_models` AS `tam` ON `taa`.`model_id`=`tam`.`id`";
  107. $sWhereClause .= " AND `taa`.`id`=:id";
  108. break;
  109. case 'events':
  110. $aMethod['params'][1] = [
  111. 'type' => BX_DOL_AI_AUTOMATOR_EVENT,
  112. 'alert_unit' => $aParams['alert_unit'],
  113. 'alert_action' => $aParams['alert_action']
  114. ];
  115. $sWhereClause .= " AND `taa`.`type`=:type AND `taa`.`alert_unit`=:alert_unit AND `taa`.`alert_action`=:alert_action";
  116. if(isset($aParams['active'])) {
  117. $aMethod['params'][1]['active'] = (int)$aParams['active'];
  118. $sWhereClause .= " AND `taa`.`active`=:active";
  119. }
  120. break;
  121. case 'schedulers':
  122. $aMethod['params'][1] = [
  123. 'type' => BX_DOL_AI_AUTOMATOR_SCHEDULER,
  124. ];
  125. $sWhereClause .= " AND `taa`.`type`=:type";
  126. if(isset($aParams['active'])) {
  127. $aMethod['params'][1]['active'] = (int)$aParams['active'];
  128. $sWhereClause .= " AND `taa`.`active`=:active";
  129. }
  130. break;
  131. case 'webhooks':
  132. $aMethod['params'][1] = [
  133. 'type' => BX_DOL_AI_AUTOMATOR_WEBHOOK,
  134. ];
  135. $sWhereClause .= " AND `taa`.`type`=:type";
  136. if(isset($aParams['provider_id'])) {
  137. $aMethod['params'][1]['provider_id'] = (int)$aParams['provider_id'];
  138. $sJoinClause = "INNER JOIN `sys_agents_automators_providers` AS `tap` ON `taa`.`id`=`tap`.`automator_id`";
  139. $sWhereClause .= " AND `tap`.`provider_id`=:provider_id";
  140. }
  141. if(isset($aParams['active'])) {
  142. $aMethod['params'][1]['active'] = (int)$aParams['active'];
  143. $sWhereClause .= " AND `taa`.`active`=:active";
  144. }
  145. break;
  146. case 'providers_by_id_pairs':
  147. $aMethod['name'] = 'getPairs';
  148. $aMethod['params'][1] = 'id';
  149. $aMethod['params'][2] = 'provider_id';
  150. $aMethod['params'][3] = [
  151. 'id' => $aParams['id']
  152. ];
  153. $sSelectClause = "`tap`.`id`, `tap`.`provider_id`";
  154. $sJoinClause = "INNER JOIN `sys_agents_automators_providers` AS `tap` ON `taa`.`id`=`tap`.`automator_id`";
  155. $sWhereClause = " AND `taa`.`id`=:id";
  156. break;
  157. case 'helpers_by_id_pairs':
  158. $aMethod['name'] = 'getPairs';
  159. $aMethod['params'][1] = 'id';
  160. $aMethod['params'][2] = 'helper_id';
  161. $aMethod['params'][3] = [
  162. 'id' => $aParams['id']
  163. ];
  164. $sSelectClause = "`tah`.`id`, `tah`.`helper_id`";
  165. $sJoinClause = "INNER JOIN `sys_agents_automators_helpers` AS `tah` ON `taa`.`id`=`tah`.`automator_id`";
  166. $sWhereClause = " AND `taa`.`id`=:id";
  167. break;
  168. }
  169. $aMethod['params'][0] = "SELECT " . $sSelectClause . "
  170. FROM `sys_agents_automators` AS `taa` " . $sJoinClause . "
  171. WHERE 1" . $sWhereClause;
  172. return call_user_func_array([$this, $aMethod['name']], $aMethod['params']);
  173. }
  174. public function updateAutomators($aSetClause, $aWhereClause)
  175. {
  176. if(empty($aSetClause) || empty($aWhereClause))
  177. return false;
  178. return (int)$this->query("UPDATE `sys_agents_automators` SET " . $this->arrayToSQL($aSetClause) . " WHERE " . $this->arrayToSQL($aWhereClause)) > 0;
  179. }
  180. public function insertAutomatorProvider($aParamsSet)
  181. {
  182. if(empty($aParamsSet))
  183. return false;
  184. return (int)$this->query("INSERT INTO `sys_agents_automators_providers` SET " . $this->arrayToSQL($aParamsSet)) > 0 ? (int)$this->lastId() : false;
  185. }
  186. public function updateAutomatorProvider($aParamsSet, $aParamsWhere)
  187. {
  188. if(empty($aParamsSet) || empty($aParamsWhere))
  189. return false;
  190. return $this->query("UPDATE `sys_agents_automators_providers` SET " . $this->arrayToSQL($aParamsSet) . " WHERE " . $this->arrayToSQL($aParamsWhere, " AND "));
  191. }
  192. public function deleteAutomatorProviders($aParamsWhere)
  193. {
  194. if(empty($aParamsWhere))
  195. return false;
  196. return (int)$this->query("DELETE FROM `sys_agents_automators_providers` WHERE " . $this->arrayToSQL($aParamsWhere)) > 0;
  197. }
  198. public function deleteAutomatorProvidersById($mixedId)
  199. {
  200. if(!is_array($mixedId))
  201. $mixedId = [$mixedId];
  202. return (int)$this->query("DELETE FROM `sys_agents_automators_providers` WHERE `id` IN (" . $this->implode_escape($mixedId) . ")") > 0;
  203. }
  204. public function insertAutomatorHelper($aParamsSet)
  205. {
  206. if(empty($aParamsSet))
  207. return false;
  208. return (int)$this->query("INSERT INTO `sys_agents_automators_helpers` SET " . $this->arrayToSQL($aParamsSet)) > 0 ? (int)$this->lastId() : false;
  209. }
  210. public function updateAutomatorHelper($aParamsSet, $aParamsWhere)
  211. {
  212. if(empty($aParamsSet) || empty($aParamsWhere))
  213. return false;
  214. return $this->query("UPDATE `sys_agents_automators_helpers` SET " . $this->arrayToSQL($aParamsSet) . " WHERE " . $this->arrayToSQL($aParamsWhere, " AND "));
  215. }
  216. public function deleteAutomatorHelpers($aParamsWhere)
  217. {
  218. if(empty($aParamsWhere))
  219. return false;
  220. return (int)$this->query("DELETE FROM `sys_agents_automators_helpers` WHERE " . $this->arrayToSQL($aParamsWhere)) > 0;
  221. }
  222. public function deleteAutomatorHelpersById($mixedId)
  223. {
  224. if(!is_array($mixedId))
  225. $mixedId = [$mixedId];
  226. return (int)$this->query("DELETE FROM `sys_agents_automators_helpers` WHERE `id` IN (" . $this->implode_escape($mixedId) . ")") > 0;
  227. }
  228. public function insertAutomatorAssistant($aParamsSet)
  229. {
  230. if(empty($aParamsSet))
  231. return false;
  232. return (int)$this->query("INSERT INTO `sys_agents_automators_assistants` SET " . $this->arrayToSQL($aParamsSet)) > 0 ? (int)$this->lastId() : false;
  233. }
  234. public function updateAutomatorAssistant($aParamsSet, $aParamsWhere)
  235. {
  236. if(empty($aParamsSet) || empty($aParamsWhere))
  237. return false;
  238. return $this->query("UPDATE `sys_agents_automators_assistants` SET " . $this->arrayToSQL($aParamsSet) . " WHERE " . $this->arrayToSQL($aParamsWhere, " AND "));
  239. }
  240. public function deleteAutomatorAssistants($aParamsWhere)
  241. {
  242. if(empty($aParamsWhere))
  243. return false;
  244. return (int)$this->query("DELETE FROM `sys_agents_automators_assistants` WHERE " . $this->arrayToSQL($aParamsWhere)) > 0;
  245. }
  246. public function deleteAutomatorAssistantsById($mixedId)
  247. {
  248. if(!is_array($mixedId))
  249. $mixedId = [$mixedId];
  250. return (int)$this->query("DELETE FROM `sys_agents_automators_assistants` WHERE `id` IN (" . $this->implode_escape($mixedId) . ")") > 0;
  251. }
  252. public function getProviderTypesBy($aParams = [])
  253. {
  254. $aMethod = ['name' => 'getAll', 'params' => [0 => 'query']];
  255. $sWhereClause = "";
  256. switch($aParams['sample']) {
  257. case 'id':
  258. $aMethod['name'] = 'getRow';
  259. $aMethod['params'][1] = [
  260. 'id' => $aParams['id']
  261. ];
  262. $sWhereClause .= " AND `id`=:id";
  263. break;
  264. case 'name':
  265. $aMethod['name'] = 'getRow';
  266. $aMethod['params'][1] = [
  267. 'name' => $aParams['name']
  268. ];
  269. $sWhereClause .= " AND `name`=:name";
  270. break;
  271. case 'all_pairs':
  272. $aMethod['name'] = 'getPairs';
  273. $aMethod['params'][1] = 'id';
  274. $aMethod['params'][2] = 'title';
  275. if(isset($aParams['active'])) {
  276. $aMethod['params'][3] = [
  277. 'active' => $aParams['active']
  278. ];
  279. $sWhereClause = " AND `active`=:active";
  280. }
  281. break;
  282. }
  283. $aMethod['params'][0] = "SELECT *
  284. FROM `sys_agents_provider_types`
  285. WHERE 1" . $sWhereClause;
  286. return call_user_func_array([$this, $aMethod['name']], $aMethod['params']);
  287. }
  288. public function getProviderOptionsBy($aParams = [])
  289. {
  290. $aMethod = ['name' => 'getAll', 'params' => [0 => 'query']];
  291. $sWhereClause = "";
  292. switch($aParams['sample']) {
  293. case 'id':
  294. $aMethod['name'] = 'getRow';
  295. $aMethod['params'][1] = [
  296. 'id' => $aParams['id']
  297. ];
  298. $sWhereClause .= " AND `id`=:id";
  299. break;
  300. case 'provider_type_id':
  301. $aMethod['params'][1] = [
  302. 'provider_type_id' => $aParams['provider_type_id']
  303. ];
  304. $sWhereClause .= " AND `provider_type_id`=:provider_type_id";
  305. break;
  306. }
  307. $aMethod['params'][0] = "SELECT *
  308. FROM `sys_agents_provider_options`
  309. WHERE 1" . $sWhereClause;
  310. return call_user_func_array([$this, $aMethod['name']], $aMethod['params']);
  311. }
  312. public function getProvidersBy($aParams = [])
  313. {
  314. $aMethod = ['name' => 'getAll', 'params' => [0 => 'query']];
  315. $sSelectClause = "`tp`.*";
  316. $sJoinClause = $sWhereClause = $sGroupClause = $sOrderClause = $sLimitClause = "";
  317. switch($aParams['sample']) {
  318. case 'id':
  319. $aMethod['name'] = 'getRow';
  320. $aMethod['params'][1] = [
  321. 'id' => $aParams['id']
  322. ];
  323. $sWhereClause = " AND `tp`.`id`=:id";
  324. break;
  325. case 'ids':
  326. $sSelectClause .= ", `tpt`.`name` AS `type_name`";
  327. $sJoinClause = "INNER JOIN `sys_agents_provider_types` AS `tpt` ON `tp`.`type_id`=`tpt`.`id`";
  328. $sWhereClause = " AND `tp`.`id` IN (" . $this->implode_escape($aParams['ids']) . ")";
  329. break;
  330. case 'options_by_id':
  331. $aMethod['params'][1] = [
  332. 'id' => $aParams['id']
  333. ];
  334. $sSelectClause = "`tpo`.`id`, `tpo`.`name`, `tpo`.`type`, `tpo`.`title`, `tpo`.`description`, `tpv`.`value`";
  335. $sJoinClause = "LEFT JOIN `sys_agents_provider_options` AS `tpo` ON `tp`.`type_id`=`tpo`.`provider_type_id` LEFT JOIN `sys_agents_providers_values` AS `tpv` ON `tp`.`id`=`tpv`.`provider_id` AND `tpo`.`id`=`tpv`.`option_id`";
  336. $sWhereClause = " AND `tp`.`id`=:id";
  337. break;
  338. case 'all_pairs':
  339. $aMethod['name'] = 'getPairs';
  340. $aMethod['params'][1] = 'id';
  341. $aMethod['params'][2] = 'name';
  342. if(isset($aParams['active'])) {
  343. $aMethod['params'][3] = [
  344. 'active' => $aParams['active']
  345. ];
  346. $sWhereClause = " AND `tp`.`active`=:active";
  347. }
  348. break;
  349. }
  350. $sOrderClause = !empty($sOrderClause) ? "ORDER BY " . $sOrderClause : $sOrderClause;
  351. $sLimitClause = !empty($sLimitClause) ? "LIMIT " . $sLimitClause : $sLimitClause;
  352. $aMethod['params'][0] = "SELECT
  353. " . $sSelectClause . "
  354. FROM `sys_agents_providers` AS `tp` " . $sJoinClause . "
  355. WHERE 1" . $sWhereClause . " " . $sGroupClause . " " . $sOrderClause . " " . $sLimitClause;
  356. return call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
  357. }
  358. public function insertProviderValue($aParamsSet)
  359. {
  360. if(empty($aParamsSet) || !is_array($aParamsSet) || !isset($aParamsSet['value']))
  361. return false;
  362. return (int)$this->query("INSERT INTO `sys_agents_providers_values` SET " . $this->arrayToSQL($aParamsSet) . " ON DUPLICATE KEY UPDATE `value`=:value", [
  363. 'value' => $aParamsSet['value']
  364. ]) > 0 ? (int)$this->lastId() : false;
  365. }
  366. public function updateProviderValue($aParamsSet, $aParamsWhere)
  367. {
  368. if(empty($aParamsSet))
  369. return false;
  370. $sWhereClause = "1";
  371. if(!empty($aParamsWhere) && is_array($aParamsWhere))
  372. $sWhereClause = $this->arrayToSQL($aParamsWhere, ' AND ');
  373. return $this->query("UPDATE `sys_agents_providers_values` SET " . $this->arrayToSQL($aParamsSet) . " WHERE " . $sWhereClause) !== false;
  374. }
  375. public function deleteProviderValues($aParamsWhere)
  376. {
  377. if(empty($aParamsWhere))
  378. return false;
  379. return (int)$this->query("DELETE FROM `sys_agents_providers_values` WHERE " . $this->arrayToSQL($aParamsWhere, ' AND ')) > 0;
  380. }
  381. public function getHelpersBy($aParams = [])
  382. {
  383. $aMethod = ['name' => 'getAll', 'params' => [0 => 'query']];
  384. $sSelectClause = "`th`.*";
  385. $sJoinClause = $sWhereClause = "";
  386. switch($aParams['sample']) {
  387. case 'id':
  388. $aMethod['name'] = 'getRow';
  389. $aMethod['params'][1] = [
  390. 'id' => $aParams['id']
  391. ];
  392. $sWhereClause .= " AND `th`.`id`=:id";
  393. break;
  394. case 'name':
  395. $aMethod['name'] = 'getRow';
  396. $aMethod['params'][1] = [
  397. 'name' => $aParams['name']
  398. ];
  399. $sWhereClause .= " AND `th`.`name`=:name";
  400. break;
  401. case 'ids':
  402. $sWhereClause = " AND `th`.`id` IN (" . $this->implode_escape($aParams['ids']) . ")";
  403. break;
  404. case 'all_pairs':
  405. $aMethod['name'] = 'getPairs';
  406. $aMethod['params'][1] = 'id';
  407. $aMethod['params'][2] = 'name';
  408. if(isset($aParams['active'])) {
  409. $aMethod['params'][3] = [
  410. 'active' => $aParams['active']
  411. ];
  412. $sWhereClause = " AND `th`.`active`=:active";
  413. }
  414. break;
  415. }
  416. $aMethod['params'][0] = "SELECT " . $sSelectClause . "
  417. FROM `sys_agents_helpers` AS `th` " . $sJoinClause . "
  418. WHERE 1" . $sWhereClause;
  419. return call_user_func_array([$this, $aMethod['name']], $aMethod['params']);
  420. }
  421. public function getAssistantsBy($aParams = [])
  422. {
  423. $aMethod = ['name' => 'getAll', 'params' => [0 => 'query']];
  424. $sSelectClause = "`ta`.*";
  425. $sJoinClause = $sWhereClause = "";
  426. switch($aParams['sample']) {
  427. case 'id':
  428. $aMethod['name'] = 'getRow';
  429. $aMethod['params'][1] = [
  430. 'id' => $aParams['id']
  431. ];
  432. $sWhereClause .= " AND `ta`.`id`=:id";
  433. break;
  434. case 'name':
  435. $aMethod['name'] = 'getRow';
  436. $aMethod['params'][1] = [
  437. 'name' => $aParams['name']
  438. ];
  439. $sWhereClause .= " AND `ta`.`name`=:name";
  440. break;
  441. case 'ids':
  442. $sWhereClause = " AND `ta`.`id` IN (" . $this->implode_escape($aParams['ids']) . ")";
  443. break;
  444. case 'all_pairs':
  445. $aMethod['name'] = 'getPairs';
  446. $aMethod['params'][1] = 'id';
  447. $aMethod['params'][2] = 'name';
  448. if(isset($aParams['active'])) {
  449. $aMethod['params'][3] = [
  450. 'active' => $aParams['active']
  451. ];
  452. $sWhereClause = " AND `ta`.`active`=:active";
  453. }
  454. break;
  455. }
  456. $aMethod['params'][0] = "SELECT " . $sSelectClause . "
  457. FROM `sys_agents_assistants` AS `ta` " . $sJoinClause . "
  458. WHERE 1" . $sWhereClause;
  459. return call_user_func_array([$this, $aMethod['name']], $aMethod['params']);
  460. }
  461. public function updateAssistants($aSetClause, $aWhereClause)
  462. {
  463. if(empty($aSetClause) || empty($aWhereClause))
  464. return false;
  465. return (int)$this->query("UPDATE `sys_agents_assistants` SET " . $this->arrayToSQL($aSetClause) . " WHERE " . $this->arrayToSQL($aWhereClause)) > 0;
  466. }
  467. public function getChatsBy($aParams = [])
  468. {
  469. $aMethod = ['name' => 'getAll', 'params' => [0 => 'query']];
  470. $sSelectClause = "`tac`.*";
  471. $sJoinClause = $sWhereClause = "";
  472. switch($aParams['sample']) {
  473. case 'id':
  474. $aMethod['name'] = 'getRow';
  475. $aMethod['params'][1] = [
  476. 'id' => $aParams['id']
  477. ];
  478. $sWhereClause .= " AND `tac`.`id`=:id";
  479. break;
  480. case 'name':
  481. $aMethod['name'] = 'getRow';
  482. $aMethod['params'][1] = [
  483. 'name' => $aParams['name']
  484. ];
  485. $sWhereClause .= " AND `tac`.`name`=:name";
  486. break;
  487. case 'assistant_id':
  488. $aMethod['params'][1] = [
  489. 'assistant_id' => $aParams['assistant_id']
  490. ];
  491. $sWhereClause .= " AND `tac`.`assistant_id`=:assistant_id";
  492. break;
  493. }
  494. $aMethod['params'][0] = "SELECT " . $sSelectClause . "
  495. FROM `sys_agents_assistants_chats` AS `tac` " . $sJoinClause . "
  496. WHERE 1" . $sWhereClause;
  497. return call_user_func_array([$this, $aMethod['name']], $aMethod['params']);
  498. }
  499. public function updateChats($aSetClause, $aWhereClause)
  500. {
  501. if(empty($aSetClause) || empty($aWhereClause))
  502. return false;
  503. return (int)$this->query("UPDATE `sys_agents_assistants_chats` SET " . $this->arrayToSQL($aSetClause) . " WHERE " . $this->arrayToSQL($aWhereClause)) > 0;
  504. }
  505. public function deleteChats($aParamsWhere)
  506. {
  507. if(empty($aParamsWhere))
  508. return false;
  509. return (int)$this->query("DELETE FROM `sys_agents_assistants_chats` WHERE " . $this->arrayToSQL($aParamsWhere, ' AND ')) > 0;
  510. }
  511. }
  512. /** @} */