Debug API for ticket module

This commit is contained in:
Laurent Destailleur
2018-04-29 18:06:31 +02:00
parent 1a9476bff5
commit aafab12f4b
5 changed files with 101 additions and 33 deletions

View File

@@ -1072,8 +1072,9 @@ class Invoices extends DolibarrApi
/**
* Add a payment to pay partially or completely one or several invoices.
* Warning: Take care that all invoices are owned by the same customer.
* Example of value for parameter arrayofamounts: {"1": "99.99", "2": "10"}
*
* @param array $arrayofamounts {@from body} Array with id of invoices with amount to pay for each invoice. Example {"1": "99.99", "2": "10"}
* @param string $arrayofamounts {@from body} Array with id of invoices with amount to pay for each invoice
* @param string $datepaye {@from body} Payment date {@type timestamp}
* @param int $paiementid {@from body} Payment mode Id {@min 1}
* @param string $closepaidinvoices {@from body} Close paid invoices {@choice yes,no}

View File

@@ -2268,6 +2268,9 @@ function getModuleDirForApiClass($module)
elseif ($module == 'ficheinter' || $module == 'interventions') {
$moduledirforclass = 'fichinter';
}
elseif ($module == 'tickets') {
$moduledirforclass = 'ticketsup';
}
return $moduledirforclass;
}

View File

@@ -59,16 +59,16 @@ class Products extends DolibarrApi
*
* @param int $id ID of product
* @param int $includestockdata Load also information about stock (slower)
* @return array|mixed data without useless information
* @return array|mixed Data without useless information
*
* @throws RestException
* @throws 401
* @throws 403
* @throws 404
*/
function get($id, $includestockdata=0)
{
if(! DolibarrApiAccess::$user->rights->produit->lire) {
throw new RestException(401);
throw new RestException(403);
}
$result = $this->product->fetch($id);

View File

@@ -28,7 +28,7 @@ require_once DOL_DOCUMENT_ROOT . '/core/lib/ticketsup.lib.php';
*
*
*/
class Ticketsups extends DolibarrApi
class Tickets extends DolibarrApi
{
/**
* @var array $FIELDS Mandatory fields, checked when create and update object
@@ -53,9 +53,6 @@ class Ticketsups extends DolibarrApi
/**
* Constructor
*
* @url GET ticketsup/
*
*/
public function __construct()
{
@@ -65,24 +62,84 @@ class Ticketsups extends DolibarrApi
}
/**
* Get properties of a ticketsup object
* Get properties of a Ticket object.
*
* Return an array with ticketsup informations
* Return an array with ticket informations
*
* @param int $id ID of ticketsup
* @return array|mixed Data without useless information
*
* @throws 401
* @throws 403
* @throws 404
*/
function get($id)
{
return $this->getCommon($id, '', '');
}
/**
* Get properties of a Ticket object from track id
*
* Return an array with ticket informations
*
* @param string $track_id Tracking ID of ticket
* @return array|mixed Data without useless information
*
* @url GET track_id/{track_id}
*
* @throws 401
* @throws 403
* @throws 404
*/
public function getByTrackId($track_id)
{
return $this->getCommon(0, $track_id, '');
}
/**
* Get properties of a Ticket object from ref
*
* Return an array with ticket informations
*
* @param string $ref Reference for ticket
* @return array|mixed Data without useless information
*
* @url GET ref/{ref}
*
* @throws 401
* @throws 403
* @throws 404
*/
public function getByRef($ref)
{
try {
return $this->getCommon(0, '', $ref);
}
catch(Exception $e)
{
throw $e;
}
}
/**
* Get properties of a Ticket object
*
* Return an array with ticket informations
*
* @param int $id ID of ticketsup
* @param string $track_id Tracking ID of ticket
* @param string $ref Reference for ticket
* @return array|mixed data without useless information
* @return array|mixed Data without useless information
*
* @url GET track_id/{track_id}
* @url GET ref/{ref}
* @url GET {id}
* @throws RestException
* @throws 401
* @throws 403
* @throws 404
*/
public function get($id = 0, $track_id = '', $ref = '')
public function getCommon($id = 0, $track_id = '', $ref = '')
{
if (! DolibarrApiAccess::$user->rights->ticketsup->read) {
throw new RestException(401);
throw new RestException(403);
}
// Check parameters
@@ -474,9 +531,9 @@ class Ticketsups extends DolibarrApi
function _cleanObjectDatas($object)
{
// Remove $db object property for object
unset($object->db);
$object = parent::_cleanObjectDatas($object);
// Other attributes to clean
$attr2clean = array(
"contact",
"contact_id",
@@ -515,7 +572,9 @@ class Ticketsups extends DolibarrApi
"firstname",
"civility_id",
"cache_msgs_ticket",
"cache_logs_ticket"
"cache_logs_ticket",
"statuts_short",
"statuts"
);
foreach ($attr2clean as $toclean) {
unset($object->$toclean);

View File

@@ -489,7 +489,8 @@ class Ticketsup extends CommonObject
dol_syslog(get_class($this) . "::fetch sql=" . $sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
if ($this->db->num_rows($resql)) {
if ($this->db->num_rows($resql))
{
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
@@ -529,10 +530,14 @@ class Ticketsup extends CommonObject
$this->tms = $this->db->jdate($obj->tms);
$this->fetch_optionals();
}
$this->db->free($resql);
$this->db->free($resql);
return 1;
}
else
{
return 0;
}
} else {
$this->error = "Error " . $this->db->lasterror();
dol_syslog(get_class($this) . "::fetch " . $this->error, LOG_ERR);