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:
@@ -142,6 +142,27 @@ while($i<count($properties))
|
|||||||
$targetcontent=preg_replace('/\'prop1\'=>\$'.$classmin.'->prop1,/', $varprop, $targetcontent);
|
$targetcontent=preg_replace('/\'prop1\'=>\$'.$classmin.'->prop1,/', $varprop, $targetcontent);
|
||||||
$targetcontent=preg_replace('/\'prop2\'=>\$'.$classmin.'->prop2,/', '', $targetcontent);
|
$targetcontent=preg_replace('/\'prop2\'=>\$'.$classmin.'->prop2,/', '', $targetcontent);
|
||||||
|
|
||||||
|
// Substitute get method parameters
|
||||||
|
$varprop="\n\t\t";
|
||||||
|
$cleanparam='';
|
||||||
|
$i=0;
|
||||||
|
|
||||||
|
while($i<count($properties))
|
||||||
|
{
|
||||||
|
|
||||||
|
$varprop.='$newobject->'.$properties[$i].'=$'.$classmin.'->'.$properties[$i].';';
|
||||||
|
|
||||||
|
$i++;
|
||||||
|
if ($i == count($properties))
|
||||||
|
$varprop.="\n";
|
||||||
|
else
|
||||||
|
$varprop.="\n\t\t";
|
||||||
|
}
|
||||||
|
$targetcontent=preg_replace('/\$newobject->prop1=\$'.$classmin.'->prop1;/', $varprop, $targetcontent);
|
||||||
|
$targetcontent=preg_replace('/\$newobject->prop2=\$'.$classmin.'->prop2;/', '', $targetcontent);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Build file
|
// Build file
|
||||||
$fp=fopen($outfile,"w");
|
$fp=fopen($outfile,"w");
|
||||||
if ($fp)
|
if ($fp)
|
||||||
|
|||||||
@@ -118,11 +118,25 @@ $server->register(
|
|||||||
'WS to get skeleton'
|
'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 array $authentication Array of authentication information
|
||||||
* @param int $id Id of object
|
* @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.
|
// Return the results.
|
||||||
$server->service($HTTP_RAW_POST_DATA);
|
$server->service($HTTP_RAW_POST_DATA);
|
||||||
|
|||||||
Reference in New Issue
Block a user