Mercurial > epgrec.yaz
annotate Keyword.class.php @ 137:a18df712fc7e
merged with upstream
| author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
|---|---|
| date | Sun, 21 Mar 2010 03:15:00 +0900 |
| parents | db185340a981 9c5e597ef6c6 |
| children | 4afd353b4507 |
| 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 { | |
| 118 | 39 $options .= " AND CONCAT(title,description) like _utf8'%".mysql_real_escape_string($keyword)."%' collate utf8_unicode_ci"; |
| 1 | 40 } |
| 41 } | |
| 42 | |
| 115 | 43 if( $type != "*" ) { |
| 44 $options .= " AND type = '".$type."'"; | |
| 1 | 45 } |
| 46 | |
| 115 | 47 if( $category_id != 0 ) { |
| 48 $options .= " AND category_id = '".$category_id."'"; | |
| 1 | 49 } |
| 50 | |
| 115 | 51 if( $channel_id != 0 ) { |
| 52 $options .= " AND channel_id = '".$channel_id."'"; | |
| 1 | 53 } |
| 54 | |
| 115 | 55 if( $weekofday != 7 ) { |
| 56 $options .= " AND WEEKDAY(starttime) = '".$weekofday."'"; | |
| 77 | 57 } |
| 58 | |
| 115 | 59 if( $prgtime != 24 ) { |
| 60 $options .= " AND time(starttime) BETWEEN cast('".sprintf( "%02d:00:00", $prgtime)."' as time) AND cast('".sprintf("%02d:59:59", $prgtime)."' as time)"; | |
| 106 | 61 } |
| 62 | |
| 115 | 63 $options .= " ORDER BY starttime ASC LIMIT ".$limit ; |
| 1 | 64 |
| 65 $recs = array(); | |
| 66 try { | |
|
37
e5f9aa34d06f
change: modify all script for web base setting
yoneda <epgrec@park.mda.or.jp>
parents:
1
diff
changeset
|
67 $recs = DBRecord::createRecords( PROGRAM_TBL, $options ); |
| 1 | 68 } |
| 69 catch( Exception $e ) { | |
| 70 throw $e; | |
| 71 } | |
| 72 return $recs; | |
| 73 } | |
| 74 | |
| 115 | 75 private function getPrograms() { |
| 76 if( $this->id == 0 ) return false; | |
| 77 $recs = array(); | |
| 78 try { | |
| 79 $recs = self::search( trim($this->keyword), $this->use_regexp, $this->type, $this->category_id, $this->channel_id, $this->weekofday, $this->prgtime ); | |
| 80 } | |
| 81 catch( Exception $e ) { | |
| 82 throw $e; | |
| 83 } | |
| 84 return $recs; | |
| 85 } | |
| 1 | 86 |
| 87 public function reservation() { | |
| 88 if( $this->id == 0 ) return; | |
| 89 | |
| 90 $precs = array(); | |
| 91 try { | |
| 92 $precs = $this->getPrograms(); | |
| 93 } | |
| 94 catch( Exception $e ) { | |
| 95 throw $e; | |
| 96 } | |
| 115 | 97 // 一気に録画予約 |
| 98 foreach( $precs as $rec ) { | |
| 99 try { | |
| 100 if( $rec->autorec ) { | |
| 101 Reservation::simple( $rec->id, $this->id, $this->autorec_mode ); | |
| 102 usleep( 100 ); // あんまり時間を空けないのもどう? | |
| 1 | 103 } |
| 104 } | |
| 115 | 105 catch( Exception $e ) { |
| 106 // 無視 | |
| 107 } | |
| 1 | 108 } |
| 109 } | |
| 110 | |
| 111 public function delete() { | |
| 112 if( $this->id == 0 ) return; | |
| 113 | |
| 114 $precs = array(); | |
| 115 try { | |
| 116 $precs = $this->getPrograms(); | |
| 117 } | |
| 118 catch( Exception $e ) { | |
| 119 throw $e; | |
| 120 } | |
| 121 // 一気にキャンセル | |
| 122 foreach( $precs as $rec ) { | |
| 123 try { | |
|
37
e5f9aa34d06f
change: modify all script for web base setting
yoneda <epgrec@park.mda.or.jp>
parents:
1
diff
changeset
|
124 $reserve = new DBRecord( RESERVE_TBL, "program_id", $rec->id ); |
| 1 | 125 // 自動予約されたもののみ削除 |
| 126 if( $reserve->autorec ) { | |
| 127 Reservation::cancel( $reserve->id ); | |
| 128 usleep( 100 ); // あんまり時間を空けないのもどう? | |
| 129 } | |
| 130 } | |
| 131 catch( Exception $e ) { | |
| 132 // 無視 | |
| 133 } | |
| 134 } | |
| 135 try { | |
| 136 parent::delete(); | |
| 137 } | |
| 138 catch( Exception $e ) { | |
| 139 throw $e; | |
| 140 } | |
| 141 } | |
| 142 | |
| 143 // staticなファンクションはオーバーライドできない | |
| 144 static function createKeywords( $options = "" ) { | |
| 145 $retval = array(); | |
| 146 $arr = array(); | |
| 147 try{ | |
| 148 $tbl = new self(); | |
| 149 $sqlstr = "SELECT * FROM ".$tbl->table." " .$options; | |
| 150 $result = $tbl->__query( $sqlstr ); | |
| 151 } | |
| 152 catch( Exception $e ) { | |
| 153 throw $e; | |
| 154 } | |
| 155 if( $result === false ) throw new exception("レコードが存在しません"); | |
| 156 while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { | |
| 157 array_push( $retval, new self('id', $row['id']) ); | |
| 158 } | |
| 159 return $retval; | |
| 160 } | |
| 161 | |
| 162 public function __destruct() { | |
| 163 parent::__destruct(); | |
| 164 } | |
| 165 } | |
|
130
290a05fd7331
mod: ?????????????????????????
Sushi-k <epgrec@park.mda.or.jp>
parents:
115
diff
changeset
|
166 ?> |
