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