IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Symfony PHP Discussion :

convertir un script PHP en TWIG


Sujet :

Symfony PHP

  1. #1
    Candidat au Club
    Homme Profil pro
    Architecte de système d'information
    Inscrit en
    Février 2012
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Architecte de système d'information
    Secteur : Enseignement

    Informations forums :
    Inscription : Février 2012
    Messages : 2
    Points : 3
    Points
    3
    Par défaut convertir un script PHP en TWIG
    Bonjour,

    Dans le cadre d'un projet je cherche a mettre en place un emploi du temps pour les classes et salles.

    J'ai un scrypte PHP qui marche bien, comme je travaille sur symfony, je cherche a le modifier en TWIG

    voici le scripte en PHP

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    <html>
     
    <head>
     
    <title>Emploi du temps</title>
     
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
     
    <style type="text/css">
     
    td { text-align: center; font: bold small Georgia, "Times New Roman", Times, serif }
     
    </style>
     
    </head>
     
    <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
     
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
     
    <tr>
     
    <?
     
    function afficher($a_afficher) {
     
    $filtre=array(
     
    "!"=>"<font color=\"#A0A0F0\">Manger</font>",
     
    "<>"=>"<br>",
     
    "t"=>"<br>TP",
     
    "M"=>"Mathématiques",
     
    "P"=>"Physiques",
     
    "S"=>"SVT",
     
    "F"=>"Français",
     
    "A"=>"Anglais",
     
    "D"=>"Allemand",
     
    "H"=>"Histoire-Géographie",
     
    "C"=>"ECJS",
     
    "E"=>"EPS"
     
    );
     
    echo ($a_afficher=="") ? "&nbsp;" : strtr($a_afficher, $filtre) ;
     
    }
     
    $jours=array(
     
    "Lundi"=>array("P<>311", "F<>56", "H<>225", "F<>321", "a;b<>", "a;b<>", "a;b<>", "", "","","M<>65"),
     
    "Mardi"=>array("P<>311", "F<>320", "F<>320", "P<>311", "a;b<>", "a;b<>", "a;b<>", "St", "St","",""),
     
    "Mercredi"=>array("S<>311", "S<>311", "D<>122", "A<>321", "a;b<>", "a;b<>", "a;b<>", "", "","",""),
     
    "Jeudi"=>array("", "", "H<>221", "F<>223", "a;b<>", "a;b<>", "a;b<>", "E", "E","",""),
     
    "Vendredi"=>array("F<>311", "P<>311", "P<>211", "D<>311", "a;b<>", "a;b<>", "a;b<>", "M<>306", "","",""),
     
    "Samedi"=>array("", "", "H<>221", "F<>223", "a;b<>", "a;b<>", "a;b<>", "E", "E","","M<>65")
     
    );
     
    $largeur=(100/count($jours));
     
    while ($largeur*count($jours)>95) { $largeur--; }
     
    echo "<td width=\"".(100-$largeur*count($jours))."%\">\n<table width=\"100%\" height=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tr><td height=\"26\"></td></tr>\n";
     
    for ($id_for=8;$id_for<=19;$id_for++) {
     
    echo "<tr><td height=\"66\">$id_for H</td></tr>\n";
     
    }
     
    echo "</table>\n</td>\n";
     
    foreach ($jours as $jour=>$horaires) {
     
    $case=0;
     
    echo "<td width=\"$largeur%\" height=\"100%\">\n<table width=\"100%\" height=\"100%\" border=\"1\" bordercolor=\"#000000\" cellspacing=\"0\" cellpadding=\"0\">\n<tr><td height=\"26\" bgcolor=\"#CFFFCF\">$jour</td></tr>\n";
     
    foreach ($horaires as $horaire) {
     
    if (($horaire!=$horaires[$case-1])||(!isset($horaires[$case-1]))) {
     
    $hauteur=66;
     
    $id_while=0;
     
    while (($horaire==$horaires[$case+(++$id_while)])&&(isset($horaires[$case+$id_while]))) {
     
    $hauteur+=66;
     
    }
     
    echo "<tr><td height=\"$hauteur\">";
     
    if (substr($horaire, 0, 1)=="a") {
     
    echo "\n<table width=\"100%\" height=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tr>\n<td width=\"50%\" bgcolor=\"#FFB45F\">";
     
    afficher(substr($horaire, 1, strpos($horaire, ";")-1));
     
    echo "</td>\n<td width=\"50%\" bgcolor=\"#FFB45F\">";
     
    afficher(substr($horaire, strpos($horaire, "b")+1));
     
    echo "</td>\n</tr></table>\n";
     
    } else { afficher($horaire); }
     
    echo "</td></tr>\n";
     
    }
     
    $case++;
     
    }
     
    echo "</table>\n</td>\n";
     
    }
     
    ?>
     
    </tr></table>
     
    </body>
     
    </html>
    Un des problemes est de trouver un equivalent de While de PHP en TWIG

  2. #2
    Modérateur
    Avatar de grunk
    Homme Profil pro
    Lead dév - Architecte
    Inscrit en
    Août 2003
    Messages
    6 691
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Lead dév - Architecte
    Secteur : Industrie

    Informations forums :
    Inscription : Août 2003
    Messages : 6 691
    Points : 20 222
    Points
    20 222
    Par défaut
    Twig ne supporte que les boucles {% for %} .

    Le but la derrière est de simplifier au maximum la vue et éviter d'y retrouver toute la logique métier.

    C'est donc à toi de faire coté controller ce qu'il faut pour pouvoir utiliser tes données dans une boucle for.
    Pry Framework php5 | N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

Discussions similaires

  1. Convertir script PHP en Python
    Par Flopp dans le forum Général Python
    Réponses: 0
    Dernier message: 19/10/2016, 19h15
  2. script php pour convertir un array en xml
    Par omar24 dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 4
    Dernier message: 02/03/2011, 14h22
  3. Convertir un script php en Perl
    Par joboy84 dans le forum Langage
    Réponses: 2
    Dernier message: 02/07/2008, 20h59
  4. Convertir un script php en asp
    Par tibow dans le forum ASP
    Réponses: 3
    Dernier message: 20/11/2005, 02h14

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo