Skip to content

Commit

Permalink
Generating Configure file for prefecture and city. Close #6. Close #7
Browse files Browse the repository at this point in the history
  • Loading branch information
kanonji committed Sep 27, 2010
1 parent eb05f6b commit 73f251e
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 3 deletions.
50 changes: 50 additions & 0 deletions config/prefecture.php
@@ -0,0 +1,50 @@
<?php
$config['prefecture'] = array(
'01' => '北海道',
'02' => '青森県',
'03' => '岩手県',
'04' => '宮城県',
'05' => '秋田県',
'06' => '山形県',
'07' => '福島県',
'08' => '茨城県',
'09' => '栃木県',
'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' => '沖縄県'
);
60 changes: 57 additions & 3 deletions vendors/shells/zipcode.php
Expand Up @@ -9,18 +9,26 @@ public function main(){
$this->hr();
$this->out(__('[I]nitialize zipcodes database table', true));
$this->out(__('[D]ownload csv and save to zipcodes table', true));
$this->out(__('[P] Generate prefecture.php for Configure', true));
$this->out(__('[C] Generate city.php for Configure', true));
$this->out(__('[J]SON for AjaxZip(not yet)', true));
$this->out(__('[H]elp', true));
$this->out(__('[Q]uit', true));

$choice = strtolower($this->in(__('What would you like to do?', true), array('I', 'D', 'J', 'H', 'Q')));
$choice = strtolower($this->in(__('What would you like to do?', true), array('I', 'D', 'P', 'C', 'J', 'H', 'Q')));
switch ($choice) {
case 'i':
$this->initdb();
break;
case 'd':
$this->download();
break;
case 'p':
$this->configurePrefecture();
break;
case 'c':
$this->configureCity();
break;
case 'j':
$this->json();
break;
Expand All @@ -31,7 +39,7 @@ public function main(){
exit(0);
break;
default:
$this->out(__('You have made an invalid selection. Please choose a command to execute by entering I, D, J, H, or Q.', true));
$this->out(__('You have made an invalid selection. Please choose a command to execute by entering I, D, P, C, J, H, or Q.', true));
}
$this->hr();
$this->main();
Expand Down Expand Up @@ -61,6 +69,52 @@ public function download(){
$this->saveBulk();
}

public function configurePrefecture(){
$target = realpath(APP.'/config/prefecture.php');
$source = dirname(dirname(dirname(__FILE__))).'/config/prefecture.php';
if(file_exists($target)){
$this->out(__('prefecture.php exists already at...', true));
$this->out($target,2);
$this->out(__('You can rename and copy this file...', true));
$this->out($source);
return;
}
if(false === copy($source, $target)){
$this->out(__('Something wrong to copy a file', true));
return;
}
$this->out(__('prefecture.php is copied to...', true));
$this->out($target);
}

public function configureCity(){
$options['group'] = 'city';
$options['fields'] = array('jiscode', 'city');
$results = $this->Zipcode->find('all', $options);
foreach($results as $item){
$array[$item['Zipcode']['jiscode']] = $item['Zipcode']['city'];
}
$array = var_export($array, true);
$code = "<?php\n\$config['city'] = {$array}";
$target = realpath(APP.'/config/city.php');
$file = new File(TMP.'city_'.time().'.php', true);
$file->write($code);
if(file_exists($target)){
$this->out(__('city.php exists already at...', true));
$this->out($target,2);
$this->out(__('File for Configure is written.', true));
$this->out(__('You can rename and move this file...', true));
$this->out($file->pwd());
} else {
if(false === rename($file->pwd(),$target)){
$this->out(__('Something wrong to move a file', true));
return;
}
$this->out(__('city.php is written to...', true));
$this->out($target);
}
}

public function json(){
$this->out(__('Not implimented yet', 2));
}
Expand Down Expand Up @@ -186,4 +240,4 @@ private function convertWithPHP($path){
$str = mb_convert_encoding($str, mb_internal_encoding(), $encoding);
return file_put_contents(TMP.'ken_all.csv', $str);
}
}
}'

0 comments on commit 73f251e

Please sign in to comment.