Add createFromClone function in skeleton
This commit is contained in:
parent
03010ac770
commit
2a6ad76913
@ -18,12 +18,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\file dev/skeletons/skeleton_class.class.php
|
* \file dev/skeletons/skeleton_class.class.php
|
||||||
\ingroup mymodule othermodule1 othermodule2
|
* \ingroup mymodule othermodule1 othermodule2
|
||||||
\brief This file is an example for a CRUD class file (Create/Read/Update/Delete)
|
* \brief This file is an example for a CRUD class file (Create/Read/Update/Delete)
|
||||||
\version $Id$
|
* \version $Id$
|
||||||
\author Put author name here
|
* \author Put author name here
|
||||||
\remarks Put here some comments
|
* \remarks Put here some comments
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Put here all includes required by your class file
|
// Put here all includes required by your class file
|
||||||
@ -33,9 +33,9 @@
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\class Skeleton_class
|
* \class Skeleton_class
|
||||||
\brief Put here description of your class
|
* \brief Put here description of your class
|
||||||
\remarks Put here some comments
|
* \remarks Put here some comments
|
||||||
*/
|
*/
|
||||||
class Skeleton_class // extends CommonObject
|
class Skeleton_class // extends CommonObject
|
||||||
{
|
{
|
||||||
@ -299,6 +299,62 @@ class Skeleton_class // extends CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Load an object from its id and create a new one in database
|
||||||
|
* \param fromid Id of object to clone
|
||||||
|
* \param invertdetail Reverse sign of amounts for lines
|
||||||
|
* \return int New id of clone
|
||||||
|
*/
|
||||||
|
function createFromClone($fromid,$invertdetail=0)
|
||||||
|
{
|
||||||
|
global $user,$langs;
|
||||||
|
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
$object=new Skeleton_class($this->db);
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
|
// Load source object
|
||||||
|
$object->fetch($fromid);
|
||||||
|
$object->id=0;
|
||||||
|
$object->statut=0;
|
||||||
|
|
||||||
|
// Clear fields
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// Create clone
|
||||||
|
$result=$object->create($user);
|
||||||
|
|
||||||
|
// Other options
|
||||||
|
if ($result < 0)
|
||||||
|
{
|
||||||
|
$this->error=$object->error;
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// End
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$this->db->commit();
|
||||||
|
return $object->id;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Initialise object with example values
|
* \brief Initialise object with example values
|
||||||
* \remarks id must be 0 if object instance is a specimen.
|
* \remarks id must be 0 if object instance is a specimen.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user