mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-06 17:48:25 +01:00
Generate Create method in script to build webservice from class
This commit is contained in:
@@ -118,11 +118,25 @@ $server->register(
|
||||
'WS to get skeleton'
|
||||
);
|
||||
|
||||
// Register WSDL
|
||||
$server->register(
|
||||
'createSkeleton',
|
||||
// Entry values
|
||||
array('authentication'=>'tns:authentication','skeleton'=>'tns:skeleton'),
|
||||
// Exit values
|
||||
array('result'=>'tns:result','id'=>'xsd:string'),
|
||||
$ns,
|
||||
$ns.'#createSkeleton',
|
||||
$styledoc,
|
||||
$styleuse,
|
||||
'WS to create a skeleton'
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get produt or service
|
||||
* Get Skeleton
|
||||
*
|
||||
* @param array $authentication Array of authentication information
|
||||
* @param int $id Id of object
|
||||
@@ -192,6 +206,67 @@ function getSkeleton($authentication,$id,$ref='',$ref_ext='')
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create Skeleton
|
||||
*
|
||||
* @param array $authentication Array of authentication information
|
||||
* @param Skeleton $skeleton $skeleton
|
||||
* @return array Array result
|
||||
*/
|
||||
function createSkeleton($authentication,$skeleton)
|
||||
{
|
||||
global $db,$conf,$langs;
|
||||
|
||||
$now=dol_now();
|
||||
|
||||
dol_syslog("Function: createSkeleton login=".$authentication['login']);
|
||||
|
||||
if ($authentication['entity']) $conf->entity=$authentication['entity'];
|
||||
|
||||
// Init and check authentication
|
||||
$objectresp=array();
|
||||
$errorcode='';$errorlabel='';
|
||||
$error=0;
|
||||
$fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
|
||||
// Check parameters
|
||||
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$newobject=new Skeleton($db);
|
||||
$newobject->prop1=$skeleton->prop1;
|
||||
$newobject->prop2=$skeleton->prop2;
|
||||
//...
|
||||
|
||||
$db->begin();
|
||||
|
||||
$result=$newobject->create($fuser);
|
||||
if ($result <= 0)
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$db->commit();
|
||||
$objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''),'id'=>$newobject->id,'ref'=>$newobject->ref);
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
$error++;
|
||||
$errorcode='KO';
|
||||
$errorlabel=$newobject->error;
|
||||
}
|
||||
}
|
||||
|
||||
if ($error)
|
||||
{
|
||||
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
|
||||
}
|
||||
|
||||
return $objectresp;
|
||||
}
|
||||
|
||||
// Return the results.
|
||||
$server->service($HTTP_RAW_POST_DATA);
|
||||
|
||||
Reference in New Issue
Block a user