comparison 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
comparison
equal deleted inserted replaced
114:f854f6606fa5 115:7a64d5e3baee
14 catch( Exception $e ) { 14 catch( Exception $e ) {
15 throw $e; 15 throw $e;
16 } 16 }
17 } 17 }
18 18
19 private function getPrograms() { 19 static public function search( $keyword = "",
20 if( $this->id == 0 ) return false; 20 $use_regexp = false,
21 $type = "*",
22 $category_id = 0,
23 $channel_id = 0,
24 $weekofday = 7,
25 $prgtime = 24,
26 $limit = 300 ) {
27 $sts = Settings::factory();
28
29 $dbh = @mysql_connect($sts->db_host, $sts->db_user, $sts->db_pass );
21 30
22 // <c罎膣≪ 31 // <c罎膣≪
23 $options = " WHERE starttime > '".date("Y-m-d H:i:s", time() + $this->settings->padding_time + 120 )."'"; 32 $options = " WHERE starttime > '".date("Y-m-d H:i:s", time() + $sts->padding_time + 60 )."'";
24 33
25 if( $this->keyword != "" ) { 34 if( $keyword != "" ) {
26 if( $this->use_regexp ) { 35 if( $use_regexp ) {
27 $options .= " AND CONCAT(title,description) REGEXP '".mysql_real_escape_string($this->keyword)."'"; 36 $options .= " AND CONCAT(title,description) REGEXP '".mysql_real_escape_string($keyword)."'";
28 } 37 }
29 else { 38 else {
30 $options .= " AND CONCAT(title,description) like '%".mysql_real_escape_string($this->keyword)."%'"; 39 $options .= " AND CONCAT(title,description) like '%".mysql_real_escape_string($keyword)."%'";
31 } 40 }
32 } 41 }
33 42
34 if( $this->type != "*" ) { 43 if( $type != "*" ) {
35 $options .= " AND type = '".$this->type."'"; 44 $options .= " AND type = '".$type."'";
36 } 45 }
37 46
38 if( $this->category_id != 0 ) { 47 if( $category_id != 0 ) {
39 $options .= " AND category_id = '".$this->category_id."'"; 48 $options .= " AND category_id = '".$category_id."'";
40 } 49 }
41 50
42 if( $this->channel_id != 0 ) { 51 if( $channel_id != 0 ) {
43 $options .= " AND channel_id = '".$this->channel_id."'"; 52 $options .= " AND channel_id = '".$channel_id."'";
44 } 53 }
45 54
46 if( $this->weekofday != 7 ) { 55 if( $weekofday != 7 ) {
47 $options .= " AND WEEKDAY(starttime) = '".$this->weekofday."'"; 56 $options .= " AND WEEKDAY(starttime) = '".$weekofday."'";
48 } 57 }
49 58
50 if( $this->prgtime != 24 ) { 59 if( $prgtime != 24 ) {
51 $options .= " AND time(starttime) BETWEEN cast('".sprintf( "%02d:00:00", $this->prgtime)."' as time) AND cast('".sprintf("%02d:59:59", $this->prgtime)."' as time)"; 60 $options .= " AND time(starttime) BETWEEN cast('".sprintf( "%02d:00:00", $prgtime)."' as time) AND cast('".sprintf("%02d:59:59", $prgtime)."' as time)";
52 } 61 }
53 62
54 $options .= " ORDER BY starttime ASC"; 63 $options .= " ORDER BY starttime ASC LIMIT ".$limit ;
55 64
56 $recs = array(); 65 $recs = array();
57 try { 66 try {
58 $recs = DBRecord::createRecords( PROGRAM_TBL, $options ); 67 $recs = DBRecord::createRecords( PROGRAM_TBL, $options );
59 } 68 }
61 throw $e; 70 throw $e;
62 } 71 }
63 return $recs; 72 return $recs;
64 } 73 }
65 74
75 private function getPrograms() {
76 if( $this->id == 0 ) return false;
77 $recs = array();
78 try {
79 $recs = self::search( trim($this->keyword), $this->use_regexp, $this->type, $this->category_id, $this->channel_id, $this->weekofday, $this->prgtime );
80 }
81 catch( Exception $e ) {
82 throw $e;
83 }
84 return $recs;
85 }
66 86
67 public function reservation() { 87 public function reservation() {
68 if( $this->id == 0 ) return; 88 if( $this->id == 0 ) return;
69 89
70 $precs = array(); 90 $precs = array();
72 $precs = $this->getPrograms(); 92 $precs = $this->getPrograms();
73 } 93 }
74 catch( Exception $e ) { 94 catch( Exception $e ) {
75 throw $e; 95 throw $e;
76 } 96 }
77 if( count($precs) < 300 ) { 97 // 筝羂牙私膣
78 // 筝羂牙私膣 98 foreach( $precs as $rec ) {
79 foreach( $precs as $rec ) { 99 try {
80 try { 100 if( $rec->autorec ) {
81 if( $rec->autorec ) { 101 Reservation::simple( $rec->id, $this->id, $this->autorec_mode );
82 Reservation::simple( $rec->id, $this->id, $this->autorec_mode ); 102 usleep( 100 ); // 障腥冴?
83 usleep( 100 ); // 障腥冴?
84 }
85 }
86 catch( Exception $e ) {
87 // ∴
88 } 103 }
89 } 104 }
90 } 105 catch( Exception $e ) {
91 else { 106 // ∴
92 throw new Exception( "300篁銀札筝牙祉絎茵с障" ); 107 }
93 } 108 }
94 } 109 }
95 110
96 public function delete() { 111 public function delete() {
97 if( $this->id == 0 ) return; 112 if( $this->id == 0 ) return;