714
edits
PolyglotBot (talk | contribs) m (Import interlang links (links to translated versions of this page in other languages) from origin English page "Business_Objects".) |
|||
| Line 1: | Line 1: | ||
{{Template开发文档}} | {{Template开发文档}} | ||
{{Template用户手册}} | {{Template用户手册}} | ||
{{TemplateMainPageZh}} | {{TemplateMainPageZh}} | ||
= 业务对象(简称‘对象’)= | =业务对象(简称‘对象’)= | ||
所有业务对象都由从 CommonObject 类(在core/class/commonobject.class.php文件中定义)继承的PHP类定义。 | |||
* | 要查找与您感兴趣的业务对象对应的类,请浏览Dolibarr的文件树,查找文件 '''*/class/*.class.php''',因为所有类都位于与对象相关的目录的 class 子目录中。例如: | ||
* | |||
* | *对于合作方 htdocs/societe/class/societe.class.php | ||
* | *对于客户发票 htdocs/compta/facture/class/facture.class.php | ||
*对于供应商发票 htdocs/fourn/class/fournisseur.facture.class.php | |||
... | |||
每个业务类都有4种CRUD方法,用于执行数据库读取或更新: | |||
*创建(C表示创建):create() | |||
*读取(R表示读取):fetch() | |||
*更改(U代表更新):update() | |||
*删除(D代表删除):delete() | |||
请参阅下面的示例... | |||
= 全部对象 = | =全部对象= | ||
[https://doxygen.dolibarr.org/inherits.html 类的继承] | [https://doxygen.dolibarr.org/inherits.html 类的继承] | ||
= | *Societe | ||
*Product | |||
*Account | |||
*AccountingAccount | |||
=业务对象之间的链接= | |||
一些业务对象相互关联。这是在 Dolibarr 中通过 [[Table llx_element_element|表llx_element_element]] 完成的。但是,您不必读取此表来检索链接到另一个表的对象。下面的代码部分显示了如何执行此操作: | |||
如果是 Dolibarr 3.1及更高版本 | |||
<source lang="php"> | |||
// get invoices from an already loaded order: | |||
$result = $order->fetchObjectLinked($order->id, 'commande', null, 'facture'); | |||
if ($result <= 0) { | |||
// handle error | |||
} | |||
// important notice : the newly populated arrays are associative. Keys are llx_element_element row ids. | |||
// now if we expect only one linked invoice: | |||
// WRONG way to get it ($invoice_id will be NULL): | |||
$invoice_id = $order->linkedObjectsIds['facture'][0] | |||
// CORRECT way ($invoice_id will hold the ID): | |||
$invoice_id = array_values($order->linkedObjectsIds['facture'])[0] | |||
// Better (if there are more than one linked invoices) : | |||
foreach ($order->linkedObjectsIds['facture'] as $element_element_id => $facture_id) { | |||
// process it | |||
} | |||
</source> | |||
如果是 Dolibarr 3.1 之前的版本 | |||
<source lang="php"> | |||
// This load the array linked_object with objects that link to this one | |||
$object->load_object_linked($object->id, $object->element); | |||
// To load array linked_object with objects that are linked by this one | |||
$object->load_object_linked($object->id, $object->element); | |||
// Then choose id with objects type you need | |||
$org_order_array = $object->linked_object["commande"]; | |||
// Now use them | |||
$thelinkedobjectid = $org_order_array[0]; | |||
// new order instance | |||
$thelinkedobject = new Commande($object->db); | |||
// load the object | |||
$thelinkedobject->fetch($thelinkedobjectid); | |||
</source> | |||
<source lang="php"> | <source lang="php"> | ||
// 将数组链接到与本对象相联系的的对象上。 | // 将数组链接到与本对象相联系的的对象上。 | ||
| Line 47: | Line 93: | ||
</source> | </source> | ||
= | =示例= | ||
=='合伙人'举例 == | =='合伙人'举例== | ||
下面是创建合伙人(例如客户公司)的示例: | 下面是创建合伙人(例如客户公司)的示例: | ||
| Line 93: | Line 139: | ||
'''注:以上代码,可以编写在card.php文件中。响应操作按键的动作。''' | '''注:以上代码,可以编写在card.php文件中。响应操作按键的动作。''' | ||
== 其他例子 == | ==其他例子== | ||
您可以找到其他操作Dolibarr对象的示例。 (Create, Read, Update, Delete) into directory '''dev/samples''' of Dolibarr snapshot. | 您可以找到其他操作Dolibarr对象的示例。 (Create, Read, Update, Delete) into directory '''dev/samples''' of Dolibarr snapshot. | ||
edits