2017 © Pedro Peláez
 

cakephp-plugin csv-combine-plugin-for-cakephp

CakePHP CsvCombine

image

satthi/csv-combine-plugin-for-cakephp

CakePHP CsvCombine

  • Friday, December 15, 2017
  • by satthi
  • Repository
  • 3 Watchers
  • 16 Stars
  • 7,267 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 19 Versions
  • 29 % Grown

The README.md

今後、新しくご利用の方は https://github.com/satthi/csv-combine をご利用ください。

CsvCombine plugin for CakePHP3

Build Status Scrutinizer Code Quality, (*1)

PHP versions 5 CakePHP version 3, (*2)

更新履歴

  • 2015/05/01 CakePHP3用に書き換え
  • 2016/05/17 固定長対応追加

特徴

  • 配列 ⇔ CSV・TSVファイルを行う機能
  • Cake1.3や2ではファイルのアップロードであったり、保存まで管理していたが自分で使ってなかったので削除しました・・・。
  • 固定長に対応しました!

準備

※copmposer対応しました, (*3)

"satthi/csv-combine-plugin-for-cakephp": "*"

※composerでインストールしないとき pluginsディレクトリ内にCsvCombineを設置, (*4)

bootstrapに以下を記述, (*5)

Plugin::load('CsvCombine', ['autoload' => true]);

使い方(CSV)

<?php
namespace App\Controller;

use Cake\Core\Configure;

use CsvCombine\Form\CsvImportForm;

class CsvController extends AppController
{
    public function initialize()
    {
        parent::initialize();
        $this->loadComponent('CsvCombine.CsvExport');
    }
    public function export()
    {
        $list = [
            [
                'test1',
                'test2',
                'test3',
            ],
            [
                'test4',
                'test5',
                'test6',
            ],
        ];
        /*
         *@array $list 出力のための配列(二次元配列が基本)
         *@param $file_name 出力ファイル名(デフォルトはexport.csv)
         *@param $delimiter 区切り文字の設定(デフォルトは",")
         *@param $directory 一時保存ディレクトリ(デフォルトはTMP,最終的にファイルを削除をする)
         *@param $export_encoding 出力するファイルのエンコード(デフォルトはSJIS-win
         *@param $array_encoding 入力する配列のエンコード(デフォルトはUTF-8
        */
        return $this->CsvExport->export($list);
    }

    public function import()
    {
        $import = new CsvImportForm();
        $file = TMP . 'test.csv';
        $column = [
            'key1',
            'key2',
            'key3',
        ];
        /*
         *@array file ファイルパス(必須
         *@array $column カラム名を並び順に(必須
         *@param $delimiter 区切り文字を設定 (デフォルトは","で"\t"や"|"などを指定することが可能)
         *@param $array_encoding 出力する配列のエンコード(デフォルトはUTF-8
         *@param $import_encoding 入力するファイルのエンコード(デフォルトはSJIS-win
        */
        $result = $import->loadDataCsv($file,$column);
        debug($result);
        exit;
    }
}

使い方(固定長)

<?php
namespace App\Controller;

use Cake\Core\Configure;

use CsvCombine\Form\FixedLengthImportForm;

class CsvController extends AppController
{
    public function initialize()
    {
        parent::initialize();
        $this->loadComponent('CsvCombine.FixedLengthExport');
    }

    public function export()
    {
        $list = [
            [
                'あいう',
                'いいい',
                'uuu',
            ],
            [
                'あいう',
                'いいい',
                'uuu',
            ],
            [
                'あいう',
                'いいい',
                'uuu',
            ],
        ];
        $fixed_options = [
            8,
            10,
            6
        ];
        //makeでファイル作成のみ
        /*
         * export 固定長の出力アクション
         *
         * @array $list 出力のための配列(二次元配列が基本)
         * @array $fixed_options 出力のための固定長の設定(各カラムのバイト数)
         * @param $file_name 出力ファイル名(デフォルトはexport.txt)
         * @param $line_feed_code 改行コード(デフォルトは\r\n)
         * @param $directory 一時保存ディレクトリ(デフォルトはTMP,最終的に削除をする)
         * @param $export_encoding 出力するファイルのエンコード(デフォルトはSJIS-win
         * @param $array_encoding 入力する配列のエンコード(デフォルトはUTF-8
         */

        //$this->FixedLengthExport->make($list,$fixed_options);
        $this->FixedLengthExport->export($list,$fixed_options);

    }

    public function import()
    {
        $filename = TMP . 'test.txt';
        $column_list = [
            ['name' => 'column1', 'length' => 8],
            ['name' => 'column2', 'length' => 10],
            ['name' => 'column3', 'length' => 6],
        ];
        $import = new FixedLengthImportForm();
        /*
         * @text $fileName 固定長テキストファイ
         * @array $column_list 各カラム情報(name:カラム名,length:バイト数 デフォルトは空配列 空時には列の数だけ0から連番を振る)
         * @param $line_feed_code 改行コード(デフォルトは\r\n)
         * @param $array_encoding 出力するする配列のエンコード(デフォルトはUTF-8
         * @param $import_encoding 入力するテキストのエンコード(デフォルトはSJIS-win
         */
        $result = $import->loadData($filename, $column_list);
        debug($result);
        exit;
    }
}

License

The MIT Lisence, (*6)

Copyright (c) 2011 Fusic Co., Ltd. (http://fusic.co.jp), (*7)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:, (*8)

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software., (*9)

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE., (*10)

Author

Satoru Hagiwara, (*11)

The Versions

15/12 2017

dev-master

9999999-dev https://github.com/satthi/csv-combine-plugin-for-CakePHP

CakePHP CsvCombine

  Sources   Download

MIT

The Requires

 

The Development Requires

by Satoru Hagiwara

csv cakephp

26/09 2017

dev-cake2

dev-cake2 https://github.com/satthi/csv-combine-plugin-for-CakePHP

CakePHP CsvCombine

  Sources   Download

MIT

by Satoru Hagiwara

csv cakephp

26/09 2017

v2.0.0

2.0.0.0 https://github.com/satthi/csv-combine-plugin-for-CakePHP

CakePHP CsvCombine

  Sources   Download

MIT

by Satoru Hagiwara

csv cakephp

05/09 2017

v3.2.8

3.2.8.0 https://github.com/satthi/csv-combine-plugin-for-CakePHP

CakePHP CsvCombine

  Sources   Download

MIT

The Requires

 

The Development Requires

by Satoru Hagiwara

csv cakephp

05/09 2017

v3.2.7

3.2.7.0 https://github.com/satthi/csv-combine-plugin-for-CakePHP

CakePHP CsvCombine

  Sources   Download

MIT

The Requires

 

The Development Requires

by Satoru Hagiwara

csv cakephp

01/08 2017

v3.2.6

3.2.6.0 https://github.com/satthi/csv-combine-plugin-for-CakePHP

CakePHP CsvCombine

  Sources   Download

MIT

The Requires

 

The Development Requires

by Satoru Hagiwara

csv cakephp

18/01 2017

v3.2.5

3.2.5.0 https://github.com/satthi/csv-combine-plugin-for-CakePHP

CakePHP CsvCombine

  Sources   Download

MIT

The Requires

 

The Development Requires

by Satoru Hagiwara

csv cakephp

14/12 2016

v3.2.4

3.2.4.0 https://github.com/satthi/csv-combine-plugin-for-CakePHP

CakePHP CsvCombine

  Sources   Download

MIT

The Requires

 

The Development Requires

by Satoru Hagiwara

csv cakephp

14/12 2016

dev-loadDataColumnListEmptySet

dev-loadDataColumnListEmptySet https://github.com/satthi/csv-combine-plugin-for-CakePHP

CakePHP CsvCombine

  Sources   Download

MIT

The Requires

 

The Development Requires

by Satoru Hagiwara

csv cakephp

08/09 2016

v3.2.3

3.2.3.0 https://github.com/satthi/csv-combine-plugin-for-CakePHP

CakePHP CsvCombine

  Sources   Download

MIT

The Requires

 

The Development Requires

by Satoru Hagiwara

csv cakephp

08/09 2016

3.2.2

3.2.2.0 https://github.com/satthi/csv-combine-plugin-for-CakePHP

CakePHP CsvCombine

  Sources   Download

MIT

The Requires

 

The Development Requires

by Satoru Hagiwara

csv cakephp

26/08 2016

v3.2.0

3.2.0.0 https://github.com/satthi/csv-combine-plugin-for-CakePHP

CakePHP CsvCombine

  Sources   Download

MIT

The Requires

 

The Development Requires

by Satoru Hagiwara

csv cakephp

26/08 2016

v3.2.1

3.2.1.0 https://github.com/satthi/csv-combine-plugin-for-CakePHP

CakePHP CsvCombine

  Sources   Download

MIT

The Requires

 

The Development Requires

by Satoru Hagiwara

csv cakephp

27/05 2016

3.1.3

3.1.3.0 https://github.com/satthi/csv-combine-plugin-for-CakePHP

CakePHP CsvCombine

  Sources   Download

MIT

The Requires

 

The Development Requires

by Satoru Hagiwara

csv cakephp

27/05 2016

3.1.2

3.1.2.0 https://github.com/satthi/csv-combine-plugin-for-CakePHP

CakePHP CsvCombine

  Sources   Download

MIT

The Requires

 

The Development Requires

by Satoru Hagiwara

csv cakephp

19/05 2016

v3.1.1

3.1.1.0 https://github.com/satthi/csv-combine-plugin-for-CakePHP

CakePHP CsvCombine

  Sources   Download

MIT

The Requires

 

The Development Requires

by Satoru Hagiwara

csv cakephp

17/05 2016

v3.1.0

3.1.0.0 https://github.com/satthi/csv-combine-plugin-for-CakePHP

CakePHP CsvCombine

  Sources   Download

MIT

The Requires

 

The Development Requires

by Satoru Hagiwara

csv cakephp

16/07 2015

dev-cake3

dev-cake3 https://github.com/satthi/csv-combine-plugin-for-CakePHP

CakePHP CsvCombine

  Sources   Download

MIT

The Requires

 

The Development Requires

by Satoru Hagiwara

csv cakephp

01/05 2015

v3.0

3.0.0.0 https://github.com/satthi/csv-combine-plugin-for-CakePHP

CakePHP CsvCombine

  Sources   Download

MIT

The Requires

 

by Satoru Hagiwara

csv cakephp