示例#1
0
function points_potins($id_user, $bdd)
{
    $points = 0;
    // Combien les potins publiés ont rapportés
    $potins_user = rechercher_potins_d_un_auteur($id_user, $bdd);
    if ($potins_user != 0) {
        foreach ($potins_user as $key => $value) {
            switch (resultat_vote($value, $bdd)) {
                case 'sur':
                    $points += 10;
                    break;
                case 'possible':
                    $points += 5;
                    break;
                case 'faux':
                    $points -= 3;
                    break;
                case 'calomnie':
                    $points -= 5;
                    break;
                default:
                    break;
            }
        }
    }
    return $points;
}
<?php

$num_page = $_GET['num_page'];
$limit = $_GET['limit'];
$offset = $limit * $num_page;
include_once 'modele/rechercher_potins.php';
include_once 'vue/potin/affichage_potin.php';
include_once 'vue/potin/potin_v4.php';
$reponse = NULL;
$j = 0;
$potins_cherches = rechercher_potins_d_un_auteur($id_user, $bdd);
if ($potins_cherches != 0) {
    $potins_cherches = array_slice($potins_cherches, $offset, $limit);
    foreach ($potins_cherches as $i => $potin_courant) {
        $potin_courant = infos_potin($potin_courant, $bdd);
        $reponse['potin' . $j] = vue_potin_v4($potin_courant, $id_user, $bdd);
        $j++;
    }
    $reponse['nb_potins'] = $j;
} else {
    $reponse['nb_potins'] = 0;
}
echo json_encode($reponse);