Find corps field in profile educations when processing broken emails.
[platal.git] / classes / profile.php
index 104702b..0f5eb73 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2011 Polytechnique.org                              *
+ *  Copyright (C) 2003-2013 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -171,6 +171,13 @@ class Profile implements PlExportable
         $this->visibility = $visibility;
     }
 
+    public function __destruct()
+    {
+        // Need to delete objects allocated by the profile
+        // http://www.php.net/manual/en/function.unset.php#98692
+        unset($this->owner);
+    }
+
     public function id()
     {
         return $this->pid;
@@ -724,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;
@@ -1227,18 +1262,19 @@ class Profile implements PlExportable
      */
     public static function getAccountEquivalentName($name)
     {
-        switch ($name)
-        {
-        case self::DN_DIRECTORY:
-        case self::DN_SORT:
+        switch ($name) {
+          case self::DN_DIRECTORY:
             return 'directory_name';
-        case self::DN_FULL:
-        case self::DN_PUBLIC:
+          case self::DN_SORT:
+            return 'sort_name';
+          case self::DN_FULL:
+          case self::DN_PUBLIC:
+          case self::DN_PRIVATE:
+          case self::DN_SHORT:
             return 'full_name';
-        case self::DN_PRIVATE:
-        case self::DN_SHORT:
-        case self::DN_YOURSELF:
-        default:
+          case self::DN_YOURSELF:
+            return 'display_name';
+          default:
             return 'display_name';
         }
     }