2,052
edits
(初期翻訳: Enから複製) Tag: 2017 source edit |
PolyglotBot (talk | contribs) m (Adding interlang links (links to translated versions of this page in other languages) triggered by origin English page "Module_development" update.) |
||
| (17 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
<!-- BEGIN | <!-- BEGIN interlang links --> | ||
<!-- | <!-- Do NOT edit this section | ||
Links below | Links below are automatically managed by PolyglotBot | ||
You can edit links on the English source page : Module_development --> | |||
[[en:Module_development]] | |||
[[fr:Développement_module]] | [[fr:Développement_module]] | ||
[[es:Desarrollo_de_un_módulo]] | [[es:Desarrollo_de_un_módulo]] | ||
| Line 11: | Line 13: | ||
{{TemplateDocDevEn}} | {{TemplateDocDevEn}} | ||
Dolibarr向け新規 モジュール/アドオン を作成するには, 複数のステップがある. | Dolibarr向け新規 モジュール/アドオン を作成するには, 複数のステップがある. このチュートリアルで記述するのは、Dolibarrの特質拡張用モジュールを作るステップのそれぞれである, 以下の1つとか、複数の組み合わせとかのように : | ||
* | *データベースに新規テーブルを追加. | ||
* | *自前メニュー項目を追加. | ||
* | *新規テーブル編集用の新規画面を追加. | ||
* | *オブジェクトビュー (請求,製品,注文,イベント, ...) に関わるタブの追加または削除. | ||
* | *内部エキスポートツール向けの事前定義済のエクスポートを追加. | ||
* | *ホームページに新規情報ウィジェットを追加. | ||
* | *新規置換変数を追加. | ||
* | *新規許認可を定義. | ||
* | *特定の Dolibarr アクションにより自動トリガされるコードを実行. | ||
* | *Dolibarr フックポジション内に自分のコードを挿入. | ||
* | *オブジェクト参照を生成するための自前の番号付けルールを追加 | ||
* | *新規文書テンプレートを追加. | ||
* | *新規スキンを追加. | ||
etc... | etc... | ||
以下の章では、これらすべてを手作業で簡単に行う方法を示す. | |||
= | =モジュールビルダ によるモジュールの生成= | ||
Dolibarr 9.0 から、モジュールビルダにより、自前モジュールのメインページ作成が可能. 起動方法は: | |||
* | *モジュールリストにて、"モジュールビルダ(Module Builder)"を有効化する, | ||
[[File:Mod_builder_2.png|400px]] | [[File:Mod_builder_2.png|400px]] | ||
* | *その後 "バグ(bug)" 画像をクリック、場所は画面右上. | ||
[[File:Mod_builder_3.png|400px]] | [[File:Mod_builder_3.png|400px]] | ||
= | =テンプレート外部モジュールの例= | ||
外部モジュールの開発を開始するのによいお手本は、ここで見つかるだろう : [https://github.com/Dolibarr/dolibarr/tree/develop/htdocs/modulebuilder/template GitHub Dolibarr Module Modèle] | |||
= | =自前モジュールを作る= | ||
== | ==自前モジュールに関するモジュール記述(Module descriptor)を作る (必須)== | ||
''' | '''必須となる時期''': アドオンを開発すると早急に必要、たとえゴールが何であれ (例外はスキンの追加). | ||
''' | '''Dolibarr 9.0 から, モジュールビルダ (ModuleBuilder) モジュールを使用すべきだ、モジュール記述を生成するための標準モデルとして使える''' | ||
=== | ===自前のモジュール記述 (module descriptor) を作成する=== | ||
最初のステップは、モジュールに対するファイル記述 (file descriptor) を作成すること. (訳者注: 以下の内容は'''モジュールビルダを使うことで自動設定'''される) | |||
* | *ディレクトリ作成: '''/htdocs/custom/''mymodule''/core/modules''' (外部モジュール向け) または '''/htdocs/''mymodule''/core/modules''' ここはDolibarr の公式コアモジュール (official core module) とする場合. 次にファイル modMyModule.class.php をディレクトリ '''htdocs/modulebuilder/template''' からコピーして上記のディレクトリに作成. ファイルの名称を modMyModule.class.php から 自前モジュールの目的に合致した名称に変更. ファイル名は、先頭に 'mod' があり、最後が .class.php で終わる (例えば、ファイル名を '新名' にするなら, 'mod新名.class.php' となる). | ||
次は、ファイルの内容を以下のように変更: | |||
* | *すべての "modMyModule" をモジュールの目的に合致した値に置換. この値は必ず 'mod' で始まりアルファベットのみで構成 (繰り返すが, もしファイルに付けた名称が 'NewName' なら, すべての "modMyModule" を "modNewName" で置換). | ||
* | *番号を変更: $this->numero = 100000 の部分で、自前モジュールIDを指定する値に. 他のモジュールとの競合を避けるため、すでに予約されているid番号の一覧ページを参考にできる: [[List of modules id|List of modules id]]. | ||
* | *コンストラクタで定義されたその他の変数(意味についてはコード雛形のコメントを参照)を変更. | ||
自前モジュールのファイルディスクリプタの準備ができた。有効化するには次ステップを参照. | |||
=== | ===自前記述をテストする=== | ||
Dolibarrを起動し、'''設定->モジュール (Setup->module'''?) ページを表示. | |||
モジュール記述でプロパティバージョン (property version) を設定すると、自前の新規モジュールを載せた新規行とそれを有効化するかどうかの選択が表示されるはず. プロパティバージョンを "develop" または "experimental" に設定した場合、自前モジュールを見るには、まず '''設定->その他 (Setup-Others)''' に行き、 MAIN_FEATURES_LEVEL を 1 に設定してから "experimental" モジュールを見るか、2にして から "development" モジュールを見るかする必要がある. | |||
== | ==新規モジュールファイルに関するパスツリー (必須)== | ||
これは、新しいモジュールを構築する際に、ファイルをどう整理するかを示している (ZIPファイルもこのルールに合わせる必要あり). | |||
注:2行目だけが必須. | |||
{{ | {{TemplateModuleTreeSimpleJA}} | ||
== | ==自前 SQL テーブル と PHP DAO クラス (任意)== | ||
''' | '''使用場面''': 自前モジュールがそれ自身のデータを管理する必要がある場合 | ||
=== | ===自前の .sql ファイルを作成=== | ||
自前モジュールが、Dolibarr標準版では利用できない独自データを管理する設計である場合、そのデータを格納するためのSQLテーブルを定義する必要がある. | |||
自前モジュールでテーブルを作成したり、データを読込むためのスクリプトは、自前モジュールのsqlサブディレクトリ ("'''mymodule/sql'''") に保存される。(ModuleBuilder では、オブジェクト タブから新しいオブジェクトを作成するとき、このディレクトリとすべての sql ファイルが自動作成される). | |||
次に、記述ファイルでの、'''init''' 関数にて、次の行 | |||
<syntaxhighlight lang="PHP">$this->_load_tables('/mymodule/sql/');</syntaxhighlight> | <syntaxhighlight lang="PHP">$this->_load_tables('/mymodule/sql/');</syntaxhighlight> | ||
が、コメントでないことを確認する. | |||
'' | ''従うべきルール:'' | ||
* | *テーブルごとに '''llx_matable.sql''' ファイルを1つ、'''llx_matable.key.sql''' ファイルを可能なら1つ、作成するという原則に基づき、テーブル作成コマンドのファイルを追加する(例として、 '''install/mysql/tables''' にあるファイルを参照). | ||
* | *SQLフィールドの推奨される型と名前は、このページに定義されてる [[Language_and_development_rules#Table_and_fields_structures]]. | ||
* | *データ管理のため、 '''/mymodule/sql/''' ディレクトリ内に '''data.sql''' というファイルを作成し、データの追加/編集/削除を行う SQL コマンドを記述すること. | ||
* | *文字列にダブルクォートを使わない(例: "chaine" でなく 'chaine') ダブルクォートは PostGreSQL では特定の意味を持つ | ||
例としてファイル data.sql の中身は | |||
<syntaxhighlight lang="sql"> | <syntaxhighlight lang="sql"> | ||
delete from llx_const where name='MYMODULE_IT_WORKS' and entity='__ENTITY__'; | delete from llx_const where name='MYMODULE_IT_WORKS' and entity='__ENTITY__'; | ||
| Line 102: | Line 104: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
ファイルは、mysql データベースで動作可能であること. 備考: 他データベースのファイルはメンテナンスされない. 他データベースのドライバによって、その場で読込まれ変換さる. | |||
=== | ===自前の .sql ファイルをテストする=== | ||
ファイルの準備ができたら、Dolibarrモジュールを有効にするページに戻り、モジュールを無効にして、データベース内のそれらのテーブルを削除し(すでに存在している場合)、モジュールを再有効化することができる。モジュールの有効化により、テーブルが再作成されるはず。もしそうでない場合、スクリプトを手で渡して確認するか、Dolibarrのログを確認すること. | |||
=== | ===PHP DAO クラスを生成=== | ||
DAO PHPファイルは、オブジェクトを作成した後にモジュールビルダによって生成されているはず. | |||
だとしても、既存オブジェクトをコピーして手動作成することもできる、しかし、モジュールビルダの使用を強く勧める。実例がここにあるはず '''htdocs/modulebuilder/templates/class/myobject.class.php''' | |||
このクラスでは、テーブル行の挿入、取得(選択)、更新、削除を実行するためのCRUD(作成/読込/更新/削除)メソッドがすでに実行可能となっている。正しいモジュール名、テーブルを使用するようにファイルを編集し、このファイルをモジュールのクラスサブディレクトリに配置する。モジュールビルダを使用すると、マウスを数回クリックするだけで、この作業を実行できる. | |||
== | ==タブ管理 (任意)== | ||
=== | ===オブジェクトシートに自前のタブを追加・削除できる=== | ||
''' | '''使用場面''': オブジェクト(請求書、注文書、提案書、メンバー...)にタブを追加する場合 | ||
そのためには、先に作成したモジュールのファイル記述に行って、$this->tabs 配列を編集する: | |||
<syntaxhighlight lang="PHP"> | <syntaxhighlight lang="PHP"> | ||
| Line 129: | Line 131: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
テーブルには文字列のリストが含まれ、各文字列は新しいタブを表す.文字列の形式は ": " で区切られた5つの部分からなる. | |||
*Part 1: | *Part 1: タブを表示するエレメントタイプ(オブジェクトタイプ)で、以下の値: | ||
{{ | {{TemplateModuleTabsJA}} | ||
*Part 2: | *Part 2: タブのコードで、タブの追加(+で始まる)または削除(-で始まる)を識別する. | ||
*Part 3: | *Part 3: タブのタイトル.タイトルが読みずらいなら、コードにして言語ファイルで翻訳するとよい. | ||
*Part 4: | *Part 4: ファイル名 "*.lang" は、コード翻訳と表示する言語の対応を含む.この名前の後に@mymoduleが続く場合、 Dolibarrはモジュール内の翻訳ファイル "*.lang "を検索するので、htdocs/mymodule/langs/code_CODE/mylangfile.langとなり、そうでない場合はhtdocs/langs/code_CODE/mylangfile.langとなる. | ||
*Part 5: | *Part 5: タブを常時表示すべきかのテスト条件.常時表示の場合は1を指定. | ||
*Part 6: | *Part 6: タブをクリックしたときに表示されるページのURL。__ID__の文字列は自動的に当該要素のIdに置き換えられる. | ||
タブの内容へデータベースからのデータを注入するには、次章を参照. | |||
既存タブの名前 'tabname' を取得するには、ファイル 'core/lib/module.lib.php' の関数 'product_prepare_head' で使用されている名前で、セクション '$head[$h][2]' に対応するものをチェックする必要がある. | |||
=== | ===自前ページにタブナビゲーションを表示=== | ||
''' | '''使用場面''': 自前ページにオブジェクト(製品、階層、など)の標準タブを表示したい | ||
以下の手順に従う : | |||
'''1. Include files you need into your file''' | '''1. Include files you need into your file''' | ||
| Line 217: | Line 218: | ||
This function will show required tabs and open an html element ''< div class="" >'' that correspond to the area under the tabs. To close area of a tab, just use ''< /div >'' into your PHP page. | This function will show required tabs and open an html element ''< div class="" >'' that correspond to the area under the tabs. To close area of a tab, just use ''< /div >'' into your PHP page. | ||
== | ==PHP 画面の作成や更新 (任意)== | ||
使用場面: モジュールの目的が、画面の新規作成または変更を必要とする機能の追加である場合. | |||
=== | ===新規 PHP 画面の作成=== | ||
次に、 '''modulebuilder/myobject_page.php''' ディレクトリに例として提示されているスケルトンテンプレートを使用して、テーブルのデータを表示/編集するPHPページを作成する必要がある (コマンドラインからのスクリプト開発については、 [[Script development]] を参照). | |||
新しいユーザー画面を作成するには、'''htdocs''' のサブディレクトリを作成し(まだ作成されていない場合)、作成するページを保存するために、モジュール(例えば、'''htdocs/mymodule''' )のサブディレクトリを作成する. | |||
そのディレクトリに、ページファイルの出発点となるファイル '''myobject_page.php''' をコピーする。. | |||
main.inc.phpファイルへの相対パスが正しくなるようにファイルを編集する. | |||
<syntaxhighlight lang="PHP"> | <syntaxhighlight lang="PHP"> | ||
// Load Dolibarr environment | // Load Dolibarr environment | ||
| Line 243: | Line 244: | ||
if (! $res) die("Include of main fails"); | if (! $res) die("Include of main fails"); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
ご覧のように、main.inc.php(または master.inc.php)のロードは何回か試行される。目標は、大抵のケースで成功すること。最小は2行: master/main.inc.phpをdolibarrルートディレクトリにロードしようとする行と、モジュールが "custom "ディレクトリにデプロイされるケースをサポートするためにファイルをロードしようとする行。しかし、より多くの状況に対応するため、より多くを持つことができる。提供された例は、ほぼすべての状況/セットアップで main/master.inc.php ファイルをロードできるはず。 | |||
注意: モジュール・ディレクトリ・ツリーに対するファイルの深さによっては、さらに"../"を追加する。 | |||
main.inc.phpファイルでは、技術上の環境変数とパーミッションを読み込む。以下の変数はこのファイルに配置されているオブジェクト: | |||
*$user | *$user ユーザーの特徴とパーミッションを保持するオブジェクト。 | ||
*$conf | *$conf Dolibarrの設定を保持するオブジェクト | ||
*$db | *$db データベースへのオープンされた接続ハンドラを保持するオブジェクト。 | ||
*$langs | *$langs ユーザー言語を保持するオブジェクト。 | ||
次にページを表示するために自前コードを入力する. | |||
* | *モジュール専用クラスやライブラリをインクルードするには、(include_onceを直接使わず)Dolibarr関数を使う: | ||
''Example :'' | ''Example :'' | ||
| Line 263: | Line 264: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
* | *Dolibarrで提供されているクラスをインクルードするには、以下の構文を使う: | ||
''Example :'' | ''Example :'' | ||
| Line 286: | Line 287: | ||
See chapter [[Hooks_system#Implement_the_Hook]] to know how to use Dolibarr existing hooks to add/replace code at Dolibarr hooks place. | See chapter [[Hooks_system#Implement_the_Hook]] to know how to use Dolibarr existing hooks to add/replace code at Dolibarr hooks place. | ||
=== | ===データベース アクセス=== | ||
自前テーブルの中でデータベースのデータを編集する必要がある場合、前に生成されたPHPクラスを使うこと。 | |||
専用の PHP クラスがないテーブルにアクセスしたい場合 (たとえば、特定の結合やフィルタを使用したレコードの一覧を取得したい場合など) 、これはいつでも可能。この場合に、倣うべきコード例は: | |||
操作が、 insert, update または delete: | |||
<syntaxhighlight lang="PHP"> | <syntaxhighlight lang="PHP"> | ||
| Line 300: | Line 301: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
操作が read: | |||
<syntaxhighlight lang="PHP"> | <syntaxhighlight lang="PHP"> | ||
| Line 359: | Line 360: | ||
as soon as the module is activate, the tpl will be overwrited | as soon as the module is activate, the tpl will be overwrited | ||
== | ==自前の準備ページを追加 (任意)== | ||
'''When''': If your module needs parameters, which are to be provided by the user, for proper setting up of the module. | '''When''': If your module needs parameters, which are to be provided by the user, for proper setting up of the module. | ||
| Line 382: | Line 383: | ||
Go into page '''Home->Setup->Modules''', you should see a picture at the end of the line of your module to reach your setup page. Click on it, you should be able to view/edit parameters from your page. | Go into page '''Home->Setup->Modules''', you should see a picture at the end of the line of your module to reach your setup page. Click on it, you should be able to view/edit parameters from your page. | ||
== | ==メニューに自前項目を定義 (任意)== | ||
'''When''': If you have created PHP pages, it is necessary that those pages can be reached from menu entries in Dolibarr menu. | '''When''': If you have created PHP pages, it is necessary that those pages can be reached from menu entries in Dolibarr menu. | ||
| Line 433: | Line 434: | ||
Disable and re-enable your module under the Dolibarr module setup page, menus entries must appear (if property 'enabled' is declaration array is ok). | Disable and re-enable your module under the Dolibarr module setup page, menus entries must appear (if property 'enabled' is declaration array is ok). | ||
== | ==自前の許認可を追加 (任意)== | ||
'''When''': If you want to add new permissions. | '''When''': If you want to add new permissions. | ||
| Line 465: | Line 466: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== | ==自前の box を定義 (任意)== | ||
'''When''': If your module needs to provide one or several new boxes to show on home page. | '''When''': If your module needs to provide one or several new boxes to show on home page. | ||
| Line 490: | Line 491: | ||
Your boxes must appear in the list of boxes you can activate. Activate the box and go on the home page to see if the box is showing correctly. | Your boxes must appear in the list of boxes you can activate. Activate the box and go on the home page to see if the box is showing correctly. | ||
== | ==自前のエキスポートを定義 (任意)== | ||
'''When''': If your module provides new predefined database export profiles (for its own tables or for already existing tables of another module). | '''When''': If your module provides new predefined database export profiles (for its own tables or for already existing tables of another module). | ||
| Line 501: | Line 502: | ||
Choose on field and try to build an export file. If ok, try again with all fields. | Choose on field and try to build an export file. If ok, try again with all fields. | ||
== | ==自前の CSS スタイルを定義 (任意)== | ||
'''When''': If in your PHP pages, you use class styles that are not defined inside Dolibarr themes CSS (not recommanded). | '''When''': If in your PHP pages, you use class styles that are not defined inside Dolibarr themes CSS (not recommanded). | ||
| Line 522: | Line 523: | ||
You should see into the HTML header, a line that declares your style sheet. | You should see into the HTML header, a line that declares your style sheet. | ||
== | ==自前の Javascript 関数を追加 (任意)== | ||
'''When''': If in your PHP pages, you use javascript functions not available in Dolibarr (in file lib_head.js) | '''When''': If in your PHP pages, you use javascript functions not available in Dolibarr (in file lib_head.js) | ||
| Line 534: | Line 535: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== | ==いずれかの Dolibarr イベントで自前コードを実行する (任意)== | ||
'''When''': If you want to execute your own code once a common Dolibarr event has occurred (example: I want to update a table in my module when an invoice is created into Dolibarr), you must create a '''triggers'''. | '''When''': If you want to execute your own code once a common Dolibarr event has occurred (example: I want to update a table in my module when an invoice is created into Dolibarr), you must create a '''triggers'''. | ||
| Line 540: | Line 541: | ||
and [[Interfaces_from_foreign_systems_toward_Dolibarr]] | and [[Interfaces_from_foreign_systems_toward_Dolibarr]] | ||
== | ==Dolibarr フックポジションの内部に、自前コードを挿入 (任意)== | ||
'''When''': When you want to add code or replace Dolibarr code into another situation than a business event (See the previous chapter for adding code during a business event). | '''When''': When you want to add code or replace Dolibarr code into another situation than a business event (See the previous chapter for adding code during a business event). | ||
| Line 546: | Line 547: | ||
== | ==自前の番号付けルールを追加== | ||
'''When''': When you need a new rule for generated ref of elements that are not covered by existing rules. | '''When''': When you need a new rule for generated ref of elements that are not covered by existing rules. | ||
See page [[Create numbering module]]. | See page [[Create numbering module]]. | ||
== | ==自前の文書テンプレートを追加 (任意)== | ||
'''When''': When you want to personalized your own generated PDF or ODT documents. | '''When''': When you want to personalized your own generated PDF or ODT documents. | ||
| Line 558: | Line 559: | ||
Documentation to add your own template is available on page [[Create_a_PDF_document_template]] or [[Create_an_ODT_document_template]]. | Documentation to add your own template is available on page [[Create_a_PDF_document_template]] or [[Create_an_ODT_document_template]]. | ||
== | ==自前のスキンを追加 (任意)== | ||
'''When''': When you want to personalized your colors/fonts/images. | '''When''': When you want to personalized your colors/fonts/images. | ||
| Line 565: | Line 566: | ||
To add your own skin, read page [[Skins]]. | To add your own skin, read page [[Skins]]. | ||
= | =コーディングルールおよび定義済み関数= | ||
The coding rules to be followed are defined in the [[Developer documentation]], under section "General Information - Language and standards development". | The coding rules to be followed are defined in the [[Developer documentation]], under section "General Information - Language and standards development". | ||
A lot of predefined features for developers are also available and described into page [[Developer documentation]] under section "Technical components of Dolibarr". | A lot of predefined features for developers are also available and described into page [[Developer documentation]] under section "Technical components of Dolibarr". | ||
= | =自前モジュールを配布し導入するためのパッケージを作成= | ||
This process must be used to generate a package to submit it on the http://www.dolistore.com marketplace. | This process must be used to generate a package to submit it on the http://www.dolistore.com marketplace. | ||
But you can use it to have a package easy to distribute on your own network. | But you can use it to have a package easy to distribute on your own network. | ||
| Line 595: | Line 596: | ||
**If quality is enough and license permits it, the code might be added inside main Dolibarr sources (except if you disagree for that). | **If quality is enough and license permits it, the code might be added inside main Dolibarr sources (except if you disagree for that). | ||
= | =DoliStore での外部モジュール 有効化/活性化 条件= | ||
See [[Module_Dolistore_Validation_Rules|Validation Rules]] | See [[Module_Dolistore_Validation_Rules|Validation Rules]] | ||
[[Category:Development]] | [[Category:Development]] | ||
edits