changeset 115:7a64d5e3baee

mod: キーワード検索を整理
author yoneda <epgrec@park.mda.or.jp>
date Sat, 13 Mar 2010 23:00:51 +0900
parents f854f6606fa5
children f268d7d10590
files Keyword.class.php programTable.php tableStruct.inc.php
diffstat 3 files changed, 66 insertions(+), 77 deletions(-) [+]
line wrap: on
line diff
--- a/Keyword.class.php	Sat Mar 13 21:37:27 2010 +0900
+++ b/Keyword.class.php	Sat Mar 13 23:00:51 2010 +0900
@@ -16,42 +16,51 @@
 		}
 	}
 	
-	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 );
 		
 		// <c罎膣≪
-		$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 @@
 		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 @@
 		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 ) {
+				// ∴
+			}
 		}
 	}
 	
--- a/programTable.php	Sat Mar 13 21:37:27 2010 +0900
+++ b/programTable.php	Sat Mar 13 23:00:51 2010 +0900
@@ -3,6 +3,7 @@
 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 @@
 $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 @@
 	$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 @@
 	$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 @@
 catch( exception $e ) {
 	exit( $e->getMessage() );
 }
-?>
+?>
\ No newline at end of file
--- a/tableStruct.inc.php	Sat Mar 13 21:37:27 2010 +0900
+++ b/tableStruct.inc.php	Sat Mar 13 23:00:51 2010 +0900
@@ -20,7 +20,7 @@
 	"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)".
 	""