附加字段: Difference between revisions
Jump to navigation
Jump to search
m (→附加字段) |
(→相关视频) Tag: 2017 source edit |
||
| (8 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
<!-- BEGIN interlang links --> | |||
<!-- Do NOT edit this section | |||
Links below are automatically managed by PolyglotBot | |||
You can edit links on the English source page : Extrafields --> | |||
[[en:Extrafields]] | |||
[[fr:Champs_personnalises]] | |||
<!-- END interlang links --> | |||
{{TemplateMainPageZh}} | {{TemplateMainPageZh}} | ||
{{Template开发文档}} | {{Template开发文档}} | ||
{{Template用户手册}} | {{Template用户手册}} | ||
= 附加字段 = | =附加字段= | ||
附加字段允许您向标准Dolibarr数据库模式中添加更多数据。自版本3.2开始引入,附加字段现在在大多数业务对象中得以实现: | |||
*合作方 & 联系人 | |||
* | *用户 | ||
* | *事件 | ||
* | *报价单 | ||
* | *客户发票 | ||
* | *订单 | ||
* | *供应商报价单 | ||
* | *供应商发票 | ||
* | *供应商订单 | ||
* | *产品 & 服务 | ||
* | *会员 & 会员类型 | ||
* | *项目 & 项目任务 (自 3.4 起) | ||
* | *类别 | ||
* | *费用报销单 | ||
* | |||
== | ==技术实现方式== | ||
每个对象在数据库中都有一个表用于存储ExtraFields的值。 | |||
== | ==数据表的附加字段表的模板== | ||
llx_''BaseTableNAme''_extrafields | llx_''BaseTableNAme''_extrafields | ||
| Line 34: | Line 43: | ||
用于在对象上实现 ExtraFields 的MySQL定义文件示例: | |||
create table llx_place_room_extrafields | create table llx_place_room_extrafields | ||
| Line 44: | Line 53: | ||
) ENGINE=innodb; | ) ENGINE=innodb; | ||
== | ==加载ExtraFields类== | ||
要使用ExtraFields,所有页面必须包括: | |||
< | |||
<syntaxhighlight lang="PHP"> | |||
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; | ||
</ | </syntaxhighlight> | ||
== | ==加载对象的ExtraField数组== | ||
< | <syntaxhighlight lang="PHP"> | ||
$extrafields = new ExtraFields($db); | $extrafields = new ExtraFields($db); | ||
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); | $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); | ||
</ | </syntaxhighlight> | ||
$extralabels 将是一个包含扩展字段的code和label的数组。此代码必须放在类中,例如放在“write_file”函数中。 | |||
== | ==加载对象的ExtraField值== | ||
把ExtraFields加载到数组 $object->array_options 中。 | |||
< | <syntaxhighlight lang="PHP"> | ||
$object->fetch($rowid); | $object->fetch($rowid); | ||
$object->fetch_optionals($rowid,$extralabels); | $object->fetch_optionals($rowid,$extralabels); | ||
</ | </syntaxhighlight> | ||
此代码应放在上述代码之后。 | |||
==以PDF或HTML格式显示ExtraField值== | |||
加载ExtraFields后 | |||
HTML示例 | |||
<syntaxhighlight lang="PHP"> | |||
< | |||
print $object->array_options ['options_XXX']; | print $object->array_options ['options_XXX']; | ||
</ | </syntaxhighlight> | ||
此处 XXX | |||
此处 XXX 是extrafields代码 | |||
PDF示例 | |||
<syntaxhighlight lang="PHP"> | |||
< | |||
$pdf->MultiCell (0,5, $outputlangs->convToOutputCharset($object->array_options ['options_XXX']),0,'L'); ) | $pdf->MultiCell (0,5, $outputlangs->convToOutputCharset($object->array_options ['options_XXX']),0,'L'); ) | ||
</ | </syntaxhighlight> | ||
此处 XXX | |||
此处 XXX 是extrafields代码 | |||
==以PDF或HTML格式显示行的ExtraField值== | |||
加载ExtraFields后 | |||
HTML示例 | |||
<syntaxhighlight lang="PHP"> | |||
< | |||
print $object->lines[$i]->array_options['options_XXX']; | print $object->lines[$i]->array_options['options_XXX']; | ||
</ | </syntaxhighlight> | ||
此处 XXX | |||
此处 XXX 是extrafields代码 | |||
PDF示例 | |||
<syntaxhighlight lang="PHP"> | |||
< | |||
$pdf->MultiCell (0,5, $outputlangs->convToOutputCharset($object->lines[$i]->array_options['options_XXX']),0,'L'); | $pdf->MultiCell (0,5, $outputlangs->convToOutputCharset($object->lines[$i]->array_options['options_XXX']),0,'L'); | ||
</ | </syntaxhighlight> | ||
此处 XXX | |||
此处 XXX 是extrafields代码 | |||
==如何在使用模板(propals等)时更改列的标签== | |||
在模板的PHP代码中,您可以通过修改名为“_tableau(...)”的函数来更改扩展字段的标签。 | |||
==在调用 $object->create() 或 $object->update()之前== | |||
必须检索表单发送的extrafields值。为此,请使用以下方法: | |||
<syntaxhighlight lang="PHP"> | |||
< | |||
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); | $ret = $extrafields->setOptionalsFromPost($extralabels,$object); | ||
</ | </syntaxhighlight> | ||
==在编辑页面中显示扩展字段== | |||
< | <syntaxhighlight lang="PHP"> | ||
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook | $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook | ||
if (empty($reshook) && ! empty($extrafields->attribute_label)) | if (empty($reshook) && ! empty($extrafields->attribute_label)) | ||
| Line 118: | Line 136: | ||
print $object->showOptionals($extrafields,'edit'); | print $object->showOptionals($extrafields,'edit'); | ||
} | } | ||
</ | </syntaxhighlight> | ||
== | ==在视图页面中显示扩展字段== | ||
< | <syntaxhighlight lang="PHP"> | ||
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook | $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook | ||
if (empty($reshook) && ! empty($extrafields->attribute_label)) | if (empty($reshook) && ! empty($extrafields->attribute_label)) | ||
| Line 128: | Line 146: | ||
print $object->showOptionals($extrafields); | print $object->showOptionals($extrafields); | ||
} | } | ||
</ | </syntaxhighlight> | ||
== | ==在此对象类的Fetch方法之后== | ||
< | <syntaxhighlight lang="PHP"> | ||
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); | require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); | ||
$extrafields=new ExtraFields($this->db); | $extrafields=new ExtraFields($this->db); | ||
| Line 138: | Line 156: | ||
$this->fetch_optionals($this->id,$extralabels); | $this->fetch_optionals($this->id,$extralabels); | ||
} | } | ||
</ | </syntaxhighlight> | ||
== | ==在此对象类的Update方法之后== | ||
< | <syntaxhighlight lang="PHP"> | ||
// Actions on extra fields (by external module or standard code) | // Actions on extra fields (by external module or standard code) | ||
// FIXME le hook fait double emploi avec le trigger !! | // FIXME le hook fait double emploi avec le trigger !! | ||
| Line 159: | Line 177: | ||
} | } | ||
else if ($reshook < 0) $error++; | else if ($reshook < 0) $error++; | ||
</ | </syntaxhighlight> | ||
== | ==在此对象类的Delete方法之后== | ||
< | <syntaxhighlight lang="PHP"> | ||
// Removed extrafields | // Removed extrafields | ||
if (! $error) | if (! $error) | ||
| Line 176: | Line 194: | ||
} | } | ||
} | } | ||
</ | </syntaxhighlight> | ||
== | ==管理页面== | ||
< | <syntaxhighlight lang="PHP"> | ||
$elementtype='facture'; //Must be the $table_element of the class that manage extrafield | $elementtype='facture'; //Must be the $table_element of the class that manage extrafield | ||
</ | </syntaxhighlight> | ||
==恢复数据库== | |||
搜索并查找$listofmodulesextra的定义添加新的extrafield语句 | |||
<syntaxhighlight lang="PHP"> | |||
< | |||
$listofmodulesextra=array('societe'=>'societe','adherent'=>'adherent','product'=>'product', | $listofmodulesextra=array('societe'=>'societe','adherent'=>'adherent','product'=>'product', | ||
'socpeople'=>'socpeople', 'commande'=>'commande', 'facture'=>'facture', | 'socpeople'=>'socpeople', 'commande'=>'commande', 'facture'=>'facture', | ||
'commande_fournisseur'=>'commande_fournisseur', 'actioncomm'=>'actioncomm', | 'commande_fournisseur'=>'commande_fournisseur', 'actioncomm'=>'actioncomm', | ||
'adherent_type'=>'adherent_type','user'=>'user','projet'=>'projet', 'projet_task'=>'projet_task'); | 'adherent_type'=>'adherent_type','user'=>'user','projet'=>'projet', 'projet_task'=>'projet_task'); | ||
</ | </syntaxhighlight> | ||
==相关视频== | |||
Extrafields: | |||
(法语配音,但有字幕,并以法语校阅) | |||
== | <youtube width="200" height="180">Eex2YXxToS0</youtube> | ||
<youtube width="200" height="180">QQnyoUGsN1c</youtube> | |||
<youtube width="200" height="180">md6JHbd8o_0</youtube> | |||
Latest revision as of 07:57, 12 October 2023
附加字段
附加字段允许您向标准Dolibarr数据库模式中添加更多数据。自版本3.2开始引入,附加字段现在在大多数业务对象中得以实现:
- 合作方 & 联系人
- 用户
- 事件
- 报价单
- 客户发票
- 订单
- 供应商报价单
- 供应商发票
- 供应商订单
- 产品 & 服务
- 会员 & 会员类型
- 项目 & 项目任务 (自 3.4 起)
- 类别
- 费用报销单
技术实现方式
每个对象在数据库中都有一个表用于存储ExtraFields的值。
数据表的附加字段表的模板
llx_BaseTableNAme_extrafields rowid integer AUTO_INCREMENT PRIMARY KEY, tms timestamp, fk_object integer NOT NULL, import_key varchar(14)
用于在对象上实现 ExtraFields 的MySQL定义文件示例:
create table llx_place_room_extrafields ( rowid integer AUTO_INCREMENT PRIMARY KEY, tms timestamp, fk_object integer NOT NULL, import_key varchar(14) -- import key ) ENGINE=innodb;
加载ExtraFields类
要使用ExtraFields,所有页面必须包括:
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
加载对象的ExtraField数组
$extrafields = new ExtraFields($db);
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
$extralabels 将是一个包含扩展字段的code和label的数组。此代码必须放在类中,例如放在“write_file”函数中。
加载对象的ExtraField值
把ExtraFields加载到数组 $object->array_options 中。
$object->fetch($rowid);
$object->fetch_optionals($rowid,$extralabels);
此代码应放在上述代码之后。
以PDF或HTML格式显示ExtraField值
加载ExtraFields后
HTML示例
print $object->array_options ['options_XXX'];
此处 XXX 是extrafields代码
PDF示例
$pdf->MultiCell (0,5, $outputlangs->convToOutputCharset($object->array_options ['options_XXX']),0,'L'); )
此处 XXX 是extrafields代码
以PDF或HTML格式显示行的ExtraField值
加载ExtraFields后
HTML示例
print $object->lines[$i]->array_options['options_XXX'];
此处 XXX 是extrafields代码
PDF示例
$pdf->MultiCell (0,5, $outputlangs->convToOutputCharset($object->lines[$i]->array_options['options_XXX']),0,'L');
此处 XXX 是extrafields代码
如何在使用模板(propals等)时更改列的标签
在模板的PHP代码中,您可以通过修改名为“_tableau(...)”的函数来更改扩展字段的标签。
在调用 $object->create() 或 $object->update()之前
必须检索表单发送的extrafields值。为此,请使用以下方法:
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
在编辑页面中显示扩展字段
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook) && ! empty($extrafields->attribute_label))
{
print $object->showOptionals($extrafields,'edit');
}
在视图页面中显示扩展字段
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook) && ! empty($extrafields->attribute_label))
{
print $object->showOptionals($extrafields);
}
在此对象类的Fetch方法之后
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php');
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
if (count($extralabels)>0) {
$this->fetch_optionals($this->id,$extralabels);
}
在此对象类的Update方法之后
// Actions on extra fields (by external module or standard code)
// FIXME le hook fait double emploi avec le trigger !!
$hookmanager->initHooks(array('HookModuleNamedao'));
$parameters=array('socid'=>$this->id);
$reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
if (empty($reshook))
{
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{
$result=$this->insertExtraFields();
if ($result < 0)
{
$error++;
}
}
}
else if ($reshook < 0) $error++;
在此对象类的Delete方法之后
// Removed extrafields
if (! $error)
{
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{
$result=$this->deleteExtraFields();
if ($result < 0)
{
$error++;
dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR);
}
}
}
管理页面
$elementtype='facture'; //Must be the $table_element of the class that manage extrafield
恢复数据库
搜索并查找$listofmodulesextra的定义添加新的extrafield语句
$listofmodulesextra=array('societe'=>'societe','adherent'=>'adherent','product'=>'product',
'socpeople'=>'socpeople', 'commande'=>'commande', 'facture'=>'facture',
'commande_fournisseur'=>'commande_fournisseur', 'actioncomm'=>'actioncomm',
'adherent_type'=>'adherent_type','user'=>'user','projet'=>'projet', 'projet_task'=>'projet_task');
相关视频
Extrafields: (法语配音,但有字幕,并以法语校阅)