Clear mentor entry of the user when is expertise is empty.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Wed, 4 Jun 2008 19:32:56 +0000 (21:32 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Wed, 4 Jun 2008 19:33:30 +0000 (21:33 +0200)
(Closes #840)

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
modules/profile/mentor.inc.php

index d1509a8..64b1de7 100644 (file)
@@ -136,9 +136,18 @@ class ProfileMentor extends ProfilePage
     protected function _saveData()
     {
         if ($this->changed['expertise']) {
-            XDB::execute("REPLACE INTO  mentor (uid, expertise)
-                                VALUES  ({?}, {?})",
-                         S::i('uid'), $this->values['expertise']);
+            $expertise = trim($this->values['expertise']);
+            if (empty($expertise)) {
+                XDB::execute("DELETE FROM  mentor
+                                    WHERE  uid = {?}",
+                             S::i('uid'));
+                $this->values['expertise'] = null;
+            } else {
+                XDB::execute("REPLACE INTO  mentor (uid, expertise)
+                                    VALUES  ({?}, {?})",
+                             S::i('uid'), $expertise);
+                $this->values['expertise'] = $expertise;
+            }
         }
     }