/
adminCreatePersonnage.php
175 lines (151 loc) · 6.75 KB
/
adminCreatePersonnage.php
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
174
175
<?php
if (!isset($_SESSION))
{
session_start();
}
require_once 'initClass.php';
require_once 'init.php';
if(isset($_SESSION['idJoueurCourant']) && $_SESSION['idJoueurCourant'] != '')
{
// Instance manager
$PersonnageTypeManager = new PersonnageTypeManager($db);
$PersonnageManager = new PersonnageManager($db);
$JoueurManager = new JoueurManager($db);
$EvolutionManager = new EvolutionManager($db);
$FormulaireUniqueId = new FormulaireUniqueId();
$Joueur = new Joueur($JoueurManager->get($_SESSION['idJoueurCourant']));
$Privilege = new Privilege($JoueurManager->getPrivilege($Joueur->getId()));
if($Privilege->hasPermission('personnageCreer'))
{
// Insertion du nouveau personnage.
if( isset($_POST) && count($_POST)>0)
{
if($FormulaireUniqueId->validate())
{
$insert = true;
// Si un champ n'a pas été saisie par l'utisateur
foreach($_POST as $key => $value)
{
if($value == ''){
$insert = false;
}
}
if($insert)
{
// Personnagetype avec les données du POST
$PersonnageType = new PersonnageType($PersonnageTypeManager->get($_POST['personnageTypeId']));
// Création du personnage avec les données POST
// personnageTypeId, nom
$Personnage = new Personnage($_POST);
// Update des attributs du personnage qui ne sont pas dans le POST
$Personnage->setDegat($PersonnageType->getDegat());
$Personnage->setExperience(0);
$Personnage->setMouvement($PersonnageType->getMouvement());
$Personnage->setNombreAttaque($PersonnageType->getNombreAttaque());
$Personnage->setPointDeVie($PersonnageType->getPointDeVie());
$Personnage->setPlanId(1);
$Personnage->setPointInvestissement(0);
$Personnage->setPositionX(1);
$Personnage->setPositionY(1);
$Personnage->setTourDeJeu(date("Y-m-d H:i:s"));
$Personnage->setProchainTourDeJeu(date("Y-m-d H:i:s", strtotime(date("Y-m-d H:i:s"))+"30 seconds"));
/***************************
* DEBUT ENREGISTREMENT BDD
***************************/
// Table personnage
$personnageId = $PersonnageManager->insert($Personnage);
// Table _joueur_personnage (liaison)
$joueurId = $_POST['joueurId'];
$PersonnageManager->insert_joueur_personnage($joueurId,$personnageId);
// Table _personnage_personnageType (liaison)
$PersonnageManager->insert_personnage_personnageType($personnageId, $Personnage->getPersonnageTypeId());
// Récuperation de la liste des évolutions correspondant au personnage type
$evolutionGetBy = $EvolutionManager->getBy('personnageTypeId', $Personnage->getPersonnageTypeId());
$listeEvolution = array();
if(count($evolutionGetBy) > 0)
{
foreach ($evolutionGetBy as $evolution)
{
// Instance de chaque evolution
$iEvolution = new Evolution($evolution);
// Pour la premiere évolution
if( $iEvolution->getPalierInferieur() == '0')
{
// Table _iconepersonnage_personnage (liaison)
$PersonnageManager->insert_iconePersonnage_personnage($personnageId, $iEvolution->getIconePersonnageId());
}
}
}
/***************************
* FIN ENREGISTREMENT BDD
***************************/
$_SESSION['messageInsertPersonnage'] = true;
}
}
}
//Liste des joueurs
$joueurGetAll = $JoueurManager->getAll();
$listeJoueur = array();
if(count($joueurGetAll) > 0)
{
foreach ($joueurGetAll as $joueur)
{
// Instance de chaque joueur
$listeJoueur[] = new Joueur($joueur);
}
}
//Liste des personnages type
$personnageTypeGetAll = $PersonnageTypeManager->getAll();
$listePersonnageType = array();
if(count($personnageTypeGetAll) > 0)
{
foreach ($personnageTypeGetAll as $personnageType)
{
// Instance de chaque personnage type
$listePersonnageType[] = new PersonnageType($personnageType);
}
}
// Contruction d'une variable selectJoueurs au format d'un optiongroup
$selectJoueurs = array();
if(count($joueurGetAll) > 0)
{
foreach ($joueurGetAll as $key => $item)
{
if( !isset($selectJoueurs[$item['roleNom']]) )
{
$selectJoueurs[$item['roleNom']] = array();
}
array_push($selectJoueurs[$item['roleNom']],new Joueur($item)) ;
}
}
if(isset($_SESSION['messageInsertPersonnage']) && $_SESSION['messageInsertPersonnage'] == true)
{
$smarty->assign('messageInsertPersonnage', true);
$smarty->assign('messageInsertPersonnageContent', $smarty->fetch('message/messageInsertPersonnage.tpl'));
// Initialisation des variables sessions
$_SESSION['messageInsertPersonnage'] = false;
}
else
{
// Initialisation des variables templates
$smarty->assign('messageInsertPersonnage', false);
}
// Variables templates
$smarty->assign('listePersonnageType', $listePersonnageType);
$smarty->assign('listeJoueur', $listeJoueur);
$smarty->assign('Joueur', $Joueur);
$smarty->assign('selectJoueurs', $selectJoueurs);
$smarty->assign('Privilege', $Privilege);
$smarty->assign('FormulaireUniqueId', $FormulaireUniqueId);
$smarty->display('page/pageAdminCreatePersonnage.tpl');
}
else
{
header('Location: homepage.php');
}
}
else
{
header('Location: index.php');
}
?>