diff Keyword.class.php @ 115:7a64d5e3baee

mod: キーワード検索を整理
author yoneda <epgrec@park.mda.or.jp>
date Sat, 13 Mar 2010 23:00:51 +0900
parents 57676bb30f64
children db185340a981 290a05fd7331
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 ) {
+				// ∴
+			}
 		}
 	}