1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
/**
* Fonction permettant d'obtenir toutes les informations à propos d'un sport. L'array retourner est de la forme :
* id : int
* nom : string
* description : string
* matos: string
* actif: boolean
* horaires:
* id: int
* salle:
* id: int
* nom: string
* ville: string
* adresse: string
* jour: string
* heure:
* debut: timestamp
* fin: timestamp
* participants:
* id: int
* nom: string
* prenom: string
* photo_id: int
* statut: string
* photos:
* id: int
*
* @param int $id Id du sport à récupérer
* @return array Contient toutes les information à propos d'un sport ( horaires, participants, photos ) cf ci dessus pour la structure
*/
public function getCompleteSport($id) {
if ( empty($id) || $id === null )
return false;
// On récupère la table sport avec les tables de liaisons qui correspondent aux participants, aux photos et aux horaires
$q = new Doctrine_RawSql();
$sport_infos = $q->select('
{s.nom},
{s.description},
{s.matos},
{s.actif},
{h.salle_id},
{h.jour},
{h.heure_debut},
{h.heure_fin},
{pa.cotisant_type_id}')
->from('
sp_sports s
LEFT JOIN sp_participants pa ON s.id = pa.sport_id
LEFT JOIN sp_photos po ON s.id = po.sport_id
LEFT JOIN sp_horaires h ON s.id = h.sport_id')
->where('s.id = ?', $id)
->addComponent('s', 'spSport s')
->addComponent('pa', 's.sp_participants pa')
->addComponent('po', 's.sp_photos po')
->addComponent('h', 's.sp_horaires h')
->execute(array(), Doctrine::HYDRATE_ARRAY);
if(empty($sport_infos))
return false;
// On récupère toutes les informations nécessaires sur les participants : nom, prenom, statut dans le sport (responsable, co responsable , ...), etc...
if (!empty($sport_infos[0]['sp_participants'])) {
// On fait la liste des participants et des statuts pour aller récupérer leurs infos
foreach ( $sport_infos[0]['sp_participants'] as $participant ) {
$participants_id[] = $participant['cotisant_id'];
$participants_statuts[] = $participant['cotisant_type_id'];
}
// Récupération des infos personnelles
$q = new Doctrine_RawSql();
$cotisants_infos = $q->select('
{c.nom},
{c.prenom},
{c.photo_id}')
->from('co_cotisants c')
->where('c.id IN (' . implode( ',', $participants_id ) . ')')
->addComponent('c', 'coCotisant c')
->execute(array(), Doctrine::HYDRATE_ARRAY);
// Récupération des infos sur le statut
$q = new Doctrine_RawSql();
$statuts_infos = $q->select('{st.description}')
->from('sp_participants_types st')
->where("st.id IN (" . implode(',', $participants_statuts) . ')')
->addComponent('st', 'spParticipantType st')
->execute(array(), Doctrine::HYDRATE_ARRAY);
;
}
// On récupère maintenant toutes les infos sur les horaires et donc les salles: nom, lieu, adresse, heure, jour,...
if (!empty($sport_infos[0]['sp_horaires'])) {
// On fait la la liste de toutes les salles prise par ce sport, pour ensuite récupérer leurs infos dans la table sp_salles
foreach ( $sport_infos[0]['sp_horaires'] as $horaire )
$horaires_salle_id[] = $horaire['salle_id'];
$q = new Doctrine_RawSql();
$salles_infos = $q->select('
{sa.adresse},
{sa.nom},
{sa.ville}')
->from('sp_salles sa')
->where('sa.id IN (' . implode( ',', $horaires_salle_id ) . ')' )
->addComponent('sa', 'spSalle sa')
->execute(array(), Doctrine::HYDRATE_ARRAY);
}
// On commence donc par remettre en forme les infos sur les salles pour condenser le tout
if (isset($salles_infos)) {
// On condense les salle
foreach ( $salles_infos as $salle )
$salles["{$salle['id']}"] = array(
'id' => $salle['id'],
'nom' => $salle['nom'],
'ville' => $salle['ville'],
'adresse' => $salle['adresse']
);
// On condense les horaires en y incluant les salles correspondantes
foreach ( $sport_infos[0]['sp_horaires'] as $horaire )
$horaires["{$horaire['id']}"] = array(
'id' => $horaire['id'],
'salle' => $salles[$horaire['salle_id']],
'jour' => $horaire['jour'],
'heure' => array('debut' => date( 'H:i', strtotime( $horaire['heure_debut'] ) ), 'fin' => date( 'H:i', strtotime( $horaire['heure_fin'] ) ) )
);
}
// On met maintenant en forme les participants ( participant = cotisant + statut )
if ( isset($cotisants_infos) && isset($statuts_infos) ) {
// On met en forme les cotisants
foreach ( $cotisants_infos as $cotisant )
$cotisants["{$cotisant['id']}"] = array(
'nom' => $cotisant['nom'],
'prenom' => $cotisant['prenom'],
'photo_id' => $cotisant['photo_id']
);
// On met en forme les statuts
foreach ( $statuts_infos as $statut )
$statuts["{$statut['id']}"] = array('description' => $statut['description']);
// On condense le tout en incluant les statut et les cotisants au sein d'un même tableau pour donnée un tableau de participants
foreach ( $sport_infos[0]['sp_participants'] as $participant )
$participants["{$participant['cotisant_id']}"] = array(
'id' => $participant['cotisant_id'],
'nom' => $cotisants["{$participant['cotisant_id']}"]['nom'],
'prenom' => $cotisants["{$participant['cotisant_id']}"]['prenom'],
'photo_id' => $cotisants["{$participant['cotisant_id']}"]['photo_id'],
'statut' => $statuts["{$participant['cotisant_type_id']}"]['description']
);
}
// On met en forme les photos
if ( !empty( $sport_infos[0]['sp_photos'] ) )
foreach ( $sport_infos[0]['sp_photos'] as $photo)
$photos[] = $photo['photo_id'];
// Phase final: on condense les infos sur le sport, sur les participants, les horaires et les photos au sein d'un même tableau.
$sport = array(
'nom' => $sport_infos[0]['nom'],
'description' => $sport_infos[0]['description'],
'matos' => $sport_infos[0]['matos'],
'actif' => $sport_infos[0]['actif'],
'horaires' => isset( $horaires ) ? $horaires : false,
'participants' => isset( $participants ) ? $participants : false,
'photos' => isset( $photos ) ? $photos : false
);
// On verifie qu'il n'y est pas d'informations manquantes pour eviter les erreur d'affichage
return ( empty($sport['nom']) || empty($sport['description']) || empty($sport['matos']) ) ? false : $sport;
} |
Partager