/**
  * Delete skeleton
  *
  * @param   int     $id   Skeleton ID
  * @return  array
  * 
  * @url	DELETE skeleton/{id}
  */
 function delete($id)
 {
     if (!DolibarrApiAccess::$user->rights->skeleton->supprimer) {
         throw new RestException(401);
     }
     $result = $this->skeleton->fetch($id);
     if (!$result) {
         throw new RestException(404, 'Skeleton not found');
     }
     if (!DolibarrApi::_checkAccessToResource('skeleton', $this->skeleton->id)) {
         throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
     }
     if (!$this->skeleton->delete($id)) {
         throw new RestException(500);
     }
     return array('success' => array('code' => 200, 'message' => 'Skeleton deleted'));
 }
/**
 * Get Skeleton
 *
 * @param	array		$authentication		Array of authentication information
 * @param	int			$id					Id of object
 * @param	string		$ref				Ref of object
 * @param	string		$ref_ext			Ref external of object
 * @return	mixed
 */
function getSkeleton($authentication, $id, $ref = '', $ref_ext = '')
{
    global $db, $conf, $langs;
    dol_syslog("Function: getSkeleton login="******" id=" . $id . " ref=" . $ref . " ref_ext=" . $ref_ext);
    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 && ($id && $ref || $id && $ref_ext || $ref && $ref_ext)) {
        $error++;
        $errorcode = 'BAD_PARAMETERS';
        $errorlabel = "Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both.";
    }
    if (!$error) {
        $fuser->getrights();
        if ($fuser->rights->skeleton->read) {
            $skeleton = new Skeleton($db);
            $result = $skeleton->fetch($id, $ref, $ref_ext);
            if ($result > 0) {
                // Create
                $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'skeleton' => array('prop1' => $skeleton->prop1, 'prop2' => $skeleton->prop2));
            } else {
                $error++;
                $errorcode = 'NOT_FOUND';
                $errorlabel = 'Object not found for id=' . $id . ' nor ref=' . $ref . ' nor ref_ext=' . $ref_ext;
            }
        } else {
            $error++;
            $errorcode = 'PERMISSION_DENIED';
            $errorlabel = 'User does not have permission for this request';
        }
    }
    if ($error) {
        $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
    }
    return $objectresp;
}