- Avertissement
- Toutes les interactions avec l'api se font en passant par les méthodes des classes
Bdu_Api et Bdu_Configuration.
Initialisation
La configuration doit être initialisée dans un fichier qui sera inclus dans toutes les pages utilisant l'api.
<?php
require_once dirname(__FILE__).'/bdu-api/lib/autoload.php';
$config->setCharset('UTF-8');
$config->setLogger($logger);
La suite de la documentation supposera que ce fichier est inclus dans toutes les pages et ne montrera plus cette étape.
Recherche d'un étudiant
Vérification d'un login
L'api permet de vérifier si un login SdE existe.
<?php
$valid = $api->isValidLogin('11goreti');
Recherche par nom, surnom ou chambre
La recherche par login se fait grâce à Bdu_Api::searchStudentByLogin() et renvoie un objet représentant un étudiant.
<?php
$student = $api->searchStudentByLogin('11goreti');
$student = $api->searchStudentByLogin('11goreti', false);
$name = $student->getProperty('cn');
Recherche par nom, surnom ou chambre
Les autres fonctions de recherche renvoient un tableau de résultats.
<?php
$students = $api->searchStudentsByName('Gorêt', 'Ignace');
$students = $api->searchStudentsByNick('Foobar');
$students = $api->searchStudentsByRoom('C322');
Recherche d'une association
L'api permet aussi de rechercher les informations sur les associations.
<?php
$associations = $api->searchAssociationsByName('SdE');
$association = $api->searchAssociationById(42);
Appartenance aux associations
Recherche par étudiant
L'api permet de rechercher les mandats d'un étudiant:
<?php
$student = $api->searchStudentByLogin('11goreti');
$mandates = $student->getCurrentMandates();
$mandates = $student->getAllMandates();
foreach ($mandates as $mandate){
echo $mandate->getStartDate()->format('d/m/Y');
$position = $mandate->getPosition();
echo $position->getName();
echo $position->getDescription();
$asso = $position->getAssociation();
}
$associations = $student->getCurrentAssociations();
$associations = $student->getAllAssociations();
Recherche par association
L'api permet de rechercher les membres d'une association:
<?php
$association = $api->searchAssociationById(147);
$mandates = $association->getCurrentMandates();
$mandates = $association->getAllMandates();
foreach ($mandates as $mandate){
echo $mandate->getStartDate()->format('d/m/Y');
$student = $mandate->getStudent();
$position = $mandate->getPosition();
echo $position->getName();
echo $position->getDescription();
}
$students = $association->getCurrentStudents();
$students = $association->getAllStudents();
Récupération des photos
L'api permet de récupérer les photos SdE des étudiants. Ceci est possible de deux manières (totalement équivalentes):
- depuis la classe
Bdu_Api <?php
?>
<img src="<?php echo $api->getStudentPhotoUrl($login); ?>" alt="" />
- depuis un objet
Bdu_Entity_Student <?php
$student = $api->searchStudentByLogin('11goreti');
?>
<img src="<?php echo $student->getPhoto(); ?>" alt="" />
- Note
- Si l'étudiant n'a pas de photo SdE une silhouette sera affichée (la même que sur le SdE).