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" );
6 include_once( INSTALL_PATH . '/Settings.class.php' );
7 include_once( INSTALL_PATH . '/recLog.inc.php' );
9 class Keyword extends DBRecord {
11 public function __construct($property = null, $value = null ) {
13 parent::__construct(KEYWORD_TBL, $property, $value );
15 catch( Exception $e ) {
20 static public function search( $keyword = "",
28 $sts = Settings::factory();
30 $dbh = @mysql_connect($sts->db_host, $sts->db_user, $sts->db_pass );
33 $options = " WHERE starttime > '".date("Y-m-d H:i:s", time() + $sts->padding_time + 60 )."'";
35 if( $keyword != "" ) {
37 $options .= " AND CONCAT(title,description) REGEXP '".mysql_real_escape_string($keyword)."'";
40 $options .= " AND CONCAT(title,description) like _utf8'%".mysql_real_escape_string($keyword)."%' collate utf8_unicode_ci";
45 $options .= " AND type = '".$type."'";
48 if( $category_id != 0 ) {
49 $options .= " AND category_id = '".$category_id."'";
52 if( $channel_id != 0 ) {
53 $options .= " AND channel_id = '".$channel_id."'";
56 if( $weekofday != 7 ) {
57 $options .= " AND WEEKDAY(starttime) = '".$weekofday."'";
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)";
64 $options .= " ORDER BY starttime ASC LIMIT ".$limit ;
68 $recs = DBRecord::createRecords( PROGRAM_TBL, $options );
70 catch( Exception $e ) {
76 private function getPrograms() {
77 if( $this->__id == 0 ) return false;
80 $recs = self::search( trim($this->keyword), $this->use_regexp, $this->type, $this->category_id, $this->channel_id, $this->weekofday, $this->prgtime );
82 catch( Exception $e ) {
88 public function reservation() {
89 if( $this->__id == 0 ) return;
93 $precs = $this->getPrograms();
95 catch( Exception $e ) {
99 foreach( $precs as $rec ) {
101 if( $rec->autorec ) {
102 Reservation::simple( $rec->id, $this->__id, $this->autorec_mode );
103 reclog( "Keyword.class::キーワードID".$this->id."の録画が予約された");
104 usleep( 100 ); // あんまり時間を空けないのもどう?
107 catch( Exception $e ) {
113 public function delete() {
114 if( $this->id == 0 ) return;
118 $precs = $this->getPrograms();
120 catch( Exception $e ) {
124 foreach( $precs as $rec ) {
126 $reserve = new DBRecord( RESERVE_TBL, "program_id", $rec->id );
128 if( $reserve->autorec ) {
129 Reservation::cancel( $reserve->id );
130 usleep( 100 ); // あんまり時間を空けないのもどう?
133 catch( Exception $e ) {
140 catch( Exception $e ) {
145 // staticなファンクションはオーバーライドできない
146 static function createKeywords( $options = "" ) {
151 $sqlstr = "SELECT * FROM ".$tbl->__table." " .$options;
152 $result = $tbl->__query( $sqlstr );
154 catch( Exception $e ) {
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']) );
164 public function __destruct() {
165 parent::__destruct();