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" );
7 class Keyword extends DBRecord {
9 public function __construct($property = null, $value = null ) {
11 parent::__construct(TBL_PREFIX.KEYWORD_TBL, $property, $value );
13 catch( Exception $e ) {
18 private function getPrograms() {
19 if( $this->id == 0 ) return false;
22 $options = " WHERE starttime > '".date("Y-m-d H:i:s", time() + PADDING_TIME + 120 )."'";
24 if( $this->keyword != "" ) {
25 if( $this->use_regexp ) {
26 $options .= " AND CONCAT(title,description) REGEXP '".mysql_real_escape_string($this->keyword)."'";
29 $options .= " AND CONCAT(title,description) like '%".mysql_real_escape_string($this->keyword)."%'";
33 if( $this->type != "*" ) {
34 $options .= " AND type = '".$this->type."'";
37 if( $this->category_id != 0 ) {
38 $options .= " AND category_id = '".$this->category_id."'";
41 if( $this->channel_id != 0 ) {
42 $options .= " AND channel_id = '".$this->channel_id."'";
45 $options .= " ORDER BY starttime ASC";
49 $recs = DBRecord::createRecords( TBL_PREFIX.PROGRAM_TBL, $options );
51 catch( Exception $e ) {
59 public function reservation() {
60 if( $this->id == 0 ) return;
64 $precs = $this->getPrograms();
66 catch( Exception $e ) {
69 if( count($precs) < 300 ) {
71 foreach( $precs as $rec ) {
74 Reservation::simple( $rec->id, $this->id );
75 usleep( 100 ); // あんまり時間を空けないのもどう?
78 catch( Exception $e ) {
84 throw new Exception( "300件以上の自動録画は実行できません" );
88 public function delete() {
89 if( $this->id == 0 ) return;
93 $precs = $this->getPrograms();
95 catch( Exception $e ) {
99 foreach( $precs as $rec ) {
101 $reserve = new DBRecord( TBL_PREFIX.RESERVE_TBL, "program_id", $rec->id );
103 if( $reserve->autorec ) {
104 Reservation::cancel( $reserve->id );
105 usleep( 100 ); // あんまり時間を空けないのもどう?
108 catch( Exception $e ) {
115 catch( Exception $e ) {
120 // staticなファンクションはオーバーライドできない
121 static function createKeywords( $options = "" ) {
126 $sqlstr = "SELECT * FROM ".$tbl->table." " .$options;
127 $result = $tbl->__query( $sqlstr );
129 catch( Exception $e ) {
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']) );
139 public function __destruct() {
140 parent::__destruct();