-
Notifications
You must be signed in to change notification settings - Fork 5
/
Keyword.class.php
168 lines (148 loc) · 4.09 KB
/
Keyword.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
include_once('config.php');
include_once( INSTALL_PATH . "/DBRecord.class.php" );
include_once( INSTALL_PATH . "/reclib.php" );
include_once( INSTALL_PATH . "/Reservation.class.php" );
include_once( INSTALL_PATH . '/Settings.class.php' );
include_once( INSTALL_PATH . '/recLog.inc.php' );
class Keyword extends DBRecord {
public function __construct($property = null, $value = null ) {
try {
parent::__construct(KEYWORD_TBL, $property, $value );
}
catch( Exception $e ) {
throw $e;
}
}
static public function search( $keyword = "",
$use_regexp = false,
$type = "*",
$category_id = 0,
$channel_id = 0,
$weekofday = 7,
$prgtime = 24,
$limit = 300 ) {
$sts = Settings::factory();
$dbh = @mysql_connect($sts->db_host, $sts->db_user, $sts->db_pass );
// ちょっと先を検索する
$options = " WHERE starttime > '".date("Y-m-d H:i:s", time() + $sts->padding_time + 60 )."'";
if( $keyword != "" ) {
if( $use_regexp ) {
$options .= " AND CONCAT(title,description) REGEXP '".mysql_real_escape_string($keyword)."'";
}
else {
$options .= " AND CONCAT(title,description) like _utf8'%".mysql_real_escape_string($keyword)."%' collate utf8_unicode_ci";
}
}
if( $type != "*" ) {
$options .= " AND type = '".$type."'";
}
if( $category_id != 0 ) {
$options .= " AND category_id = '".$category_id."'";
}
if( $channel_id != 0 ) {
$options .= " AND channel_id = '".$channel_id."'";
}
if( $weekofday != 7 ) {
$options .= " AND WEEKDAY(starttime) = '".$weekofday."'";
}
if( $prgtime != 24 ) {
$options .= " AND time(starttime) BETWEEN cast('".sprintf( "%02d:00:00", $prgtime)."' as time) AND cast('".sprintf("%02d:59:59", $prgtime)."' as time)";
}
$options .= " ORDER BY starttime ASC LIMIT ".$limit ;
$recs = array();
try {
$recs = DBRecord::createRecords( PROGRAM_TBL, $options );
}
catch( Exception $e ) {
throw $e;
}
return $recs;
}
private function getPrograms() {
if( $this->__id == 0 ) return false;
$recs = array();
try {
$recs = self::search( trim($this->keyword), $this->use_regexp, $this->type, $this->category_id, $this->channel_id, $this->weekofday, $this->prgtime );
}
catch( Exception $e ) {
throw $e;
}
return $recs;
}
public function reservation() {
if( $this->__id == 0 ) return;
$precs = array();
try {
$precs = $this->getPrograms();
}
catch( Exception $e ) {
throw $e;
}
// 一気に録画予約
foreach( $precs as $rec ) {
try {
if( $rec->autorec ) {
Reservation::simple( $rec->id, $this->__id, $this->autorec_mode );
reclog( "Keyword.class::キーワードID".$this->id."の録画が予約された");
usleep( 100 ); // あんまり時間を空けないのもどう?
}
}
catch( Exception $e ) {
// 無視
}
}
}
public function delete() {
if( $this->id == 0 ) return;
$precs = array();
try {
$precs = $this->getPrograms();
}
catch( Exception $e ) {
throw $e;
}
// 一気にキャンセル
foreach( $precs as $rec ) {
try {
$reserve = new DBRecord( RESERVE_TBL, "program_id", $rec->id );
// 自動予約されたもののみ削除
if( $reserve->autorec ) {
Reservation::cancel( $reserve->id );
usleep( 100 ); // あんまり時間を空けないのもどう?
}
}
catch( Exception $e ) {
// 無視
}
}
try {
parent::delete();
}
catch( Exception $e ) {
throw $e;
}
}
// staticなファンクションはオーバーライドできない
static function createKeywords( $options = "" ) {
$retval = array();
$arr = array();
try{
$tbl = new self();
$sqlstr = "SELECT * FROM ".$tbl->__table." " .$options;
$result = $tbl->__query( $sqlstr );
}
catch( Exception $e ) {
throw $e;
}
if( $result === false ) throw new exception("レコードが存在しません");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
array_push( $retval, new self('id', $row['id']) );
}
return $retval;
}
public function __destruct() {
parent::__destruct();
}
}
?>