From aafab12f4b4775cebe001ba40a1a0e1a7db0fd6d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 29 Apr 2018 18:06:31 +0200 Subject: [PATCH] Debug API for ticket module --- .../facture/class/api_invoices.class.php | 3 +- htdocs/core/lib/functions2.lib.php | 3 + htdocs/product/class/api_products.class.php | 6 +- ...etsups.class.php => api_tickets.class.php} | 109 ++++++++++++++---- htdocs/ticketsup/class/ticketsup.class.php | 13 ++- 5 files changed, 101 insertions(+), 33 deletions(-) rename htdocs/ticketsup/class/{api_ticketsups.class.php => api_tickets.class.php} (89%) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 35f7e966104..8547be8cb2c 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -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} diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index dc223f58ec3..0b8d42f3a9e 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -2268,6 +2268,9 @@ function getModuleDirForApiClass($module) elseif ($module == 'ficheinter' || $module == 'interventions') { $moduledirforclass = 'fichinter'; } + elseif ($module == 'tickets') { + $moduledirforclass = 'ticketsup'; + } return $moduledirforclass; } diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 083aeb80e34..8d4c435b18e 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -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); diff --git a/htdocs/ticketsup/class/api_ticketsups.class.php b/htdocs/ticketsup/class/api_tickets.class.php similarity index 89% rename from htdocs/ticketsup/class/api_ticketsups.class.php rename to htdocs/ticketsup/class/api_tickets.class.php index 98af42fd262..e2e2776dcfc 100644 --- a/htdocs/ticketsup/class/api_ticketsups.class.php +++ b/htdocs/ticketsup/class/api_tickets.class.php @@ -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,36 +53,93 @@ class Ticketsups extends DolibarrApi /** * Constructor - * - * @url GET ticketsup/ - * */ public function __construct() { - global $db; - $this->db = $db; + global $db; + $this->db = $db; $this->ticketsup = new Ticketsup($this->db); } /** - * Get properties of a ticketsup object - * - * Return an array with ticketsup 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 - * - * @url GET track_id/{track_id} - * @url GET ref/{ref} - * @url GET {id} - * @throws RestException - */ - public function get($id = 0, $track_id = '', $ref = '') + * Get properties of a Ticket object. + * + * 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 + * + * @throws 401 + * @throws 403 + * @throws 404 + */ + 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); diff --git a/htdocs/ticketsup/class/ticketsup.class.php b/htdocs/ticketsup/class/ticketsup.class.php index a8b8e7f5479..b416819b4b6 100644 --- a/htdocs/ticketsup/class/ticketsup.class.php +++ b/htdocs/ticketsup/class/ticketsup.class.php @@ -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); - return 1; + $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);