Mercurial > epgrec.yaz
annotate 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 |
rev | line source |
---|---|
1 | 1 <?php |
2 include_once('config.php'); | |
3 include_once( INSTALL_PATH . "/DBRecord.class.php" ); | |
4 include_once( INSTALL_PATH . "/reclib.php" ); | |
5 include_once( INSTALL_PATH . "/Reservation.class.php" ); | |
37
e5f9aa34d06f
change: modify all script for web base setting
yoneda <epgrec@park.mda.or.jp>
parents:
1
diff
changeset
|
6 include_once( INSTALL_PATH . '/Settings.class.php' ); |
1 | 7 |
8 class Keyword extends DBRecord { | |
9 | |
10 public function __construct($property = null, $value = null ) { | |
11 try { | |
37
e5f9aa34d06f
change: modify all script for web base setting
yoneda <epgrec@park.mda.or.jp>
parents:
1
diff
changeset
|
12 parent::__construct(KEYWORD_TBL, $property, $value ); |
1 | 13 } |
14 catch( Exception $e ) { | |
15 throw $e; | |
16 } | |
17 } | |
18 | |
115 | 19 static public function search( $keyword = "", |
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 ); | |
1 | 30 |
31 // <c罎膣≪ | |
115 | 32 $options = " WHERE starttime > '".date("Y-m-d H:i:s", time() + $sts->padding_time + 60 )."'"; |
1 | 33 |
115 | 34 if( $keyword != "" ) { |
35 if( $use_regexp ) { | |
36 $options .= " AND CONCAT(title,description) REGEXP '".mysql_real_escape_string($keyword)."'"; | |
1 | 37 } |
38 else { | |
115 | 39 $options .= " AND CONCAT(title,description) like '%".mysql_real_escape_string($keyword)."%'"; |
1 | 40 } |
41 } | |
42 | |
115 | 43 if( $type != "*" ) { |
44 $options .= " AND type = '".$type."'"; | |
1 | 45 } |
46 | |
115 | 47 if( $category_id != 0 ) { |
48 $options .= " AND category_id = '".$category_id."'"; | |
1 | 49 } |
50 | |
115 | 51 if( $channel_id != 0 ) { |
52 $options .= " AND channel_id = '".$channel_id."'"; | |
1 | 53 } |
54 | |
115 | 55 if( $weekofday != 7 ) { |
56 $options .= " AND WEEKDAY(starttime) = '".$weekofday."'"; | |
77 | 57 } |
58 | |
115 | 59 if( $prgtime != 24 ) { |
60 $options .= " AND time(starttime) BETWEEN cast('".sprintf( "%02d:00:00", $prgtime)."' as time) AND cast('".sprintf("%02d:59:59", $prgtime)."' as time)"; | |
106 | 61 } |
62 | |
115 | 63 $options .= " ORDER BY starttime ASC LIMIT ".$limit ; |
1 | 64 |
65 $recs = array(); | |
66 try { | |
37
e5f9aa34d06f
change: modify all script for web base setting
yoneda <epgrec@park.mda.or.jp>
parents:
1
diff
changeset
|
67 $recs = DBRecord::createRecords( PROGRAM_TBL, $options ); |
1 | 68 } |
69 catch( Exception $e ) { | |
70 throw $e; | |
71 } | |
72 return $recs; | |
73 } | |
74 | |
115 | 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 } | |
1 | 86 |
87 public function reservation() { | |
88 if( $this->id == 0 ) return; | |
89 | |
90 $precs = array(); | |
91 try { | |
92 $precs = $this->getPrograms(); | |
93 } | |
94 catch( Exception $e ) { | |
95 throw $e; | |
96 } | |
115 | 97 // 筝羂牙私膣 |
98 foreach( $precs as $rec ) { | |
99 try { | |
100 if( $rec->autorec ) { | |
101 Reservation::simple( $rec->id, $this->id, $this->autorec_mode ); | |
102 usleep( 100 ); // 障腥冴? | |
1 | 103 } |
104 } | |
115 | 105 catch( Exception $e ) { |
106 // ∴ | |
107 } | |
1 | 108 } |
109 } | |
110 | |
111 public function delete() { | |
112 if( $this->id == 0 ) return; | |
113 | |
114 $precs = array(); | |
115 try { | |
116 $precs = $this->getPrograms(); | |
117 } | |
118 catch( Exception $e ) { | |
119 throw $e; | |
120 } | |
121 // 筝羂c潟祉 | |
122 foreach( $precs as $rec ) { | |
123 try { | |
37
e5f9aa34d06f
change: modify all script for web base setting
yoneda <epgrec@park.mda.or.jp>
parents:
1
diff
changeset
|
124 $reserve = new DBRecord( RESERVE_TBL, "program_id", $rec->id ); |
1 | 125 // 篋膣水 |
126 if( $reserve->autorec ) { | |
127 Reservation::cancel( $reserve->id ); | |
128 usleep( 100 ); // 障腥冴? | |
129 } | |
130 } | |
131 catch( Exception $e ) { | |
132 // ∴ | |
133 } | |
134 } | |
135 try { | |
136 parent::delete(); | |
137 } | |
138 catch( Exception $e ) { | |
139 throw $e; | |
140 } | |
141 } | |
142 | |
143 // static<潟激с潟若若ゃс | |
144 static function createKeywords( $options = "" ) { | |
145 $retval = array(); | |
146 $arr = array(); | |
147 try{ | |
148 $tbl = new self(); | |
149 $sqlstr = "SELECT * FROM ".$tbl->table." " .$options; | |
150 $result = $tbl->__query( $sqlstr ); | |
151 } | |
152 catch( Exception $e ) { | |
153 throw $e; | |
154 } | |
155 if( $result === false ) throw new exception("潟若絖障"); | |
156 while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { | |
157 array_push( $retval, new self('id', $row['id']) ); | |
158 } | |
159 return $retval; | |
160 } | |
161 | |
162 public function __destruct() { | |
163 parent::__destruct(); | |
164 } | |
165 } | |
166 ?> |