Mercurial > epgrec.yaz
annotate Keyword.class.php @ 130:290a05fd7331
mod: 半角英数で検索しても全角英数がヒットするように変更
author | Sushi-k <epgrec@park.mda.or.jp> |
---|---|
date | Thu, 18 Mar 2010 17:50:01 +0900 |
parents | 7a64d5e3baee |
children | 9c5e597ef6c6 |
rev | line source |
---|---|
1 | 1 <?php |
2 include_once('config.php'); | |
3 include_once( INSTALL_PATH . "/DBRecord.class.php" ); | |
4 include_once( INSTALL_PATH . "/reclib.php" ); | |
5 include_once( INSTALL_PATH . "/Reservation.class.php" ); | |
37
e5f9aa34d06f
change: modify all script for web base setting
yoneda <epgrec@park.mda.or.jp>
parents:
1
diff
changeset
|
6 include_once( INSTALL_PATH . '/Settings.class.php' ); |
1 | 7 |
8 class Keyword extends DBRecord { | |
9 | |
10 public function __construct($property = null, $value = null ) { | |
11 try { | |
37
e5f9aa34d06f
change: modify all script for web base setting
yoneda <epgrec@park.mda.or.jp>
parents:
1
diff
changeset
|
12 parent::__construct(KEYWORD_TBL, $property, $value ); |
1 | 13 } |
14 catch( Exception $e ) { | |
15 throw $e; | |
16 } | |
17 } | |
18 | |
115 | 19 static public function search( $keyword = "", |
20 $use_regexp = false, | |
21 $type = "*", | |
22 $category_id = 0, | |
23 $channel_id = 0, | |
24 $weekofday = 7, | |
25 $prgtime = 24, | |
26 $limit = 300 ) { | |
27 $sts = Settings::factory(); | |
28 | |
29 $dbh = @mysql_connect($sts->db_host, $sts->db_user, $sts->db_pass ); | |
1 | 30 |
31 // <c罎膣≪ | |
115 | 32 $options = " WHERE starttime > '".date("Y-m-d H:i:s", time() + $sts->padding_time + 60 )."'"; |
1 | 33 |
115 | 34 if( $keyword != "" ) { |
35 if( $use_regexp ) { | |
36 $options .= " AND CONCAT(title,description) REGEXP '".mysql_real_escape_string($keyword)."'"; | |
1 | 37 } |
38 else { | |
130
290a05fd7331
mod: 半角英数で検索しても全角英数がヒットするように変更
Sushi-k <epgrec@park.mda.or.jp>
parents:
115
diff
changeset
|
39 // 茹茹 |
290a05fd7331
mod: 半角英数で検索しても全角英数がヒットするように変更
Sushi-k <epgrec@park.mda.or.jp>
parents:
115
diff
changeset
|
40 // 翫絲上 |
290a05fd7331
mod: 半角英数で検索しても全角英数がヒットするように変更
Sushi-k <epgrec@park.mda.or.jp>
parents:
115
diff
changeset
|
41 $f_zennum = preg_match('/[0-9]/u', $keyword ); |
290a05fd7331
mod: 半角英数で検索しても全角英数がヒットするように変更
Sushi-k <epgrec@park.mda.or.jp>
parents:
115
diff
changeset
|
42 $f_zenal = preg_match('/[a-zA-Z]/u', $keyword ); |
290a05fd7331
mod: 半角英数で検索しても全角英数がヒットするように変更
Sushi-k <epgrec@park.mda.or.jp>
parents:
115
diff
changeset
|
43 |
290a05fd7331
mod: 半角英数で検索しても全角英数がヒットするように変更
Sushi-k <epgrec@park.mda.or.jp>
parents:
115
diff
changeset
|
44 $options .= " AND ( CONCAT(title,' ',description) like '%".mysql_real_escape_string($keyword)."%'"; |
290a05fd7331
mod: 半角英数で検索しても全角英数がヒットするように変更
Sushi-k <epgrec@park.mda.or.jp>
parents:
115
diff
changeset
|
45 |
290a05fd7331
mod: 半角英数で検索しても全角英数がヒットするように変更
Sushi-k <epgrec@park.mda.or.jp>
parents:
115
diff
changeset
|
46 if( $f_zennum ) { |
290a05fd7331
mod: 半角英数で検索しても全角英数がヒットするように変更
Sushi-k <epgrec@park.mda.or.jp>
parents:
115
diff
changeset
|
47 $options .= " OR CONCAT(title,' ',description) like '%".mysql_real_escape_string(mb_convert_kana( $keyword, 'KVN' ))."%'"; |
290a05fd7331
mod: 半角英数で検索しても全角英数がヒットするように変更
Sushi-k <epgrec@park.mda.or.jp>
parents:
115
diff
changeset
|
48 } |
290a05fd7331
mod: 半角英数で検索しても全角英数がヒットするように変更
Sushi-k <epgrec@park.mda.or.jp>
parents:
115
diff
changeset
|
49 if( $f_zenal ) { |
290a05fd7331
mod: 半角英数で検索しても全角英数がヒットするように変更
Sushi-k <epgrec@park.mda.or.jp>
parents:
115
diff
changeset
|
50 $options .= " OR CONCAT(title,' ',description) like '%".mysql_real_escape_string(mb_convert_kana( $keyword, 'KVR' ))."%'"; |
290a05fd7331
mod: 半角英数で検索しても全角英数がヒットするように変更
Sushi-k <epgrec@park.mda.or.jp>
parents:
115
diff
changeset
|
51 } |
290a05fd7331
mod: 半角英数で検索しても全角英数がヒットするように変更
Sushi-k <epgrec@park.mda.or.jp>
parents:
115
diff
changeset
|
52 if( $f_zenal && $f_zennum ) { |
290a05fd7331
mod: 半角英数で検索しても全角英数がヒットするように変更
Sushi-k <epgrec@park.mda.or.jp>
parents:
115
diff
changeset
|
53 $options .= " OR CONCAT(title,' ',description) like '%".mysql_real_escape_string(mb_convert_kana( $keyword, 'KVRN' ))."%'"; |
290a05fd7331
mod: 半角英数で検索しても全角英数がヒットするように変更
Sushi-k <epgrec@park.mda.or.jp>
parents:
115
diff
changeset
|
54 } |
290a05fd7331
mod: 半角英数で検索しても全角英数がヒットするように変更
Sushi-k <epgrec@park.mda.or.jp>
parents:
115
diff
changeset
|
55 $options .= ") "; |
1 | 56 } |
57 } | |
58 | |
115 | 59 if( $type != "*" ) { |
60 $options .= " AND type = '".$type."'"; | |
1 | 61 } |
62 | |
115 | 63 if( $category_id != 0 ) { |
64 $options .= " AND category_id = '".$category_id."'"; | |
1 | 65 } |
66 | |
115 | 67 if( $channel_id != 0 ) { |
68 $options .= " AND channel_id = '".$channel_id."'"; | |
1 | 69 } |
70 | |
115 | 71 if( $weekofday != 7 ) { |
72 $options .= " AND WEEKDAY(starttime) = '".$weekofday."'"; | |
77 | 73 } |
74 | |
115 | 75 if( $prgtime != 24 ) { |
76 $options .= " AND time(starttime) BETWEEN cast('".sprintf( "%02d:00:00", $prgtime)."' as time) AND cast('".sprintf("%02d:59:59", $prgtime)."' as time)"; | |
106 | 77 } |
78 | |
115 | 79 $options .= " ORDER BY starttime ASC LIMIT ".$limit ; |
1 | 80 |
81 $recs = array(); | |
82 try { | |
37
e5f9aa34d06f
change: modify all script for web base setting
yoneda <epgrec@park.mda.or.jp>
parents:
1
diff
changeset
|
83 $recs = DBRecord::createRecords( PROGRAM_TBL, $options ); |
1 | 84 } |
85 catch( Exception $e ) { | |
86 throw $e; | |
87 } | |
88 return $recs; | |
89 } | |
90 | |
115 | 91 private function getPrograms() { |
92 if( $this->id == 0 ) return false; | |
93 $recs = array(); | |
94 try { | |
95 $recs = self::search( trim($this->keyword), $this->use_regexp, $this->type, $this->category_id, $this->channel_id, $this->weekofday, $this->prgtime ); | |
96 } | |
97 catch( Exception $e ) { | |
98 throw $e; | |
99 } | |
100 return $recs; | |
101 } | |
1 | 102 |
103 public function reservation() { | |
104 if( $this->id == 0 ) return; | |
105 | |
106 $precs = array(); | |
107 try { | |
108 $precs = $this->getPrograms(); | |
109 } | |
110 catch( Exception $e ) { | |
111 throw $e; | |
112 } | |
115 | 113 // 筝羂牙私膣 |
114 foreach( $precs as $rec ) { | |
115 try { | |
116 if( $rec->autorec ) { | |
117 Reservation::simple( $rec->id, $this->id, $this->autorec_mode ); | |
118 usleep( 100 ); // 障腥冴? | |
1 | 119 } |
120 } | |
115 | 121 catch( Exception $e ) { |
122 // ∴ | |
123 } | |
1 | 124 } |
125 } | |
126 | |
127 public function delete() { | |
128 if( $this->id == 0 ) return; | |
129 | |
130 $precs = array(); | |
131 try { | |
132 $precs = $this->getPrograms(); | |
133 } | |
134 catch( Exception $e ) { | |
135 throw $e; | |
136 } | |
137 // 筝羂c潟祉 | |
138 foreach( $precs as $rec ) { | |
139 try { | |
37
e5f9aa34d06f
change: modify all script for web base setting
yoneda <epgrec@park.mda.or.jp>
parents:
1
diff
changeset
|
140 $reserve = new DBRecord( RESERVE_TBL, "program_id", $rec->id ); |
1 | 141 // 篋膣水 |
142 if( $reserve->autorec ) { | |
143 Reservation::cancel( $reserve->id ); | |
144 usleep( 100 ); // 障腥冴? | |
145 } | |
146 } | |
147 catch( Exception $e ) { | |
148 // ∴ | |
149 } | |
150 } | |
151 try { | |
152 parent::delete(); | |
153 } | |
154 catch( Exception $e ) { | |
155 throw $e; | |
156 } | |
157 } | |
158 | |
159 // static<潟激с潟若若ゃс | |
160 static function createKeywords( $options = "" ) { | |
161 $retval = array(); | |
162 $arr = array(); | |
163 try{ | |
164 $tbl = new self(); | |
165 $sqlstr = "SELECT * FROM ".$tbl->table." " .$options; | |
166 $result = $tbl->__query( $sqlstr ); | |
167 } | |
168 catch( Exception $e ) { | |
169 throw $e; | |
170 } | |
171 if( $result === false ) throw new exception("潟若絖障"); | |
172 while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { | |
173 array_push( $retval, new self('id', $row['id']) ); | |
174 } | |
175 return $retval; | |
176 } | |
177 | |
178 public function __destruct() { | |
179 parent::__destruct(); | |
180 } | |
181 } | |
130
290a05fd7331
mod: 半角英数で検索しても全角英数がヒットするように変更
Sushi-k <epgrec@park.mda.or.jp>
parents:
115
diff
changeset
|
182 ?> |