Objetos de negociado: Difference between revisions

From Dolibarr ERP CRM Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 7: Line 7:
* Update: update()
* Update: update()
* Delete: delete()
* Delete: delete()
= Linked business objects =
Some business objects are linked to other. This is done into Dolibarr using the [[Table llx_element_element]]. But you don't have to read this table to get objects linked to another.
This is a portion of code that show you how ou can do this:
<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>


= Ejemplos =
= Ejemplos =

Revision as of 15:52, 3 September 2010

Business objects

All business objects are defined by a PHP class that herits of class CommonObject (defined in file commonobject.class.php). Every business object has the 4 CRUD methods:

  • Create: create()
  • Read: fetch()
  • Update: update()
  • Delete: delete()

Linked business objects

Some business objects are linked to other. This is done into Dolibarr using the Table llx_element_element. But you don't have to read this table to get objects linked to another. This is a portion of code that show you how ou can do this:

// 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);

Ejemplos

Ejemplo para la creación de un tercero

He aquí un ejemplo para la creación de un tercero (empresa cliente, por ejemplo):

Si se encuentra en el caso de un script externo a Dolibarr, es necesario realizar un inicio, antes de cualquier cosa

include('/pathofdolibarrhtdocs/master.inc.php');

para que el entorno Dolibarr (objetos $conf, $db, $lang y $user sean creados). Si queremos que las acciones (creación, actualización), se asocien a un usuario en particular, es necesario hacerlo despues del include de master.inc.php

$user->fetch(0,'loginuser');

Seguidamente, podremos realizar nuestras acciones.

// Declaramos la clase que vamos a manipular
include_once('/pathofdolibarrhtdocs/societe.class.php');

// Creamos una instancia del objeto a manipular
$mycompany = new Societe($db);

// Indicamos sus características
$mycompany->nom='Big Brother';
$mycompany->client=1;

// Si queremos que la acción de creación se asocie a un usuario 'loginuser' en particular,
// hay que descomentar esta linea para cambiar las caracteriísticas de este usuario.
// Si lo dejamos comentado, Dolibarr meterá un null en los campos de usuario de creacion o actualización.
// $user->fetch('loginuser');

// Llamamos a la creación
$id=$mycompany->create($user);

// Para cambiar el objeto
$mycompany->fetch($id);

// Para actualizar
$mycompany->update($user);

Otros ejemplos

Encontrará otros ejemplos de manipulación de objetos Dolibarr (Creación, Lectura, Modificación, Eliminación) en el directorio dev/samples del snapshot CVS de Dolibarr.