Download the PHP package rashiku/colrow-php-sdk without Composer
On this page you can find all versions of the php package rashiku/colrow-php-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package colrow-php-sdk
COLROW PHP SDK
COLROW PHP SDK は、PHP 環境にて COLROW API を利用するための SDK です。
インストール方法
Composer を使います。まずはプロジェクトのルートディレクトリにて、以下の composer.json を作成し、php composer.phar install を実行してください。
以下のように記述することで COLROW PHP SDK が利用できるようになります。
何らかの事情で Composer が使えない場合は、ファイル一式をダウンロードし、Colrow フォルダをそのままお使いください。上記の autoload.php の代わりに以下のように記述し、必要なファイル群を読み込んでください。
※PHP のバージョンは 5.4 以上である必要があります。
初期化
SDK から必要なファイルを読み込んだ後、ColrowClient を初期化する必要があります(ColrowDrive だけは例外)。
3つの引数はそれぞれ「COLROW に登録した Google アカウント」「スプレッドシートの key」「ワークシート名」になります。
基本的な使い方
利用する機能に応じたクラスを use 文にて宣言します。大抵のケースでは、以下の3つのクラス(のうちいずれか)を宣言することになるでしょう。
オブジェクトとして全件取得:
最初の1件を取得:
クエリ(後述)を指定して取得:
件数をカウント:
シートに新しい行を追加:
行の内容を更新:
行を削除:
COLROW オブジェクト
ColrowQuery クラス経由で取得したオブジェクトは、get メソッドによって内容を参照できます。
その他にも、以下のメソッドが利用可能です。
- set(label, value) ... オブジェクトの label(列のラベル名)に value をセット
- save() ... オブジェクトを保存。シートの該当行の内容も更新(新規作成した場合は最終行に追加)
- destroy() ... オブジェクトを削除。シートの該当行も削除
- getId() ... オブジェクトの ID(=該当行に割り当てられた固有の ID)を参照
- toJson() ... JSON 文字列に変換(デバッグ用)
クエリ
シートの内容を抽出するため、ColrowQuery クラスのインスタンスに対して、SQL の where 句に相当する以下のメソッドが用意されています。
- equalTo(label, value) ... label の値が value に等しい
- notEqualTo(label, value) ... label の値が value に等しくない
- lessThan(label, value) ... label の値が value より小さい
- greaterThan(label, value) ... label の値が value より大きい
- lessThanOrEqualTo(label, value) ... label の値が value より小さいか等しい
- greaterThanOrEqualTo(label, value) ... label の値が value より大きいか等しい
- exists(label) ... label の値が空ではない
- doesNotExist(label) ... label の値が空である
上記の条件を複数列記することで AND として扱われます。
OR の場合は ColrowQuery のインスタンスを個別に作成し、orQuery メソッドを使います。
その他にも以下のメソッドが利用可能です。
- orderBy(label) ... label の値でソート(デフォルトは昇順)
- reverse(boolean) ... true を指定することでソートを降順に変更
- offset(number) ... 指定した列数をスキップ
- limit(number) ... 取得する列数を指定
ColrowDrive について
Google ドライブにファイルをアップロードするために用意された ColrowDrive クラスは、前述した他のクラスとはやや使用感が異なります。
$parent_id はファイルのアップロード先、つまり Google ドライブのフォルダの ID になります。そのフォルダのページの URL の https://drive.google.com/drive/u/0/folders/
以降に書かれているのがそれです。また、ColrowDrive::upload() の第1引数には、COLROW に登録した Google アカウントを指定してください。