Example #1
0
 function WSEAuthenticateHeader($header)
 {
     log_to_file("wsSeguimiento header: " . serialize($header));
     $header = rcommon_object_to_array_lower($header);
     $this->user = isset($header['user']) ? $header['user'] : false;
     $this->password = isset($header['password']) ? $header['password'] : false;
 }
/**
 * Web Service to access digital content SM
 * @param none
 * @return obj -> web service response
 */
function get_book_structure($publisher, $isbn)
{
    global $DB;
    // echo "<br>Indice Libro: ".$wsurl_contenido."<br>";
    $book = $DB->get_record('rcommon_books', array('isbn' => $isbn));
    if (!$book) {
        throw new Exception('Book not found');
    }
    try {
        $client = get_marsupial_ws_client($publisher);
        $isbnparam = @new SoapVar($isbn, XSD_STRING, "string", "http://www.w3.org/2001/XMLSchema");
        $response = $client->ObtenerEstructura(array('ISBN' => $isbnparam));
        log_to_file("get_book_structure Request: " . $client->__getLastRequest());
        log_to_file("get_book_structure Response: " . $client->__getLastResponse());
    } catch (Exception $fault) {
        log_to_file("wsBookStructure: get_book_structure - Exception = " . $fault->getMessage());
        $message = rcommon_ws_error('get_book_structure', $fault->getMessage());
        throw new Exception($message);
    }
    $response = rcommon_object_to_array_lower($response, true);
    $response = isset($response['obtenerestructuraresult']) ? $response['obtenerestructuraresult'] : false;
    if (!$response) {
        $message = get_string('empty_response_error', 'local_rcommon');
        print_object($client->__getLastRequest());
        print_object($client->__getLastResponse());
        debugging('<pre>' . htmlentities($client->__getLastResponse()) . '</pre>');
        $message = rcommon_ws_error('get_book_structure', $message);
        die;
        throw new Exception(get_string('empty_response_error', 'local_rcommon'));
    } else {
        if (isset($response['codigo']) && $response['codigo'] <= 0) {
            $text = array('code' => $response['codigo'], 'description' => $response['descripcion']);
            $message = get_string('wserror', 'local_rcommon', $text);
            if (isset($response['url'])) {
                $message .= ', URL: ' . test_ws_url($response['url']);
            }
            $message = rcommon_ws_error('get_book_structure', $message);
            throw new Exception($message);
        } else {
            save_book_structure($response, $book);
        }
    }
}
Example #3
0
function rcommon_object_to_array_lower($value, $recursive = false)
{
    if (is_array($value)) {
        $array = $value;
    } else {
        if (is_object($value)) {
            $array = (array) $value;
        } else {
            return $value;
        }
    }
    // Solve lack of xmlns
    if (count($array) == 1 && isset($array['any'])) {
        $anyxml = simplexml_load_string('<aux>' . $array['any'] . '</aux>');
        $anyxml = $anyxml->children();
        if (!$anyxml) {
            return false;
        }
        $name = $anyxml->getName();
        if (count($anyxml->{$name}) == 1) {
            $array = array($name => $anyxml->{$name});
        } else {
            $children = array();
            foreach ($anyxml->{$name} as $child) {
                $children[] = $child;
            }
            $array = array($name => $children);
        }
    }
    $array_ret = array();
    foreach ($array as $key => $value) {
        if ($recursive) {
            $array_ret[strtolower($key)] = rcommon_object_to_array_lower($value, $recursive);
        } else {
            $array_ret[strtolower($key)] = $value;
        }
    }
    return $array_ret;
}