Beispiel #1
0
function detailsToStrings($events)
{
    // fonction transforme les détails en chaînes faciles à afficher type "de 8 à 30 ans"
    if ($events) {
        // Traitement des contenus :
        foreach ($events as $key => $event) {
            // echo $event['id'], $event['type'].'<br />';
            $events[$key]['lien'] = generateMediaLink($event['id'], $event['type']);
            // echo $event[$key]['lien'].'<br />';
            // Préparation de la chaîne représentant la tranche d'âge :
            if (isset($event['age_min'], $event['age_max'])) {
                $events[$key]['tranche_age'] = 'De ' . $event['age_min'] . ' à ' . $event['age_max'] . ' ans';
            } elseif (isset($event['age_min'])) {
                $events[$key]['tranche_age'] = 'À partir de ' . $event['age_min'] . ' ans';
            } elseif (isset($event['age_max'])) {
                $events[$key]['tranche_age'] = 'Jusqu\'à ' . $event['age_max'] . ' ans';
            } else {
                $events[$key]['tranche_age'] = '';
            }
            // Préparation de la chaîne représentant le lieu :
            $addressLines = explode(',', $event['adresse']);
            $events[$key]['lieu'] = end($addressLines);
            $events[$key]['debut'] = substr($events[$key]['debut'], 0, 16);
            $events[$key]['debut'] = preg_replace('/-/', '/', $events[$key]['debut']);
            // Préparation de la chaîne représentant la participation
            if (isset($event['invitation'])) {
                switch ($event['invitation']) {
                    case 0:
                        $events[$key]['participation'] = "Vous êtes invité";
                        break;
                    case 1:
                        $events[$key]['participation'] = "Vous participez";
                        break;
                    case 2:
                        $events[$key]['participation'] = "Vous participez peut-être";
                        break;
                    case 3:
                    default:
                        $events[$key]['participation'] = "Vous ne participez pas";
                        break;
                }
            } else {
                $events[$key]['participation'] = "Vous ne participez pas";
            }
            // Préparation de la chaîne représentant la privacy de l'event
        }
        // var_dump($events);
        return $events;
    } else {
        return False;
    }
}
Beispiel #2
0
function getMemberEvents($id)
{
    require_once MODELES . 'events/suggestions.php';
    // requete sql pour prendre les infos nécessaires
    $bdd = new PDO(DSN, DBUSER, DBPASS);
    $query = 'SELECT evenement.id, evenement.debut AS date, evenement.titre, type.nom AS type, adresse.adresse_condensee, evenement.tarif, evenement.age_min, evenement.age_max, evenement.description, media.lien AS image, invitation.etat AS invitation
                FROM membre
                LEFT JOIN invitation ON membre.id=invitation.id_destinataire
                LEFT JOIN evenement ON evenement.id=invitation.id_evenement
                LEFT JOIN type ON evenement.id_type = type.id
                LEFT JOIN adresse ON evenement.id_adresse = adresse.id
                LEFT JOIN media ON evenement.id_media_principal = media.id
                WHERE membre.id = :id
                ORDER BY evenement.debut';
    $query = $bdd->prepare($query);
    $query->execute(['id' => $id]);
    $events = $query->fetchAll(PDO::FETCH_ASSOC);
    // transformation des détails en chaînes faciles à afficher type "de 8 à 30 ans"
    if ($events) {
        // Traitement des contenus :
        foreach ($events as $key => $event) {
            // Préparation de la chaîne représentant la tranche d'âge :
            if (isset($event['age_min'], $event['age_max'])) {
                $events[$key]['tranche_age'] = 'De ' . $event['age_min'] . ' à ' . $event['age_max'] . ' ans';
            } elseif (isset($event['age_min'])) {
                $events[$key]['tranche_age'] = 'À partir de ' . $event['age_min'] . ' ans';
            } elseif (isset($event['age_max'])) {
                $events[$key]['tranche_age'] = 'Jusqu\'à ' . $event['age_max'] . ' ans';
            } else {
                $events[$key]['tranche_age'] = '';
            }
            // Préparation de la chaîne représentant le lieu :
            $addressLines = explode(',', $event['adresse_condensee']);
            $events[$key]['ville'] = end($addressLines);
            // $events[$key]['ville'] = end(explode(' ',end($addressLines)));
            $events[$key]['lien'] = generateMediaLink($event['id'], $event['type']);
            // chaîne représentant la date :
            $events[$key]['day'] = getdate(strtotime($events[$key]['date']))['mday'];
            $events[$key]['month'] = getdate(strtotime($events[$key]['date']))['mon'];
            $events[$key]['year'] = getdate(strtotime($events[$key]['date']))['year'];
            $events[$key]['date'] = date('j/m/o', strtotime($events[$key]['date']));
            // Préparation de la chaîne représentant la participation
            if (isset($event['invitation'])) {
                switch ($event['invitation']) {
                    case 0:
                        $events[$key]['participation'] = "Vous êtes invité";
                        break;
                    case 1:
                        $events[$key]['participation'] = "Vous participez";
                        break;
                    case 2:
                        $events[$key]['participation'] = "Vous participez peut-être";
                        break;
                    case 3:
                    default:
                        $events[$key]['participation'] = "Vous ne participez pas";
                        break;
                }
            } else {
                $events[$key]['participation'] = "Vous ne participez pas";
            }
            // Préparation de la chaîne représentant la privacy de l'event
        }
        // echo '<pre>';
        // var_dump($events);
        // echo '</pre>';
        return $events;
    } else {
        return False;
    }
}
Beispiel #3
0
function suggestions()
{
    if (connected()) {
        //On attrape les infos qu'on veut
        $user_info = getUserDetails($_SESSION['id']);
        $user_events = getMemberEvents($_SESSION['id']);
        $events = getEvents($_SESSION['id']);
        if (empty($events) || empty($user_events) || empty($user_info) || count($events) < 3) {
            return [];
        }
        //Enlève les évents auquel il participe.
        foreach ($events as $key => $value) {
            foreach ($user_events as $cle => $valeur) {
                if (count($events) - count($user_events) > 3) {
                    // Teste s'il y a assez d'évènements pour faire 3 recommendations
                    if ($value["id"] == $valeur['id']) {
                        unset($events[$key]);
                    }
                }
            }
            //Ajoute les coordonnées à chaue événement auquel il ne participe pas.
            if (!isset($events[$key])) {
                continue;
            }
            $event_adress = getAdressCoord($value['id']);
            $events[$key]['coordonnee_long'] = $event_adress['coordonnee_long'];
            $events[$key]['coordonnee_lat'] = $event_adress['coordonnee_lat'];
            $events[$key]['lien_photo'] = generateMediaLink($value['id'], $value['type']);
        }
        // ======= BIENTOT ========
        //Tri par date des evenements
        function date_compare($a, $b)
        {
            $t1 = strtotime($a['debut']);
            $t2 = strtotime($b['debut']);
            return $t1 - $t2;
        }
        usort($events, 'date_compare');
        $timeRec = $events[0];
        // ======= TYPE ========
        //Classement des Types par ID.
        $types = [];
        foreach ($user_events as $key => $value) {
            array_push($types, $value["type"]);
        }
        $types = array_count_values($types);
        $top_type = array_keys($types, max($types));
        //Choix de l'évènement par Type.
        foreach ($events as $key => $value) {
            if (in_array($value['type'], $top_type)) {
                $typeRec = $value;
                if ($timeRec['id'] == $typeRec['id']) {
                    continue;
                } else {
                    break;
                }
            }
        }
        //Aléatoire sinon.
        if (!isset($typeRec)) {
            $typeRec = $events[rand(0, count($events) - 1)];
            while ($timeRec['id'] == $typeRec['id']) {
                $typeRec = $events[rand(0, count($events) - 1)];
            }
        }
        // ======= PROXIMITE ========
        if (isset($user_info['coordonnee_long']) && isset($user_info['coordonnee_lat'])) {
            // Addresse renseignée.
            //Tri par distance (grande sphère)
            foreach ($events as $key => $value) {
                $events[$key]['distance'] = haversineGreatCircleDistance(floatval($user_info['coordonnee_lat']), floatval($user_info['coordonnee_long']), floatval($events[$key]['coordonnee_lat']), floatval($events[$key]['coordonnee_long']));
            }
            function distance_compare($a, $b)
            {
                return $a['distance'] - $b['distance'];
            }
            usort($events, 'distance_compare');
            $proxRec = $events[0];
            if ($proxRec['id'] == $typeRec['id']) {
                $proxRec = $events[1];
            }
        } else {
            //Addresse non renseignée. Donc aléatoire.
            $proxRec = $events[rand(0, count($events) - 1)];
            while ($proxRec['id'] == $typeRec['id'] || $proxRec['id'] == $timeRec['id']) {
                $proxRec = $events[rand(0, count($events) - 1)];
            }
        }
        return [$timeRec, $typeRec, $proxRec];
    } else {
        // 100% radom public events
        $events = getEvents();
        if (count($events) < 3) {
            return [];
        }
        $recs = array_rand($events, 3);
        foreach ($recs as $key => $value) {
            $events[$value]['lien_photo'] = generateMediaLink($value, $events[$value]['type']);
        }
        return [$events[$recs[0]], $events[$recs[1]], $events[$recs[2]]];
    }
}