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