4.13  Topic Content Retrieval Webservice: offset

This webservice differs from the previous one in the sense that you can define an offset mode to add retrieval pagination

$param = array(
    'idforum' => 1,
    'idcat' => 22,
    'idtopic' => 48,
    'tri' => 0,
    'offset' => 0,
    'limit' => 10
);
$results = $sel->call('read_topic', $param);

This webservice returns several parameters:

4.13.1  Pagination Management Example via the read_topic_page Webservice

We provide an example of topic reading management via the webservice which can be used on a website to include comments on the articles.

<?php

require('nusoap/nusoap.php');

// tests parameters
$idsite= 1;
$urlnameforum= 'forumdev';
$url_forum= 'http://forumdev.mydiscussions.net/';
$url_webservice= 'http://forumdev.mydiscussions.net/webservices/wservice.php';
$idcat= 22;
$idtopic= 48;
$tri= 0; // 0 = ascending order, 1 => descending order
$reponse_par_page= 5;

if (isset($_GET['idtopic'])) {
    $idtopic= intval($_GET['idtopic']);    
}
if (isset($_GET['page'])) {
    $page= intval($_GET['page']);
} else {
    $page= 1;
}

$offset= (($page-1)*$reponse_par_page)+1;

$sel = new soapclient($url_webservice);

$param = array('idforum' => $idsite,'idcat' => $idcat,'idtopic' => $idtopic,'tri' => $tri, 'offset' => $offset,'limit' => $reponse_par_page);
$results = $sel->call('read_topic_page', $param);

$sujet_titre= $results['topictitle'];

?>

<h1><?php echo $sujet_titre; ?></h1>
<p>Ici se trouve mon site.</p>
<?php
$nbrep= $results['nbanswer'];

echo $nbrep,' messages<hr />';

$nbpage= ceil(($nbrep)/$reponse_par_page); // Calculate the number of pages

echo 'Pages :';
for ($i=1;$i<=$nbpage;$i++) {
    if ($i == $page) {
        echo ' ',$i,' ';
    } else {
        echo ' <a href="?idtopic='.$idtopic.'&amp;page='.$i.'">',$i,'</a> ';    
    }
}

echo '</hr>';
if ($nbrep == 0) { // if the number of replies is equal to 0, we display a different message.
    echo "<a href=\"$url_forum/message.php?config=$urlnameforum.inc&cat=$idcat&post=$idtopic&page=$page\">Be the first to leave a comment</a>";    
} else {
    echo "<a href=\"$url_forum/message.php?config=$urlnameforum.inc&cat=$idcat&post=$idtopic&page=$page\">Leave a comment</a>";    
}
echo '<hr />';
$xml_get = simplexml_load_string(utf8_encode($results['messages']));

if ($xml_get) {
    foreach ($xml_get->reponse as $reponse) {
     $auteur= $reponse->auteur;
     $date= $reponse->date;
     $contenu= $reponse->message;
     echo '<blockquote>';
        echo utf8_decode($auteur),' - ',utf8_decode($date),'<br />';
        echo '-------<br />';
        echo utf8_decode($contenu);
     echo '</blockquote>';
        echo '<hr />';
    }
}
?>

4.12 Topic Content Retrieval Webservice4.14 User Creation Webservice