OSDN Git Service

mod: キーワード検索を整理
authoryoneda <epgrec@park.mda.or.jp>
Sat, 13 Mar 2010 14:00:51 +0000 (23:00 +0900)
committeryoneda <epgrec@park.mda.or.jp>
Sat, 13 Mar 2010 14:00:51 +0000 (23:00 +0900)
Keyword.class.php
programTable.php
tableStruct.inc.php

index b262f80..3d104f8 100755 (executable)
@@ -16,42 +16,51 @@ class Keyword extends DBRecord {
                }
        }
        
-       private function getPrograms() {
-               if( $this->id == 0 ) return false;
+       static public function search(  $keyword = "", 
+                                                                       $use_regexp = false,
+                                                                       $type = "*", 
+                                                                       $category_id = 0,
+                                                                       $channel_id = 0,
+                                                                       $weekofday = 7,
+                                                                       $prgtime = 24,
+                                                                       $limit = 300 ) {
+               $sts = Settings::factory();
+               
+               $dbh = @mysql_connect($sts->db_host, $sts->db_user, $sts->db_pass );
                
                // ちょっと先を検索する
-               $options = " WHERE starttime > '".date("Y-m-d H:i:s", time() + $this->settings->padding_time + 120 )."'";
+               $options = " WHERE starttime > '".date("Y-m-d H:i:s", time() + $sts->padding_time + 60 )."'";
                
-               if( $this->keyword != "" ) {
-                       if( $this->use_regexp ) {
-                               $options .= " AND CONCAT(title,description) REGEXP '".mysql_real_escape_string($this->keyword)."'";
+               if( $keyword != "" ) {
+                       if( $use_regexp ) {
+                               $options .= " AND CONCAT(title,description) REGEXP '".mysql_real_escape_string($keyword)."'";
                        }
                        else {
-                               $options .= " AND CONCAT(title,description) like '%".mysql_real_escape_string($this->keyword)."%'";
+                               $options .= " AND CONCAT(title,description) like '%".mysql_real_escape_string($keyword)."%'";
                        }
                }
                
-               if( $this->type != "*" ) {
-                       $options .= " AND type = '".$this->type."'";
+               if( $type != "*" ) {
+                       $options .= " AND type = '".$type."'";
                }
                
-               if( $this->category_id != 0 ) {
-                       $options .= " AND category_id = '".$this->category_id."'";
+               if( $category_id != 0 ) {
+                       $options .= " AND category_id = '".$category_id."'";
                }
                
-               if( $this->channel_id != 0 ) {
-                       $options .= " AND channel_id = '".$this->channel_id."'";
+               if( $channel_id != 0 ) {
+                       $options .= " AND channel_id = '".$channel_id."'";
                }
                
-               if( $this->weekofday != 7 ) {
-                       $options .= " AND WEEKDAY(starttime) = '".$this->weekofday."'";
+               if( $weekofday != 7 ) {
+                       $options .= " AND WEEKDAY(starttime) = '".$weekofday."'";
                }
                
-               if( $this->prgtime != 24 ) {
-                       $options .= " AND time(starttime) BETWEEN cast('".sprintf( "%02d:00:00", $this->prgtime)."' as time) AND cast('".sprintf("%02d:59:59", $this->prgtime)."' as time)";
+               if( $prgtime != 24 ) {
+                       $options .= " AND time(starttime) BETWEEN cast('".sprintf( "%02d:00:00", $prgtime)."' as time) AND cast('".sprintf("%02d:59:59", $prgtime)."' as time)";
                }
                
-               $options .= " ORDER BY starttime ASC";
+               $options .= " ORDER BY starttime ASC  LIMIT ".$limit ;
                
                $recs = array();
                try {
@@ -63,6 +72,17 @@ class Keyword extends DBRecord {
                return $recs;
        }
        
+       private function getPrograms() {
+               if( $this->id == 0 ) return false;
+               $recs = array();
+               try {
+                        $recs = self::search( trim($this->keyword), $this->use_regexp, $this->type, $this->category_id, $this->channel_id, $this->weekofday, $this->prgtime );
+               }
+               catch( Exception $e ) {
+                       throw $e;
+               }
+               return $recs;
+       }
        
        public function reservation() {
                if( $this->id == 0 ) return;
@@ -74,22 +94,17 @@ class Keyword extends DBRecord {
                catch( Exception $e ) {
                        throw $e;
                }
-               if( count($precs) < 300 ) {
-                       // 一気に録画予約
-                       foreach( $precs as $rec ) {
-                               try {
-                                       if( $rec->autorec ) {
-                                               Reservation::simple( $rec->id, $this->id, $this->autorec_mode );
-                                               usleep( 100 );          // あんまり時間を空けないのもどう?
-                                       }
-                               }
-                               catch( Exception $e ) {
-                                       // 無視
+               // 一気に録画予約
+               foreach( $precs as $rec ) {
+                       try {
+                               if( $rec->autorec ) {
+                                       Reservation::simple( $rec->id, $this->id, $this->autorec_mode );
+                                       usleep( 100 );          // あんまり時間を空けないのもどう?
                                }
                        }
-               }
-               else {
-                       throw new Exception( "300件以上の自動録画は実行できません" );
+                       catch( Exception $e ) {
+                               // 無視
+                       }
                }
        }
        
index d6f900a..3d57aaa 100755 (executable)
@@ -3,6 +3,7 @@ include_once('config.php');
 include_once( INSTALL_PATH . '/DBRecord.class.php' );
 include_once( INSTALL_PATH . '/Smarty/Smarty.class.php' );
 include_once( INSTALL_PATH . '/Settings.class.php' );
+include_once( INSTALL_PATH . '/Keyword.class.php' );
 
 $settings = Settings::factory();
 
@@ -24,72 +25,45 @@ $weekofdays = array(
 $autorec_modes = $RECORD_MODE;
 $autorec_modes[(int)($settings->autorec_mode)]['selected'] = "selected";
 
-$weekofday = 7;
 $search = "";
 $use_regexp = 0;
 $type = "*";
 $category_id = 0;
-$station = 0;
+$channel_id = 0;
+$weekofday = 7;
 $prgtime = 24;
 
-
-// mysql_real_escape_stringより先に接続しておく必要がある
-$dbh = @mysql_connect($settings->db_host, $settings->db_user, $settings->db_pass );
-
-       // パラメータの処理
+// パラメータの処理
 if(isset( $_POST['do_search'] )) {
        if( isset($_POST['search'])){
-               if( $_POST['search'] != "" ) {
-                       $search = $_POST['search'];
-                       if( isset($_POST['use_regexp']) && ($_POST['use_regexp']) ) {
-                               $use_regexp = $_POST['use_regexp'];
-                               $options .= " AND CONCAT(title,description) REGEXP '".mysql_real_escape_string($search)."'";
-                       }
-                       else {
-                               $options .= " AND CONCAT(title,description) like '%".mysql_real_escape_string($search)."%'";
-                       }
+               $search = $_POST['search'];
+               if( isset($_POST['use_regexp']) && ($_POST['use_regexp']) ) {
+                       $use_regexp = (int)($_POST['use_regexp']);
                }
        }
        if( isset($_POST['type'])){
-               if( $_POST['type'] != "*" ) {
-                       $type = $_POST['type'];
-                       $options .= " AND type = '".$_POST['type']."'";
-               }
+               $type = $_POST['type'];
        }
        if( isset($_POST['category_id'])) {
-               if( $_POST['category_id'] != 0 ) {
-                       $category_id = $_POST['category_id'];
-                       $options .= " AND category_id = '".$_POST['category_id']."'";
-               }
+               $category_id = (int)($_POST['category_id']);
        }
        if( isset($_POST['station'])) {
-               if( $_POST['station'] != 0 ) {
-                       $station = $_POST['station'];
-                       $options .= " AND channel_id = '".$_POST['station']."'";
-               }
+               $channel_id = (int)($_POST['station']);
        }
        if( isset($_POST['weekofday']) ) {
-               $weekofday = $_POST['weekofday'];
-               if( $weekofday != 7 ) {
-                       $options .= " AND WEEKDAY(starttime) = '".$weekofday."'";
-               }
+               $weekofday = (int)($_POST['weekofday']);
        }
        if( isset($_POST['prgtime']) ) {
                $prgtime = (int)($_POST['prgtime']);
-               if( $prgtime != 24 ) {
-                       $options .= " AND time(starttime) BETWEEN cast('".sprintf( "%02d:00:00", $prgtime)."' as time) AND cast('".sprintf("%02d:59:59", $prgtime)."' as time)";
-               }
        }
 }
-$options .= " ORDER BY starttime ASC LIMIT 300";
-
 
 $do_keyword = 0;
-if( ($search != "") || ($type != "*") || ($category_id != 0) || ($station != 0) )
+if( ($search != "") || ($type != "*") || ($category_id != 0) || ($channel_id != 0) )
        $do_keyword = 1;
        
 try{
-       $precs = DBRecord::createRecords(PROGRAM_TBL, $options );
+       $precs = Keyword::search( $search, $use_regexp, $type, $category_id, $channel_id, $weekofday, $prgtime );
        
        $programs = array();
        foreach( $precs as $p ) {
@@ -157,13 +131,13 @@ try{
        $stations = array();
        $stations[0]['id'] = 0;
        $stations[0]['name'] = "すべて";
-       $stations[0]['selected'] = (! $station) ? "selected" : "";
+       $stations[0]['selected'] = (! $channel_id) ? "selected" : "";
        foreach( $crecs as $c ) {
                $arr = array();
                $arr['id'] = $c->id;
                $arr['name'] = $c->name;
-               $arr['selected'] = $station == $c->id ? "selected" : "";
-               if( $station == $c->id ) $k_station_name = $c->name;
+               $arr['selected'] = $channel_id == $c->id ? "selected" : "";
+               if( $channel_id == $c->id ) $k_station_name = $c->name;
                array_push( $stations, $arr );
        }
        $weekofdays["$weekofday"]["selected"] = "selected" ;
@@ -192,7 +166,7 @@ try{
        $smarty->assign( "search" , $search );
        $smarty->assign( "use_regexp", $use_regexp );
        $smarty->assign( "stations", $stations );
-       $smarty->assign( "k_station", $station );
+       $smarty->assign( "k_station", $channel_id );
        $smarty->assign( "k_station_name", $k_station_name );
        $smarty->assign( "weekofday", $weekofday );
        $smarty->assign( "k_weekofday", $weekofdays["$weekofday"]["name"] );
@@ -206,4 +180,4 @@ try{
 catch( exception $e ) {
        exit( $e->getMessage() );
 }
-?>
+?>
\ No newline at end of file
index c84cbd7..2ec35b5 100755 (executable)
@@ -20,7 +20,7 @@ define( "RESERVE_STRUCT",
        "complete boolean not null default '0',".                                               // 完了フラグ
        "reserve_disc varchar(128) not null default 'none',".                   // 識別用hash
        "autorec integer not null default '0',".                                                // キーワードID
-       "mode integer not null default '0',".                                                   //録画モード
+       "mode integer not null default '0',".                                                   // 録画モード
        "index reserve_ch_idx (channel_disc),".                                                 // インデックス
        "index reserve_st_idx (starttime)".
        ""