diff Reservation.class.php @ 159:66eabfc1b118

revoke all whitespace modifications
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Wed, 31 Mar 2010 06:42:51 +0900
parents 3a6ec345ab0c
children 3d4df1fe4166
line wrap: on
line diff
--- a/Reservation.class.php	Wed Mar 31 06:16:04 2010 +0900
+++ b/Reservation.class.php	Wed Mar 31 06:42:51 2010 +0900
@@ -9,13 +9,13 @@
 // 予約クラス
 
 class Reservation {
-
+	
 	public static function simple( $program_id , $autorec = 0, $mode = 0) {
 		$settings = Settings::factory();
 		$rval = 0;
 		try {
 			$prec = new DBRecord( PROGRAM_TBL, "id", $program_id );
-
+			
 			$rval = self::custom(
 				$prec->starttime,
 				$prec->endtime,
@@ -26,14 +26,14 @@
 				$program_id,
 				$autorec,
 				$mode );
-
+				
 		}
 		catch( Exception $e ) {
 			throw $e;
 		}
 		return $rval;
 	}
-
+	
 	public static function custom(
 		$starttime,				// 開始時間Datetime型
 		$endtime,				// 終了時間Datetime型
@@ -52,20 +52,20 @@
 		// 時間を計算
 		$start_time = toTimestamp( $starttime );
 		$end_time = toTimestamp( $endtime ) + $settings->extra_time;
-
+		
 		if( $start_time < (time() + PADDING_TIME + 10) ) {	// 現在時刻より3分先より小さい=すでに開始されている番組
 			$start_time = time() + PADDING_TIME + 10;		// 録画開始時間を3分10秒先に設定する
 		}
 		$at_start = $start_time - PADDING_TIME;
 		$sleep_time = PADDING_TIME - $settings->former_time;
 		$rec_start = $start_time - $settings->former_time;
-
+		
 		// durationを計算しておく
 		$duration = $end_time - $rec_start;
 		if( $duration < ($settings->former_time + 60) ) {	// 60秒以下の番組は弾く
 			throw new Exception( "終わりつつある/終わっている番組です" );
 		}
-
+		
 		$rrec = null;
 		try {
 			// 同一番組予約チェック
@@ -75,19 +75,19 @@
 					throw new Exception("同一の番組が録画予約されています");
 				}
 			}
-
+			
 			$crec = new DBRecord( CHANNEL_TBL, "id", $channel_id );
-
+			
 			// 既存予約数 = TUNER番号
 			$tuners = ($crec->type == "GR") ? (int)($settings->gr_tuners) : (int)($settings->bs_tuners);
 			$type_str = ($crec->type == "GR") ? "type = 'GR' " : "(type = 'BS' OR type = 'CS') ";
-
+			
 			$battings = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' ".
 															  "AND ".$type_str.
 															  "AND starttime < '".toDatetime($end_time) ."' ".
 															  "AND endtime > '".toDatetime($rec_start)."'"
 			);
-
+			
 			if( $battings >= $tuners ) {
 				// 重複を発見した
 				if( $settings->force_cont_rec == 1 ) {
@@ -96,15 +96,15 @@
 					$nexts = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' ".
 																	"AND ".$type_str.
 																	"AND starttime = '".toDatetime($end_time - $settings->former_time)."'");
-
+					
 					$prevs = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' ".
 																"AND ".$type_str.
 																"AND endtime = '".$starttime."'"  );
-
+					
 					// 前後を引いてもチューナー数と同数以上なら重複の解消は無理
 					if( ($battings - $nexts - $prevs) >= $tuners )
 						throw new Exception( "重複予約を解消できません" );
-
+					
 					// 直後の番組はあるか?
 					if( $nexts ) {
 						// この番組の終わりをちょっとだけ早める
@@ -112,7 +112,7 @@
 						$duration = $end_time - $rec_start;		// durationを計算しなおす
 					}
 					$battings -= $nexts;
-
+					
 					// 直前の録画予約を見付ける
 					$trecs = DBRecord::createRecords(RESERVE_TBL, "WHERE complete = '0' ".
 																		 "AND ".$type_str.
@@ -140,13 +140,13 @@
 							$prev_starttime = toDatetime( $prev_start_time + $settings->former_time );
 							// 終わりをちょっとだけずらす
 							$prev_endtime   = toDatetime( toTimestamp($prev_endtime) - $settings->former_time - $settings->rec_switch_time );
-
+							
 							// tryのネスト
 							try {
 								// いったん予約取り消し
 								self::cancel( $prev_id );
 								// 再予約
-								self::custom(
+								self::custom( 
 									$prev_starttime,			// 開始時間Datetime型
 									$prev_endtime,				// 終了時間Datetime型
 									$prev_channel_id,			// チャンネルID
@@ -176,7 +176,7 @@
 			}
 			// チューナー番号
 			$tuner = $battings;
-
+			
 			// 改めてdurationをチェックしなおす
 			if( $duration < ($settings->former_time + 60) ) {	// 60秒以下の番組は弾く
 				throw new Exception( "終わりつつある/終わっている番組です" );
@@ -242,14 +242,14 @@
 			
 			$filename .= $RECORD_MODE["$mode"]['suffix'];
 			$thumbname = $filename.".jpg";
-
+			
 			// サムネール
 			$gen_thumbnail = INSTALL_PATH."/gen-thumbnail.sh";
-			if( defined("GEN_THUMBNAIL") )
+			if( defined("GEN_THUMBNAIL") ) 
 				$gen_thumbnail = GEN_THUMBNAIL;
-
+			
 			// ファイル名生成終了
-
+			
 			// 予約レコードを埋める
 			$rrec = new DBRecord( RESERVE_TBL );
 			$rrec->channel_disc = $crec->channel_disc;
@@ -266,7 +266,7 @@
 			$rrec->autorec = $autorec;
 			$rrec->mode = $mode;
 			$rrec->reserve_disc = md5( $crec->channel_disc . toDatetime( $start_time ). toDatetime( $end_time ) );
-
+			
 			// 予約実行
 			$cmdline = $settings->at." ".date("H:i m/d/Y", $at_start);
 			$descriptor = array( 0 => array( "pipe", "r" ),
@@ -284,7 +284,7 @@
 			              "FFMPEG"   => "".$settings->ffmpeg,
 			              "SID"      => $crec->sid,
 			);
-
+			
 			// ATで予約する
 			$process = proc_open( $cmdline , $descriptor, $pipes, INSTALL_PATH.$settings->spool, $env );
 			if( is_resource( $process ) ) {
@@ -297,7 +297,7 @@
 				fclose($pipes[0]);
 				// 標準エラーを取る
 				$rstring = stream_get_contents( $pipes[2]);
-
+				
 			    fclose( $pipes[2] );
 			    proc_close( $process );
 			}
@@ -337,12 +337,12 @@
 		}
 	}
 	// custom 終了
-
+	
 	// 取り消し
 	public static function cancel( $reserve_id = 0, $program_id = 0 ) {
 		$settings = Settings::factory();
 		$rec = null;
-
+		
 		try {
 			if( $reserve_id ) {
 				$rec = new DBRecord( RESERVE_TBL, "id" , $reserve_id );