Rename education_fmt to display_education and make it a Smarty plugin
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Mon, 22 Mar 2010 09:23:41 +0000 (10:23 +0100)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Mon, 22 Mar 2010 13:07:56 +0000 (14:07 +0100)
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
include/education.func.inc.php
plugins/function.display_education.php [new file with mode: 0644]
templates/include/minifiche.tpl

index 4da4acd..16cca57 100644 (file)
@@ -106,68 +106,5 @@ function education_degree_name()
 }
 Platal::page()->register_function('education_degree_name', 'education_degree_name');
 
-/** formatte une formation pour l'affichage
- */
-function education_fmt($name, $url, $degree, $grad_year, $field, $program, $sexe, $long)
-{
-    $field = strtolower($field);
-    $txt = "";
-
-    if ($grad_year || $field || $program) {
-        $txt .= "<span title=\"(";
-        if ($program) {
-            $txt .= $program;
-            if ($grad_year || $field) {
-                $txt .= ", ";
-            }
-        }
-        if ($grad_year) {
-            if ($sexe) {
-                $txt .= "diplômée en $grad_year";
-            } else {
-                $txt .= "diplômé en $grad_year";
-            }
-            if ($field) {
-                $txt .= ", ";
-            }
-        }
-        if ($field) {
-            $txt .= "domaine : $field)\">";
-        }
-    }
-
-    if (($degree != "Lic.") || ($long)) {
-        if (($degree != "Ing.") && ($degree != "Dipl.")) {
-            $txt .= $degree;
-        }
-        if ($name) {
-            $txt .= ' ';
-        }
-        if ($url != ' ') {
-            $txt .= "<a href=\"$url\" onclick=\"return popup(this)\">$name</a>";
-        } else {
-            $txt .= $name;
-        }
-    }
-    $txt .= "</span>";
-
-    return $txt;
-}
-
-function _education_fmt($params, &$smarty)
-{
-    $params  = new PlDict($params);
-    $edu     = $params->v('edu');
-    if (!$params->has('sex')) {
-        $profile = $params->v('profile');
-        $sex = $profile->isFemale();
-    } else {
-        $sex = $params->b('sex');
-    }
-    return education_fmt($edu->school_short, $edu->school_url, $edu->degree_short, $edu->grad_year,
-                         $edu->field, $edu->program, $sex, $params->b('long'));
-}
-Platal::page()->register_function('education_fmt', '_education_fmt');
-
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>
diff --git a/plugins/function.display_education.php b/plugins/function.display_education.php
new file mode 100644 (file)
index 0000000..da0ea96
--- /dev/null
@@ -0,0 +1,85 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *  GNU General Public License for more details.                           *
+ *                                                                         *
+ *  You should have received a copy of the GNU General Public License      *
+ *  along with this program; if not, write to the Free Software            *
+ *  Foundation, Inc.,                                                      *
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
+ ***************************************************************************/
+
+
+function display_education($name, $url, $degree, $grad_year, $field, $program, $sexe, $long)
+{
+    $field = strtolower($field);
+    $txt = "";
+
+    if ($grad_year || $field || $program) {
+        $txt .= "<span title=\"(";
+        if ($program) {
+            $txt .= $program;
+            if ($grad_year || $field) {
+                $txt .= ", ";
+            }
+        }
+        if ($grad_year) {
+            if ($sexe) {
+                $txt .= "diplômée en $grad_year";
+            } else {
+                $txt .= "diplômé en $grad_year";
+            }
+            if ($field) {
+                $txt .= ", ";
+            }
+        }
+        if ($field) {
+            $txt .= "domaine : $field";
+        }
+        $txt .= ")\">";
+    }
+
+    if (($degree != "Lic.") || ($long)) {
+        if (($degree != "Ing.") && ($degree != "Dipl.")) {
+            $txt .= $degree;
+        }
+        if ($name) {
+            $txt .= ' ';
+        }
+        if ($url != '') {
+            $txt .= "<a href=\"$url\" onclick=\"return popup(this)\">$name</a>";
+        } else {
+            $txt .= $name;
+        }
+    }
+    $txt .= "</span>";
+
+    return $txt;
+}
+
+function smarty_function_display_education($params, &$smarty)
+{
+    $params  = new PlDict($params);
+    $edu     = $params->v('edu');
+    if (!$params->has('sex')) {
+        $profile = $params->v('profile');
+        $sex = $profile->isFemale();
+    } else {
+        $sex = $params->b('sex');
+    }
+    return display_education($edu->school_short, $edu->school_url, $edu->degree_short, $edu->grad_year,
+                         $edu->field, $edu->program, $sex, $params->b('long'));
+}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+?>
index 0640732..c4f0dfa 100644 (file)
@@ -64,7 +64,7 @@
       <img src='images/flags/{$nat}.gif' alt='{$nat}' height='11' title='{$nat}' />&nbsp;
       {/foreach}
       {$profile->promo()}{*
-      *}{iterate from=$profile->getExtraEducations(4) item=edu}, {education_fmt edu=$edu profile=$profile}{/iterate}{*
+      *}{iterate from=$profile->getExtraEducations(4) item=edu}, {display_education edu=$edu profile=$profile}{/iterate}{*
       *}{if $dead}, {"décédé"|sex:"décédée":$profile} le {$profile->deathdate|date_format}{/if}
     </div>
   </div>