Find corps field in profile educations when processing broken emails.
authorNicolas Iooss <nicolas.iooss_git@polytechnique.org>
Mon, 14 Oct 2013 17:19:36 +0000 (19:19 +0200)
committerNicolas Iooss <nicolas.iooss_git@polytechnique.org>
Mon, 14 Oct 2013 18:52:36 +0000 (20:52 +0200)
The process of the borken emails produces a CSV file with a "corps" field to help finding a working email address.
As $profile->getCorps() is often empty, this field can be field with the corps education found in $profile->getExtraEducations(), if it exists.

Signed-off-by: Nicolas Iooss <nicolas.iooss_git@polytechnique.org>
classes/profile.php
modules/email.php

index bb4d2bf..0f5eb73 100644 (file)
@@ -731,6 +731,34 @@ class Profile implements PlExportable
         return $this->corps;
     }
 
+    /**
+     * Retrieve the name of the corps which has been done.
+     *
+     * Note: this function first tries getCorps(), and if this field is blank
+     * tries to find an education which degree is "Corps".
+     *
+     * Returns an empty string if nothing has been found.
+     */
+    public function getCorpsName()
+    {
+        $corps = $this->getCorps();
+        if ($corps && $corps->current) {
+            $corpsList = DirEnum::getOptions(DirEnum::CURRENTCORPS);
+            return $corpsList[$corps->current];
+        }
+
+        foreach ($this->getExtraEducations() as $edu) {
+            if (!strcasecmp($edu->degree, 'Corps')) {
+                if ($edu->school_short) {
+                    return $edu->school_short;
+                } elseif ($edu->school) {
+                    return $edu->school;
+                }
+            }
+        }
+        return '';
+    }
+
     /** Networking
      */
     private $networks = null;
index 6402337..e7f1e28 100644 (file)
@@ -891,8 +891,7 @@ class EmailModule extends PLModule
                 $corpsList = DirEnum::getOptions(DirEnum::CURRENTCORPS);
                 foreach ($broken_user_list as $uid => $mails) {
                     $profile = Profile::get($uid);
-                    $corps = $profile->getCorps();
-                    $current_corps = ($corps && $corps->current) ? $corpsList[$corps->current] : '';
+                    $current_corps = $profile->getCorpsName();
                     $jobs = $profile->getJobs();
                     $companies = array();
                     foreach ($jobs as $job) {