Mercurial > epgrec.yaz
annotate Keyword.class.php @ 68:25736d81c66d
modified: config.php.sample
author | Sushi-k <epgrec@park.mda.or.jp> |
---|---|
date | Wed, 21 Oct 2009 16:57:26 +0900 |
parents | 8965ef108821 |
children | 3d6e7c606896 |
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 | |
19 private function getPrograms() { | |
20 if( $this->id == 0 ) return false; | |
21 | |
22 // ちょっと先を検索する | |
37
e5f9aa34d06f
change: modify all script for web base setting
yoneda <epgrec@park.mda.or.jp>
parents:
1
diff
changeset
|
23 $options = " WHERE starttime > '".date("Y-m-d H:i:s", time() + $this->settings->padding_time + 120 )."'"; |
1 | 24 |
25 if( $this->keyword != "" ) { | |
26 if( $this->use_regexp ) { | |
27 $options .= " AND CONCAT(title,description) REGEXP '".mysql_real_escape_string($this->keyword)."'"; | |
28 } | |
29 else { | |
30 $options .= " AND CONCAT(title,description) like '%".mysql_real_escape_string($this->keyword)."%'"; | |
31 } | |
32 } | |
33 | |
34 if( $this->type != "*" ) { | |
35 $options .= " AND type = '".$this->type."'"; | |
36 } | |
37 | |
38 if( $this->category_id != 0 ) { | |
39 $options .= " AND category_id = '".$this->category_id."'"; | |
40 } | |
41 | |
42 if( $this->channel_id != 0 ) { | |
43 $options .= " AND channel_id = '".$this->channel_id."'"; | |
44 } | |
45 | |
46 $options .= " ORDER BY starttime ASC"; | |
47 | |
48 $recs = array(); | |
49 try { | |
37
e5f9aa34d06f
change: modify all script for web base setting
yoneda <epgrec@park.mda.or.jp>
parents:
1
diff
changeset
|
50 $recs = DBRecord::createRecords( PROGRAM_TBL, $options ); |
1 | 51 } |
52 catch( Exception $e ) { | |
53 throw $e; | |
54 } | |
55 | |
56 return $recs; | |
57 } | |
58 | |
59 | |
60 public function reservation() { | |
61 if( $this->id == 0 ) return; | |
62 | |
63 $precs = array(); | |
64 try { | |
65 $precs = $this->getPrograms(); | |
66 } | |
67 catch( Exception $e ) { | |
68 throw $e; | |
69 } | |
70 if( count($precs) < 300 ) { | |
71 // 一気に録画予約 | |
72 foreach( $precs as $rec ) { | |
73 try { | |
74 if( $rec->autorec ) { | |
75 Reservation::simple( $rec->id, $this->id ); | |
76 usleep( 100 ); // あんまり時間を空けないのもどう? | |
77 } | |
78 } | |
79 catch( Exception $e ) { | |
80 // 無視 | |
81 } | |
82 } | |
83 } | |
84 else { | |
85 throw new Exception( "300件以上の自動録画は実行できません" ); | |
86 } | |
87 } | |
88 | |
89 public function delete() { | |
90 if( $this->id == 0 ) return; | |
91 | |
92 $precs = array(); | |
93 try { | |
94 $precs = $this->getPrograms(); | |
95 } | |
96 catch( Exception $e ) { | |
97 throw $e; | |
98 } | |
99 // 一気にキャンセル | |
100 foreach( $precs as $rec ) { | |
101 try { | |
37
e5f9aa34d06f
change: modify all script for web base setting
yoneda <epgrec@park.mda.or.jp>
parents:
1
diff
changeset
|
102 $reserve = new DBRecord( RESERVE_TBL, "program_id", $rec->id ); |
1 | 103 // 自動予約されたもののみ削除 |
104 if( $reserve->autorec ) { | |
105 Reservation::cancel( $reserve->id ); | |
106 usleep( 100 ); // あんまり時間を空けないのもどう? | |
107 } | |
108 } | |
109 catch( Exception $e ) { | |
110 // 無視 | |
111 } | |
112 } | |
113 try { | |
114 parent::delete(); | |
115 } | |
116 catch( Exception $e ) { | |
117 throw $e; | |
118 } | |
119 } | |
120 | |
121 // staticなファンクションはオーバーライドできない | |
122 static function createKeywords( $options = "" ) { | |
123 $retval = array(); | |
124 $arr = array(); | |
125 try{ | |
126 $tbl = new self(); | |
127 $sqlstr = "SELECT * FROM ".$tbl->table." " .$options; | |
128 $result = $tbl->__query( $sqlstr ); | |
129 } | |
130 catch( Exception $e ) { | |
131 throw $e; | |
132 } | |
133 if( $result === false ) throw new exception("レコードが存在しません"); | |
134 while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { | |
135 array_push( $retval, new self('id', $row['id']) ); | |
136 } | |
137 return $retval; | |
138 } | |
139 | |
140 public function __destruct() { | |
141 parent::__destruct(); | |
142 } | |
143 } | |
144 ?> |