VM暫存
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

148 satır
3.9KB

  1. <?php
  2. /*
  3. file: Qcar3_model.php 查車3
  4. */
  5. class Qcar3_model extends CI_Model
  6. {
  7. function __construct()
  8. {
  9. parent::__construct();
  10. $this->load->database();
  11. }
  12. // 查車
  13. public function q_pks($lpr)
  14. {
  15. $sql = "select p.pksno, p.pic_name, p.update_time, p.in_time, p.posx, p.posy, m.group_id, g.group_name, g.floors
  16. from pks p, pks_group_member m, pks_groups g
  17. where p.pksno = m.pksno
  18. and m.group_id = g.group_id
  19. and g.group_type = 1
  20. and p.lpr = '{$lpr}'
  21. limit 1";
  22. $rows = $this->db->query($sql)->row_array();
  23. //if (!empty($rows['pic_name'])) $rows['pic_name'] = str_replace('.jpg', '', $rows['pic_name']);
  24. //else $rows['pksno'] = 0; // 如無該筆資料, 車位號碼設為0
  25. return $rows;
  26. }
  27. // 模糊比對
  28. function getLevenshteinSQLStatement($word, $target)
  29. {
  30. $words = array();
  31. if(strlen($word) >= 5)
  32. {
  33. for ($i = 0; $i < strlen($word); $i++) {
  34. // insertions
  35. $words[] = substr($word, 0, $i) . '_' . substr($word, $i);
  36. // deletions
  37. $words[] = substr($word, 0, $i) . substr($word, $i + 1);
  38. // substitutions
  39. //$words[] = substr($word, 0, $i) . '_' . substr($word, $i + 1);
  40. }
  41. }
  42. else
  43. {
  44. for ($i = 0; $i < strlen($word); $i++) {
  45. // insertions
  46. $words[] = substr($word, 0, $i) . '_' . substr($word, $i);
  47. }
  48. }
  49. // last insertion
  50. $words[] = $word . '_';
  51. //return $words;
  52. $fuzzy_statement = ' (';
  53. foreach ($words as $idx => $word)
  54. {
  55. $fuzzy_statement .= " {$target} LIKE '%{$word}%' OR ";
  56. }
  57. $last_or_pos = strrpos($fuzzy_statement, 'OR');
  58. if($last_or_pos !== false)
  59. {
  60. $fuzzy_statement = substr_replace($fuzzy_statement, ')', $last_or_pos, strlen('OR'));
  61. }
  62. return $fuzzy_statement;
  63. }
  64. // 取得進場資訊 (模糊比對)
  65. public function q_fuzzy_pks($word)
  66. {
  67. if(empty($word) || strlen($word) <= 0 || strlen($word) > 10)
  68. {
  69. return null;
  70. }
  71. $sql = "SELECT station_no, lpr, in_time, pic_name as pks_pic_name
  72. FROM pks
  73. WHERE {$this->getLevenshteinSQLStatement($word, 'lpr')}
  74. ORDER BY lpr ASC";
  75. $retults = $this->db->query($sql)->result_array();
  76. if(count($retults) > 0)
  77. {
  78. foreach ($retults as $idx => $rows)
  79. {
  80. $pks_pic_path = '';
  81. if(!empty($rows['pks_pic_name']))
  82. {
  83. //$pks_pic_path = APP_URL.'pks_pics/'.str_replace('.jpg', '', $rows['pks_pic_name']);
  84. $pks_pic_path = SERVER_URL.'pkspic/'.$rows['pks_pic_name'];
  85. }
  86. $data['result'][$idx] = array
  87. (
  88. 'lpr'=> $rows['lpr'],
  89. 'pks_pic_path' => $pks_pic_path,
  90. 'station_no' => $rows['station_no'],
  91. 'in_time' => $rows['in_time']
  92. );
  93. }
  94. }
  95. /*
  96. else
  97. {
  98. // 讀取入場資料
  99. $sql = "SELECT cario.station_no as station_no, cario.obj_id as lpr, cario.in_time as in_time, cario.in_pic_name as pks_pic_name
  100. FROM cario
  101. WHERE {$this->getLevenshteinSQLStatement($word, 'obj_id')}
  102. AND in_out = 'CI' AND finished = 0 AND err = 0 AND out_time IS NULL
  103. ORDER BY lpr ASC";
  104. // AND in_time > DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 5 DAY)
  105. $retults = $this->db->query($sql)->result_array();
  106. if(count($retults) > 0)
  107. {
  108. foreach ($retults as $idx => $rows)
  109. {
  110. $pks_pic_path = '';
  111. if(!empty($rows['pks_pic_name']))
  112. {
  113. $pic_name = str_replace('.jpg', '', $rows['pks_pic_name']);
  114. $arr = explode('-', $pic_name);
  115. //$pks_pic_path = SERVER_URL.'carspic/'.substr($arr[7], 0, 8).'/'.$pic_name.'.jpg';
  116. $pks_pic_path = SERVER_URL.'carpic/'.substr($arr[7], 0, 8).'/'.$pic_name.'.jpg';
  117. }
  118. $data['result'][$idx] = array
  119. (
  120. 'lpr'=> $rows['lpr'],
  121. 'pks_pic_path' => $pks_pic_path,
  122. 'station_no' => $rows['station_no'],
  123. 'in_time' => $rows['in_time']
  124. );
  125. }
  126. }
  127. }
  128. */
  129. return $data;
  130. }
  131. }