Mercurial > epgrec.yaz
annotate Keyword.class.php @ 136:6754b6aa50cf
mod: ????????config.php???
| author | epgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp> |
|---|---|
| date | Sun, 21 Mar 2010 00:00:58 +0900 |
| parents | 9c5e597ef6c6 |
| children | a18df712fc7e 2cb414518ccd |
| 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 // ちょっと先を検索する | |
| 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 ) { |
|
135
9c5e597ef6c6
mod: ???????
epgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp>
parents:
130
diff
changeset
|
47 $options .= " OR CONCAT(title,' ',description) like '%".mysql_real_escape_string(mb_convert_kana( $keyword, 'KVN',"UTF-8" ))."%'"; |
|
130
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 ) { |
|
135
9c5e597ef6c6
mod: ???????
epgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp>
parents:
130
diff
changeset
|
50 $options .= " OR CONCAT(title,' ',description) like '%".mysql_real_escape_string(mb_convert_kana( $keyword, 'KVR', "UTF-8" ))."%'"; |
|
130
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 ) { |
|
135
9c5e597ef6c6
mod: ???????
epgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp>
parents:
130
diff
changeset
|
53 $options .= " OR CONCAT(title,' ',description) like '%".mysql_real_escape_string(mb_convert_kana( $keyword, 'KVRN', "UTF-8" ))."%'"; |
|
130
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 // 一気にキャンセル | |
| 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 ?> |
