Mercurial > epgrec.yaz
annotate Keyword.class.php @ 169:e379552d084c
fix: recorder.php:???????????????????
| author | epgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp> |
|---|---|
| date | Sun, 18 Apr 2010 18:06:39 +0900 |
| parents | 784e3c82926e |
| children | 190a3c46611d |
| 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' ); |
|
145
2cb414518ccd
mod: ?????????????????
epgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp>
parents:
135
diff
changeset
|
7 include_once( INSTALL_PATH . '/recLog.inc.php' ); |
| 1 | 8 |
| 9 class Keyword extends DBRecord { | |
| 10 | |
| 11 public function __construct($property = null, $value = null ) { | |
| 12 try { | |
|
37
e5f9aa34d06f
change: modify all script for web base setting
yoneda <epgrec@park.mda.or.jp>
parents:
1
diff
changeset
|
13 parent::__construct(KEYWORD_TBL, $property, $value ); |
| 1 | 14 } |
| 15 catch( Exception $e ) { | |
| 16 throw $e; | |
| 17 } | |
| 18 } | |
| 19 | |
| 115 | 20 static public function search( $keyword = "", |
| 21 $use_regexp = false, | |
| 22 $type = "*", | |
| 23 $category_id = 0, | |
| 24 $channel_id = 0, | |
| 25 $weekofday = 7, | |
| 26 $prgtime = 24, | |
| 27 $limit = 300 ) { | |
| 28 $sts = Settings::factory(); | |
| 29 | |
| 30 $dbh = @mysql_connect($sts->db_host, $sts->db_user, $sts->db_pass ); | |
| 1 | 31 |
| 32 // ちょっと先を検索する | |
| 115 | 33 $options = " WHERE starttime > '".date("Y-m-d H:i:s", time() + $sts->padding_time + 60 )."'"; |
| 1 | 34 |
| 115 | 35 if( $keyword != "" ) { |
| 36 if( $use_regexp ) { | |
| 37 $options .= " AND CONCAT(title,description) REGEXP '".mysql_real_escape_string($keyword)."'"; | |
| 1 | 38 } |
| 39 else { | |
|
152
784e3c82926e
mod: yazucchi??????????
epgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp>
parents:
145
diff
changeset
|
40 $options .= " AND CONCAT(title,description) like _utf8'%".mysql_real_escape_string($keyword)."%' collate utf8_unicode_ci"; |
| 1 | 41 } |
| 42 } | |
| 43 | |
| 115 | 44 if( $type != "*" ) { |
| 45 $options .= " AND type = '".$type."'"; | |
| 1 | 46 } |
| 47 | |
| 115 | 48 if( $category_id != 0 ) { |
| 49 $options .= " AND category_id = '".$category_id."'"; | |
| 1 | 50 } |
| 51 | |
| 115 | 52 if( $channel_id != 0 ) { |
| 53 $options .= " AND channel_id = '".$channel_id."'"; | |
| 1 | 54 } |
| 55 | |
| 115 | 56 if( $weekofday != 7 ) { |
| 57 $options .= " AND WEEKDAY(starttime) = '".$weekofday."'"; | |
| 77 | 58 } |
| 59 | |
| 115 | 60 if( $prgtime != 24 ) { |
| 61 $options .= " AND time(starttime) BETWEEN cast('".sprintf( "%02d:00:00", $prgtime)."' as time) AND cast('".sprintf("%02d:59:59", $prgtime)."' as time)"; | |
| 106 | 62 } |
| 63 | |
| 115 | 64 $options .= " ORDER BY starttime ASC LIMIT ".$limit ; |
| 1 | 65 |
| 66 $recs = array(); | |
| 67 try { | |
|
37
e5f9aa34d06f
change: modify all script for web base setting
yoneda <epgrec@park.mda.or.jp>
parents:
1
diff
changeset
|
68 $recs = DBRecord::createRecords( PROGRAM_TBL, $options ); |
| 1 | 69 } |
| 70 catch( Exception $e ) { | |
| 71 throw $e; | |
| 72 } | |
| 73 return $recs; | |
| 74 } | |
| 75 | |
| 115 | 76 private function getPrograms() { |
| 77 if( $this->id == 0 ) return false; | |
| 78 $recs = array(); | |
| 79 try { | |
| 80 $recs = self::search( trim($this->keyword), $this->use_regexp, $this->type, $this->category_id, $this->channel_id, $this->weekofday, $this->prgtime ); | |
| 81 } | |
| 82 catch( Exception $e ) { | |
| 83 throw $e; | |
| 84 } | |
| 85 return $recs; | |
| 86 } | |
| 1 | 87 |
| 88 public function reservation() { | |
| 89 if( $this->id == 0 ) return; | |
| 90 | |
| 91 $precs = array(); | |
| 92 try { | |
| 93 $precs = $this->getPrograms(); | |
| 94 } | |
| 95 catch( Exception $e ) { | |
| 96 throw $e; | |
| 97 } | |
| 115 | 98 // 一気に録画予約 |
| 99 foreach( $precs as $rec ) { | |
| 100 try { | |
| 101 if( $rec->autorec ) { | |
| 102 Reservation::simple( $rec->id, $this->id, $this->autorec_mode ); | |
|
145
2cb414518ccd
mod: ?????????????????
epgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp>
parents:
135
diff
changeset
|
103 reclog( "Keyword.class::キーワードID".$this->id."の録画が予約された"); |
| 115 | 104 usleep( 100 ); // あんまり時間を空けないのもどう? |
| 1 | 105 } |
| 106 } | |
| 115 | 107 catch( Exception $e ) { |
| 108 // 無視 | |
| 109 } | |
| 1 | 110 } |
| 111 } | |
| 112 | |
| 113 public function delete() { | |
| 114 if( $this->id == 0 ) return; | |
| 115 | |
| 116 $precs = array(); | |
| 117 try { | |
| 118 $precs = $this->getPrograms(); | |
| 119 } | |
| 120 catch( Exception $e ) { | |
| 121 throw $e; | |
| 122 } | |
| 123 // 一気にキャンセル | |
| 124 foreach( $precs as $rec ) { | |
| 125 try { | |
|
37
e5f9aa34d06f
change: modify all script for web base setting
yoneda <epgrec@park.mda.or.jp>
parents:
1
diff
changeset
|
126 $reserve = new DBRecord( RESERVE_TBL, "program_id", $rec->id ); |
| 1 | 127 // 自動予約されたもののみ削除 |
| 128 if( $reserve->autorec ) { | |
| 129 Reservation::cancel( $reserve->id ); | |
| 130 usleep( 100 ); // あんまり時間を空けないのもどう? | |
| 131 } | |
| 132 } | |
| 133 catch( Exception $e ) { | |
| 134 // 無視 | |
| 135 } | |
| 136 } | |
| 137 try { | |
| 138 parent::delete(); | |
| 139 } | |
| 140 catch( Exception $e ) { | |
| 141 throw $e; | |
| 142 } | |
| 143 } | |
| 144 | |
| 145 // staticなファンクションはオーバーライドできない | |
| 146 static function createKeywords( $options = "" ) { | |
| 147 $retval = array(); | |
| 148 $arr = array(); | |
| 149 try{ | |
| 150 $tbl = new self(); | |
| 151 $sqlstr = "SELECT * FROM ".$tbl->table." " .$options; | |
| 152 $result = $tbl->__query( $sqlstr ); | |
| 153 } | |
| 154 catch( Exception $e ) { | |
| 155 throw $e; | |
| 156 } | |
| 157 if( $result === false ) throw new exception("レコードが存在しません"); | |
| 158 while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { | |
| 159 array_push( $retval, new self('id', $row['id']) ); | |
| 160 } | |
| 161 return $retval; | |
| 162 } | |
| 163 | |
| 164 public function __destruct() { | |
| 165 parent::__destruct(); | |
| 166 } | |
| 167 } | |
|
130
290a05fd7331
mod: ?????????????????????????
Sushi-k <epgrec@park.mda.or.jp>
parents:
115
diff
changeset
|
168 ?> |
