search.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. <?php
  2. //@2014-01-18 some tunning of searching by A.Binder
  3. function task_CRM_SEARCH() {
  4. $q = V::get('q', '', $_REQUEST);
  5. $f_limit = V::get('f-_limit', 10, $_REQUEST, 'int');
  6. $f_offset = V::get('f-_offset', 0, $_REQUEST, 'int');
  7. $active_tab = V::get('_active_tab', 0, $_REQUEST, 'int');
  8. $db = DB::getDB();
  9. $qProces = new CrmSearchProces($db);
  10. $qProces->set_search($q);
  11. $qProces->set_param('limit', $f_limit);
  12. if ($active_tab == 0) {
  13. $qProces->set_param('offset', $f_offset);
  14. }
  15. echo '<h1>' . "Wyszukiwanie: " . htmlspecialchars($q) . '</h1>';
  16. if (!$qProces->check_search()) {
  17. echo App::ui_widget('alert', "Wyszukiwane słowo musi mieć conajmniej 2 znaki");
  18. return;
  19. }
  20. $qZasob = new CrmSearchZasob($db);
  21. $qZasob->set_search($q);
  22. $qZasob->set_param('limit', $f_limit);
  23. if ($active_tab == 1) {
  24. $qZasob->set_param('offset', $f_offset);
  25. }
  26. $qWsk = new CrmSearchWskaznik($db);
  27. $qWsk->set_search($q);
  28. $qWsk->set_param('limit', $f_limit);
  29. if ($active_tab == 2) {
  30. $qWsk->set_param('offset', $f_offset);
  31. }
  32. $qProcesInit = new CrmSearchProcesInit($db);
  33. $qProcesInit->set_search($q);
  34. $qProcesInit->set_param('limit', $f_limit);
  35. if ($active_tab == 3) {
  36. $qProcesInit->set_param('offset', $f_offset);
  37. }
  38. Lib::loadClass('PageNav');
  39. ?>
  40. <div>
  41. <ul id="search-result-tabs" class="nav nav-tabs">
  42. <li class="active"><a href="#tabs-1" data-toggle="tabs-1">Procesy (<?php echo $qProces->get_total();?>)</a></li>
  43. <li><a href="#tabs-2" data-toggle="tabs-2">Zasoby (<?php echo $qZasob->get_total();?>)</a></li>
  44. <li><a href="#tabs-3" data-toggle="tabs-3">Wskaźniki (<?php echo $qWsk->get_total();?>)</a></li>
  45. <li><a href="#tabs-4" data-toggle="tabs-4">Procesy Start (<?php echo $qProcesInit->get_total();?>)</a></li>
  46. <!--
  47. <li><a href="#tabs-1" style="outline:none">Procesy (<?php echo $qProces->get_total();?>)</a></li>
  48. <li><a href="#tabs-2" style="outline:none">Zasoby (<?php echo $qZasob->get_total();?>)</a></li>
  49. <li><a href="#tabs-3" style="outline:none">Wskaźniki (<?php echo $qWsk->get_total();?>)</a></li>
  50. <li><a href="#tabs-4" style="outline:none">Procesy Start (<?php echo $qProcesInit->get_total();?>)</a></li>
  51. -->
  52. </ul>
  53. <div id="myTabContent" class="tab-content">
  54. <?php $tab_nr = 1; ?>
  55. <div id="tabs-<?php echo $tab_nr; ?>" class="tab-pane fade in active" style="padding:10px 0;">
  56. <?php
  57. $total = $qProces->get_total();
  58. if ($total <= 0) {
  59. echo App::ui_widget('info', "Nie znaleziono żadnych rekordów pasujacych do kryteriów wyszukiwania");
  60. }
  61. else {
  62. $list = $qProces->get_list();
  63. $nav = new PageNav($total, $qProces->get_param('offset'), $qProces->get_param('limit'));
  64. $nav->set_request_args(array('task'=>'CRM_SEARCH', 'q'=>$q, '_active_tab'=>($tab_nr - 1)));
  65. $nav->set_request_method_post();
  66. $nav->set_request_arg_page_nr_name('f-_offset');
  67. echo $nav->render('links_only');
  68. ?>
  69. <table cellspacing="0" cellpadding="0" border="1" class="tbl-view">
  70. <thead>
  71. <tr>
  72. <th>ID</th>
  73. <th>DESC</th>
  74. <th>OPIS</th>
  75. <th>hit_counter</th>
  76. </tr>
  77. </thead>
  78. <tbody>
  79. <?php
  80. $t = 0;
  81. foreach ($list as $r) {
  82. $desc = strip_tags($r->DESC);
  83. $desc = str_replace($q, '<b>'.$q.'</b>', $desc);
  84. $desc = str_replace(strtoupper($q), '<b>'.strtoupper($q).'</b>', $desc);
  85. $opis = strip_tags($r->OPIS);
  86. if (strlen($opis) > 255) {
  87. $opis = substr($opis, 0, 255) . ' ...';
  88. }
  89. $opis = str_replace($q, '<b>'.$q.'</b>', $opis);
  90. $opis = str_replace(strtoupper($q), '<b>'.strtoupper($q).'</b>', $opis);
  91. echo '<tr class="row-'.($t = 1 - $t).'">';
  92. echo '<td>' . App::link($r->ID, array('task'=>'CRM_PROCES', 'filtr_id'=>$r->ID), array('class'=>'external', 'target'=>'_blank')) . '</td>';
  93. echo '<td>' . $desc . '</td>';
  94. echo '<td>' . $opis . '</td>';
  95. echo '<td>' . $r->hit_counter . '</td>';
  96. echo '</tr>';
  97. }
  98. ?>
  99. </tbody>
  100. </table>
  101. <?php
  102. echo $nav->render();
  103. }
  104. ?>
  105. </div>
  106. <?php $tab_nr++; ?>
  107. <div id="tabs-<?php echo $tab_nr; ?>" class="tab-pane fade" style="padding:10px 0;">
  108. <?php
  109. $total = $qZasob->get_total();
  110. if ($total <= 0) {
  111. echo App::ui_widget('info', "Nie znaleziono żadnych rekordów pasujacych do kryteriów wyszukiwania");
  112. }
  113. else {
  114. $list = $qZasob->get_list();
  115. $nav = new PageNav($total, $qZasob->get_param('offset'), $qZasob->get_param('limit'));
  116. $nav->set_request_args(array('task'=>'CRM_SEARCH', 'q'=>$q, '_active_tab'=>($tab_nr - 1)));
  117. $nav->set_request_method_post();
  118. $nav->set_request_arg_page_nr_name('f-_offset');
  119. echo $nav->render('links_only');
  120. ?>
  121. <table cellspacing="0" cellpadding="0" border="1" class="tbl-view">
  122. <thead>
  123. <tr>
  124. <th>ID</th>
  125. <th>DESC</th>
  126. <th>OPIS</th>
  127. <th>hit_counter</th>
  128. </tr>
  129. </thead>
  130. <tbody>
  131. <?php
  132. $t = 0;
  133. foreach ($list as $r) {
  134. $desc = strip_tags($r->DESC);
  135. $desc = str_replace($q, '<b>'.$q.'</b>', $desc);
  136. $desc = str_replace(strtoupper($q), '<b>'.strtoupper($q).'</b>', $desc);
  137. $opis = strip_tags($r->OPIS);
  138. if (strlen($opis) > 255) {
  139. $opis = substr($opis, 0, 255) . ' ...';
  140. }
  141. $opis = str_replace($q, '<b>'.$q.'</b>', $opis);
  142. $opis = str_replace(strtoupper($q), '<b>'.strtoupper($q).'</b>', $opis);
  143. echo '<tr class="row-'.($t = 1 - $t).'">';
  144. echo '<td>' . App::link($r->ID, array('task'=>'CRM_LISTA_ZASOBOW', 'filtr_id'=>$r->ID), array('class'=>'external', 'target'=>'_blank')) . '</td>';
  145. echo '<td>' . $desc . '</td>';
  146. echo '<td>' . $opis . '</td>';
  147. echo '<td>' . $r->hit_counter . '</td>';
  148. echo '</tr>';
  149. }
  150. ?>
  151. </tbody>
  152. </table>
  153. <?php
  154. echo $nav->render();
  155. }
  156. ?>
  157. </div>
  158. <?php $tab_nr++; ?>
  159. <div id="tabs-<?php echo $tab_nr; ?>" class="tab-pane fade" style="padding:10px 0;">
  160. <?php
  161. $total = $qWsk->get_total();
  162. if ($total <= 0) {
  163. echo App::ui_widget('info', "Nie znaleziono żadnych rekordów pasujacych do kryteriów wyszukiwania");
  164. }
  165. else {
  166. $list = $qWsk->get_list();
  167. $nav = new PageNav($total, $qWsk->get_param('offset'), $qWsk->get_param('limit'));
  168. $nav->set_request_args(array('task'=>'CRM_SEARCH', 'q'=>$q, '_active_tab'=>($tab_nr - 1)));
  169. $nav->set_request_method_post();
  170. $nav->set_request_arg_page_nr_name('f-_offset');
  171. echo $nav->render('links_only');
  172. ?>
  173. <table cellspacing="0" cellpadding="0" border="1" class="tbl-view">
  174. <thead>
  175. <tr>
  176. <th>ID</th>
  177. <th>ID_PROCES</th>
  178. <th>ID_ZASOB</th>
  179. <th>OPIS_ZASOB</th>
  180. <th>hit_counter</th>
  181. </tr>
  182. </thead>
  183. <tbody>
  184. <?php
  185. $t = 0;
  186. foreach ($list as $r) {
  187. $desc = strip_tags($r->DESC);
  188. $desc = str_replace($q, '<b>'.$q.'</b>', $desc);
  189. $desc = str_replace(strtoupper($q), '<b>'.strtoupper($q).'</b>', $desc);
  190. $opis = strip_tags($r->OPIS_ZASOB);
  191. if (strlen($opis) > 255) {
  192. $opis = substr($opis, 0, 255) . ' ...';
  193. }
  194. $opis = str_replace($q, '<b>'.$q.'</b>', $opis);
  195. $opis = str_replace(strtoupper($q), '<b>'.strtoupper($q).'</b>', $opis);
  196. echo '<tr class="row-'.($t = 1 - $t).'">';
  197. echo '<td>' . $r->ID . '</td>';
  198. echo '<td>' . App::link($r->ID_PROCES, array('task'=>'CRM_PROCES', 'filtr_id'=>$r->ID_PROCES), array('class'=>'external', 'target'=>'_blank')) . '</td>';
  199. echo '<td>' . App::link($r->ID_ZASOB, array('task'=>'CRM_LISTA_ZASOBOW', 'filtr_id'=>$r->ID_ZASOB), array('class'=>'external', 'target'=>'_blank')) . '</td>';
  200. echo '<td>' . $opis . '</td>';
  201. echo '<td>' . $r->hit_counter . '</td>';
  202. echo '</tr>';
  203. }
  204. ?>
  205. </tbody>
  206. </table>
  207. <?php
  208. echo $nav->render();
  209. }
  210. ?>
  211. </div>
  212. <?php $tab_nr = 4; ?>
  213. <div id="tabs-<?php echo $tab_nr; ?>" class="tab-pane fade" style="padding:10px 0;">
  214. <?php
  215. $total = $qProcesInit->get_total();
  216. if ($total <= 0) {
  217. echo App::ui_widget('info', "Nie znaleziono żadnych rekordów pasujacych do kryteriów wyszukiwania");
  218. }
  219. else {
  220. $list = $qProcesInit->get_list();
  221. $nav = new PageNav($total, $qProcesInit->get_param('offset'), $qProcesInit->get_param('limit'));
  222. $nav->set_request_args(array('task'=>'CRM_SEARCH', 'q'=>$q, '_active_tab'=>($tab_nr - 1)));
  223. $nav->set_request_method_post();
  224. $nav->set_request_arg_page_nr_name('f-_offset');
  225. echo $nav->render('links_only');
  226. ?>
  227. <table cellspacing="0" cellpadding="0" border="1" class="tbl-view">
  228. <thead>
  229. <tr>
  230. <th>ID</th>
  231. <th>DESC</th>
  232. <th>OPIS</th>
  233. <th>hit_counter</th>
  234. </tr>
  235. </thead>
  236. <tbody>
  237. <?php
  238. $t = 0;
  239. foreach ($list as $r) {
  240. $desc = strip_tags($r->DESC);
  241. $desc = str_replace($q, '<b>'.$q.'</b>', $desc);
  242. $desc = str_replace(strtoupper($q), '<b>'.strtoupper($q).'</b>', $desc);
  243. $opis = strip_tags($r->OPIS);
  244. if (strlen($opis) > 255) {
  245. $opis = substr($opis, 0, 255) . ' ...';
  246. }
  247. $opis = str_replace($q, '<b>'.$q.'</b>', $opis);
  248. $opis = str_replace(strtoupper($q), '<b>'.strtoupper($q).'</b>', $opis);
  249. echo '<tr class="row-'.($t = 1 - $t).'">';
  250. echo '<td>' . App::link($r->ID, array('task'=>'CRM_PROCES', 'filtr_id'=>$r->ID), array('class'=>'external', 'target'=>'_blank')) . '</td>';
  251. echo '<td>' . $desc . '</td>';
  252. echo '<td>' . $opis . '</td>';
  253. echo '<td>' . $r->hit_counter . '</td>';
  254. echo '</tr>';
  255. }
  256. ?>
  257. </tbody>
  258. </table>
  259. <?php
  260. echo $nav->render();
  261. }
  262. ?>
  263. </div>
  264. </div>
  265. </div>
  266. <script type="text/javascript">
  267. jQuery(document).ready(function(){
  268. $('#search-result-tabs a').click(function (e) {
  269. e.preventDefault();
  270. $(this).tab('show');
  271. })
  272. });
  273. </script>
  274. <?php
  275. }
  276. class CrmSearchBase {
  277. var $db = null;
  278. var $q = '';
  279. var $params = array();
  280. var $fields = array();
  281. var $_limit = 0;
  282. var $_total = null;
  283. var $_list = null;
  284. public function __construct($db) {
  285. $this->db = $db;
  286. }
  287. public function set_fields($fields) {
  288. $this->fields = $fields;
  289. }
  290. public function add_field($field, $label) {
  291. $this->fields[$field] = $label;
  292. }
  293. public function get_field_names() {
  294. return array_keys($this->fields);
  295. }
  296. public function get_field_labels() {
  297. return array_values($this->fields);
  298. }
  299. public function get_fields() {
  300. return $this->fields;
  301. }
  302. public function set_search($q) {
  303. $q = trim($q);
  304. $this->q = $this->db->_($q);
  305. }
  306. public function check_search() {
  307. return (!empty($this->q) && strlen($this->q) > 2);
  308. }
  309. public function set_param($key, $value) {
  310. $this->params[$key] = $value;
  311. }
  312. public function get_param($key) {
  313. return (array_key_exists($key, $this->params))? $this->params[$key] : null;
  314. }
  315. public function get_total() {
  316. if ($this->_total === null) {
  317. $this->_total = $this->_fetch_total();
  318. }
  319. return $this->_total;
  320. }
  321. public function get_list() {
  322. if ($this->_list === null) {
  323. $this->_list = $this->_fetch_list();
  324. }
  325. return $this->_list;
  326. }
  327. protected function _fetch_total() {
  328. return 0;
  329. }
  330. protected function _fetch_list() {
  331. $ret = array();
  332. return $ret;
  333. }
  334. }
  335. class CrmSearchProces extends CrmSearchBase {
  336. function _get_sql_where() {
  337. $sql_where = "
  338. p.`A_STATUS` in('NORMAL','WAITING')
  339. and (p.`DESC` like '%{$this->q}%' or p.`OPIS` like '%{$this->q}%' or p.`ID` like '{$this->q}')
  340. ";
  341. return $sql_where;
  342. }
  343. function _fetch_total() {
  344. $total = 0;
  345. $sql_where = $this->_get_sql_where();
  346. $sql = "select count(1) as cnt
  347. from `CRM_PROCES` as p
  348. where {$sql_where}
  349. ";
  350. $res = $this->db->query($sql);
  351. if ($r = $this->db->fetch($res)) {
  352. $total = $r->cnt;
  353. }
  354. return $total;
  355. }
  356. function _fetch_list() {
  357. $list = array();
  358. $sql_where = $this->_get_sql_where();
  359. $sql_limit = V::get('limit', 10, $this->params, 'int');
  360. $sql_offset = V::get('offset', 0, $this->params, 'int');
  361. $sql = "select p.`ID`, p.`DESC`, p.`OPIS`
  362. , if(p.`ID`='{$this->q}', 100
  363. , if(p.`DESC`='{$this->q}', 99
  364. , if(p.`DESC` like '{$this->q}%', 90
  365. , if(p.`DESC` like '%{$this->q}%', 80
  366. , if(p.`OPIS`='{$this->q}', 50
  367. , if(p.`OPIS` like '{$this->q}%', 40
  368. , if(p.`OPIS` like '%{$this->q}%', 30
  369. , 0
  370. )
  371. )
  372. )
  373. )
  374. )
  375. )
  376. )
  377. as hit_counter
  378. from `CRM_PROCES` as p
  379. where {$sql_where}
  380. order by hit_counter DESC, p.`ID` DESC
  381. limit {$sql_limit} offset {$sql_offset}
  382. ";
  383. $res = $this->db->query($sql);
  384. while ($r = $this->db->fetch($res)) {
  385. $list[$r->ID] = $r;
  386. }
  387. return $list;
  388. }
  389. }
  390. class CrmSearchProcesInit extends CrmSearchBase {
  391. function _get_sql_where() {
  392. $sql_where = "
  393. p.`A_STATUS` in('NORMAL','WAITING')
  394. and (p.`DESC` like '%{$this->q}%' or p.`OPIS` like '%{$this->q}%' or p.`ID` like '%{$this->q}%')
  395. and p.`TYPE`='PROCES_INIT'
  396. ";
  397. return $sql_where;
  398. }
  399. function _fetch_total() {
  400. $total = 0;
  401. $sql_where = $this->_get_sql_where();
  402. $sql = "select count(1) as cnt
  403. from `CRM_PROCES` as p
  404. where {$sql_where}
  405. ";
  406. $res = $this->db->query($sql);
  407. if ($r = $this->db->fetch($res)) {
  408. $total = $r->cnt;
  409. }
  410. return $total;
  411. }
  412. function _fetch_list() {
  413. $list = array();
  414. $sql_where = $this->_get_sql_where();
  415. $sql_limit = V::get('limit', 10, $this->params, 'int');
  416. $sql_offset = V::get('offset', 0, $this->params, 'int');
  417. $sql = "select p.`ID`, p.`DESC`, p.`OPIS`
  418. , if(p.`ID`='{$this->q}', 100
  419. , if(p.`DESC`='{$this->q}', 99
  420. , if(p.`DESC` like '{$this->q}%', 90
  421. , if(p.`DESC` like '%{$this->q}%', 80
  422. , if(p.`OPIS`='{$this->q}', 50
  423. , if(p.`OPIS` like '{$this->q}%', 40
  424. , if(p.`OPIS` like '%{$this->q}%', 30
  425. , 0
  426. )
  427. )
  428. )
  429. )
  430. )
  431. )
  432. ) as hit_counter
  433. from `CRM_PROCES` as p
  434. where {$sql_where}
  435. order by hit_counter DESC, p.`ID` DESC
  436. limit {$sql_limit} offset {$sql_offset}
  437. ";
  438. $res = $this->db->query($sql);
  439. while ($r = $this->db->fetch($res)) {
  440. $list[$r->ID] = $r;
  441. }
  442. return $list;
  443. }
  444. }
  445. class CrmSearchZasob extends CrmSearchBase {
  446. function _get_sql_where() {
  447. $sql_where = "
  448. z.`A_STATUS` in('NORMAL','WAITING')
  449. and (z.`DESC` like '%{$this->q}%' or z.`OPIS` like '%{$this->q}%' or z.`ID` like '{$this->q}')
  450. ";
  451. return $sql_where;
  452. }
  453. function _fetch_total() {
  454. $total = 0;
  455. $sql_where = $this->_get_sql_where();
  456. $sql = "select count(1) as cnt
  457. from `CRM_LISTA_ZASOBOW` as z
  458. where {$sql_where}
  459. ";
  460. $res = $this->db->query($sql);
  461. if ($r = $this->db->fetch($res)) {
  462. $total = $r->cnt;
  463. }
  464. return $total;
  465. }
  466. function _fetch_list() {
  467. $list = array();
  468. $sql_where = $this->_get_sql_where();
  469. $sql_limit = V::get('limit', 10, $this->params, 'int');
  470. $sql_offset = V::get('offset', 0, $this->params, 'int');
  471. $sql = "select z.`ID`, concat(z.`DESC`,' (',z.`TYPE`,')') as `DESC`, z.`OPIS`
  472. , if(z.`ID`='{$this->q}', 100
  473. , if(z.`DESC`='{$this->q}', 99
  474. , if(z.`DESC` like '{$this->q}%', 90
  475. , if(z.`DESC` like '%{$this->q}%', 80
  476. , if(z.`OPIS`='{$this->q}', 50
  477. , if(z.`OPIS` like '{$this->q}%', 40
  478. , if(z.`OPIS` like '%{$this->q}%', 30
  479. , 0
  480. )
  481. )
  482. )
  483. )
  484. )
  485. )
  486. ) as hit_counter
  487. from `CRM_LISTA_ZASOBOW` as z
  488. where {$sql_where}
  489. order by hit_counter DESC, z.`ID` DESC
  490. limit {$sql_limit} offset {$sql_offset}
  491. ";
  492. $res = $this->db->query($sql);
  493. while ($r = $this->db->fetch($res)) {
  494. $list[$r->ID] = $r;
  495. }
  496. return $list;
  497. }
  498. }
  499. class CrmSearchWskaznik extends CrmSearchBase {
  500. function _get_sql_where() {
  501. $sql_where = "
  502. w.`A_STATUS` in('NORMAL','WAITING')
  503. and p.`A_STATUS` in('NORMAL','WAITING')
  504. and z.`A_STATUS` in('NORMAL','WAITING')
  505. and (w.`OPIS_ZASOB` like '%{$this->q}%' or w.`ID_ZASOB` like '{$this->q}' or w.`ID_PROCES` like '{$this->q}' )
  506. ";
  507. return $sql_where;
  508. }
  509. function _fetch_total() {
  510. $total = 0;
  511. $sql_where = $this->_get_sql_where();
  512. $sql = "select count(1) as cnt
  513. from `CRM_WSKAZNIK` as w
  514. join `CRM_PROCES` as p on(p.`ID`=w.`ID_PROCES`)
  515. join `CRM_LISTA_ZASOBOW` as z on(z.`ID`=w.`ID_ZASOB`)
  516. where {$sql_where}
  517. ";
  518. $res = $this->db->query($sql);
  519. if ($r = $this->db->fetch($res)) {
  520. $total = $r->cnt;
  521. }
  522. return $total;
  523. }
  524. function _fetch_list() {
  525. $list = array();
  526. $sql_where = $this->_get_sql_where();
  527. $sql_limit = V::get('limit', 10, $this->params, 'int');
  528. $sql_offset = V::get('offset', 0, $this->params, 'int');
  529. $sql = "select w.`ID`, w.`ID_PROCES`, w.`ID_ZASOB`, w.`OPIS_ZASOB`
  530. , if(w.`ID_ZASOB`='{$this->q}', 100
  531. , if(w.`ID_PROCES`='{$this->q}', 100
  532. , if(w.`OPIS_ZASOB`='{$this->q}', 99
  533. , if(w.`OPIS_ZASOB` like '{$this->q}%', 90
  534. , if(w.`OPIS_ZASOB` like '%{$this->q}%', 80
  535. , 0
  536. )
  537. )
  538. )
  539. )
  540. ) as hit_counter
  541. from `CRM_WSKAZNIK` as w
  542. join `CRM_PROCES` as p on(p.`ID`=w.`ID_PROCES`)
  543. join `CRM_LISTA_ZASOBOW` as z on(z.`ID`=w.`ID_ZASOB`)
  544. where {$sql_where}
  545. order by hit_counter DESC, w.`ID` DESC
  546. limit {$sql_limit} offset {$sql_offset}
  547. ";
  548. $res = $this->db->query($sql);
  549. while ($r = $this->db->fetch($res)) {
  550. $list[$r->ID] = $r;
  551. }
  552. return $list;
  553. }
  554. }