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 include_once( INSTALL_PATH . '/Settings.class.php' );
8 class Keyword extends DBRecord {
10 public function __construct($property = null, $value = null ) {
12 parent::__construct(KEYWORD_TBL, $property, $value );
14 catch( Exception $e ) {
19 private function getPrograms() {
20 if( $this->id == 0 ) return false;
23 $options = " WHERE starttime > '".date("Y-m-d H:i:s", time() + $this->settings->padding_time + 120 )."'";
25 if( $this->keyword != "" ) {
26 if( $this->use_regexp ) {
27 $options .= " AND CONCAT(title,description) REGEXP '".mysql_real_escape_string($this->keyword)."'";
30 $options .= " AND CONCAT(title,description) like '%".mysql_real_escape_string($this->keyword)."%'";
34 if( $this->type != "*" ) {
35 $options .= " AND type = '".$this->type."'";
38 if( $this->category_id != 0 ) {
39 $options .= " AND category_id = '".$this->category_id."'";
42 if( $this->channel_id != 0 ) {
43 $options .= " AND channel_id = '".$this->channel_id."'";
46 $options .= " ORDER BY starttime ASC";
50 $recs = DBRecord::createRecords( PROGRAM_TBL, $options );
52 catch( Exception $e ) {
60 public function reservation() {
61 if( $this->id == 0 ) return;
65 $precs = $this->getPrograms();
67 catch( Exception $e ) {
70 if( count($precs) < 300 ) {
72 foreach( $precs as $rec ) {
75 Reservation::simple( $rec->id, $this->id );
76 usleep( 100 ); // あんまり時間を空けないのもどう?
79 catch( Exception $e ) {
85 throw new Exception( "300件以上の自動録画は実行できません" );
89 public function delete() {
90 if( $this->id == 0 ) return;
94 $precs = $this->getPrograms();
96 catch( Exception $e ) {
100 foreach( $precs as $rec ) {
102 $reserve = new DBRecord( RESERVE_TBL, "program_id", $rec->id );
104 if( $reserve->autorec ) {
105 Reservation::cancel( $reserve->id );
106 usleep( 100 ); // あんまり時間を空けないのもどう?
109 catch( Exception $e ) {
116 catch( Exception $e ) {
121 // staticなファンクションはオーバーライドできない
122 static function createKeywords( $options = "" ) {
127 $sqlstr = "SELECT * FROM ".$tbl->table." " .$options;
128 $result = $tbl->__query( $sqlstr );
130 catch( Exception $e ) {
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']) );
140 public function __destruct() {
141 parent::__destruct();