Fixes payment transactions addition
[platal.git] / classes / profile.php
index 3f28654..bb4d2bf 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;
@@ -321,6 +328,16 @@ class Profile implements PlExportable
         }
     }
 
+    // Returns younger/older promotion year for a given education.
+    static public function extremePromotions($education)
+    {
+        return XDB::fetchOneRow("SELECT  MIN(pe.promo_year) AS min, MAX(pe.promo_year) AS max
+                                     FROM  profile_education             AS pe
+                               INNER JOIN  profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
+                                    WHERE  pede.degree = {?} AND FIND_IN_SET('primary', pe.flags)",
+                                  $education);
+    }
+
     /** Print a name with the given formatting:
      * %s = • for women
      * %f = firstname
@@ -942,6 +959,19 @@ class Profile implements PlExportable
             return array();
         }
     }
+
+    public function getFullBinets()
+    {
+        if ($this->visibility->isVisible(Visibility::EXPORT_PRIVATE)) {
+            return XDB::fetchAllAssoc('SELECT  binet_id, text, url
+                                         FROM  profile_binets AS pb
+                                    LEFT JOIN  profile_binet_enum AS pbe ON (pbe.id = pb.binet_id)
+                                        WHERE  pid = {?}', $this->id());
+        } else {
+            return array();
+        }
+    }
+
     public function getBinetsNames()
     {
         if ($this->visibility->isVisible(Visibility::EXPORT_PRIVATE)) {
@@ -1060,7 +1090,7 @@ class Profile implements PlExportable
                                      IF ({?}, pse.text, NULL) AS section,
                                      ppn.firstname_main AS firstname, ppn.lastname_main AS lastname, IF ({?}, pn.name, NULL) AS nickname,
                                      IF (ppn.firstname_ordinary = \'\', ppn.firstname_main, ppn.firstname_ordinary) AS firstname_ordinary,
-                                     IF (ppn.lastname_ordinary = \'\', ppn.firstname_main, ppn.lastname_ordinary) AS lastname_ordinary,
+                                     IF (ppn.lastname_ordinary = \'\', ppn.lastname_main, ppn.lastname_ordinary) AS lastname_ordinary,
                                      pd.yourself, pd.promo, pd.short_name, pd.public_name AS full_name,
                                      pd.directory_name, pd.public_name, pd.private_name,
                                      IF (pp.pub >= {?}, pp.display_tel, NULL) AS mobile,
@@ -1204,18 +1234,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';
         }
     }