Mercurial > epgrec.yaz
comparison storeProgram.inc.php @ 111:3bed74eca373
change: EPG取得並列化が可能かどうかを判定するように変更
author | epgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp> |
---|---|
date | Sat, 13 Mar 2010 16:45:29 +0900 |
parents | |
children | ef3df87f3c7d |
comparison
equal
deleted
inserted
replaced
108:4bd07b03c694 | 111:3bed74eca373 |
---|---|
1 <?php | |
2 | |
3 function garbageClean() { | |
4 // 筝荀違 | |
5 // 8ヤ札筝違羔 | |
6 $arr = array(); | |
7 $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE endtime < subdate( now(), 8 )" ); | |
8 foreach( $arr as $val ) $val->delete(); | |
9 | |
10 // 8ヤ札筝若帥井 | |
11 $arr = array(); | |
12 $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE starttime > adddate( now(), 8 )" ); | |
13 foreach( $arr as $val ) $val->delete(); | |
14 } | |
15 | |
16 function doKeywordReservation() { | |
17 // 若若牙私膣 | |
18 $arr = array(); | |
19 $arr = Keyword::createKeywords(); | |
20 foreach( $arr as $val ) { | |
21 try { | |
22 $val->reservation(); | |
23 } | |
24 catch( Exception $e ) { | |
25 // ∴ | |
26 } | |
27 } | |
28 } | |
29 | |
30 function storeProgram( $type, $xmlfile ) { | |
31 global $BS_CHANNEL_MAP, $GR_CHANNEL_MAP, $CS_CHANNEL_MAP; | |
32 // c潟<ゃ羣 | |
33 $map = array(); | |
34 if( $type == "BS" ) $map = $BS_CHANNEL_MAP; | |
35 else if( $type == "GR") $map = $GR_CHANNEL_MAP; | |
36 else if( $type == "CS") $map = $CS_CHANNEL_MAP; | |
37 | |
38 // XML parse | |
39 $xml = @simplexml_load_file( $xmlfile ); | |
40 if( $xml === false ) { | |
41 return; // XML茯水篏 | |
42 } | |
43 // channel遵 | |
44 foreach( $xml->channel as $ch ) { | |
45 $disc = $ch['id']; | |
46 try { | |
47 // c潟若帥「 | |
48 $num = DBRecord::countRecords( CHANNEL_TBL , "WHERE channel_disc = '" . $disc ."'" ); | |
49 if( $num == 0 ) { | |
50 if( array_key_exists( "$disc", $map ) ) { | |
51 // c潟若帥域鋎 | |
52 $rec = new DBRecord( CHANNEL_TBL ); | |
53 $rec->type = $type; | |
54 $rec->channel = $map["$disc"]; | |
55 $rec->channel_disc = $disc; | |
56 $rec->name = $ch->{'display-name'}; | |
57 } | |
58 } | |
59 else { | |
60 // 絖翫c潟贋違 | |
61 $rec = new DBRecord(CHANNEL_TBL, "channel_disc", $disc ); | |
62 $rec->name = $ch->{'display-name'}; | |
63 } | |
64 } | |
65 catch( Exception $e ) { | |
66 // ∴ | |
67 } | |
68 } | |
69 // channel 腟篋 | |
70 | |
71 // programme 緇 | |
72 | |
73 foreach( $xml->programme as $program ) { | |
74 $channel_disc = $program['channel']; | |
75 if( ! array_key_exists( "$channel_disc", $map ) ) continue; | |
76 | |
77 $channel = $map["$channel_disc"]; | |
78 $starttime = str_replace(" +0900", '', $program['start'] ); | |
79 $endtime = str_replace( " +0900", '', $program['stop'] ); | |
80 $title = $program->title; | |
81 $desc = $program->desc; | |
82 $cat_ja = ""; | |
83 $cat_en = ""; | |
84 foreach( $program->category as $cat ) { | |
85 if( $cat['lang'] == "ja_JP" ) $cat_ja = $cat; | |
86 if( $cat['lang'] == "en" ) $cat_en = $cat; | |
87 } | |
88 $program_disc = md5( $channel_disc . $starttime . $endtime ); | |
89 // printf( "%s %s %s %s %s %s %s \n", $program_disc, $channel, $starttime, $endtime, $title, $desc, $cat_ja ); | |
90 try { | |
91 // 眼 | |
92 $category_disc = md5( $cat_ja . $cat_en ); | |
93 $num = DBRecord::countRecords(CATEGORY_TBL, "WHERE category_disc = '".$category_disc."'" ); | |
94 $cat_rec = null; | |
95 if( $num == 0 ) { | |
96 // 域眼菴遵 | |
97 $cat_rec = new DBRecord( CATEGORY_TBL ); | |
98 $cat_rec->name_jp = $cat_ja; | |
99 $cat_rec->name_en = $cat_en; | |
100 $cat_rec->category_disc = $category_disc; | |
101 } | |
102 else | |
103 $cat_rec = new DBRecord(CATEGORY_TBL, "category_disc" , $category_disc ); | |
104 // | |
105 $channel_rec = new DBRecord(CHANNEL_TBL, "channel_disc", $channel_disc ); | |
106 $num = DBRecord::countRecords(PROGRAM_TBL, "WHERE program_disc = '".$program_disc."'" ); | |
107 if( $num == 0 ) { | |
108 // 域腟 | |
109 // 茲с 絽腟 | |
110 $options = "WHERE channel_disc = '".$channel_disc."' ". | |
111 "AND starttime < '". $endtime ."' AND endtime > '".$starttime."'"; | |
112 $battings = DBRecord::countRecords(PROGRAM_TBL, $options ); | |
113 if( $battings > 0 ) { | |
114 // 茲榊鐚丈紊 | |
115 $records = DBRecord::createRecords(PROGRAM_TBL, $options ); | |
116 foreach( $records as $rec ) { | |
117 // 牙私膣腟丈紊眼cゃ | |
118 try { | |
119 $reserve = new DBRecord(RESERVE_TBL, "program_id", $rec->id ); | |
120 if( $reserve->autorec ) { | |
121 Reservation::cancel( $reserve->id ); | |
122 } | |
123 } | |
124 catch( Exception $e ) { | |
125 //∴ | |
126 } | |
127 // 腟 | |
128 $rec->delete(); | |
129 } | |
130 } | |
131 // // | |
132 $rec = new DBRecord( PROGRAM_TBL ); | |
133 $rec->channel_disc = $channel_disc; | |
134 $rec->channel_id = $channel_rec->id; | |
135 $rec->type = $type; | |
136 $rec->channel = $channel_rec->channel; | |
137 $rec->title = $title; | |
138 $rec->description = $desc; | |
139 $rec->category_id = $cat_rec->id; | |
140 $rec->starttime = $starttime; | |
141 $rec->endtime = $endtime; | |
142 $rec->program_disc = $program_disc; | |
143 } | |
144 else { | |
145 // 腟絎号贋 | |
146 $rec = new DBRecord( PROGRAM_TBL, "program_disc", $program_disc ); | |
147 $rec->title = $title; | |
148 $rec->description = $desc; | |
149 $rec->category_id = $cat_rec->id; | |
150 } | |
151 } | |
152 catch(Exception $e) { | |
153 exit( $e->getMessage() ); | |
154 } | |
155 } | |
156 // Programme緇絎篋 | |
157 } | |
158 ?> |