Change sorting order on ML display to use sort_name.
[platal.git] / classes / profile.php
index b11e31d..6722784 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2011 Polytechnique.org                              *
+ *  Copyright (C) 2003-2014 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -134,6 +134,7 @@ class Profile implements PlExportable
         'yourself'        => 'Nom affiché',
         'freetext'        => 'Commentaire',
         'freetext_pub'    => 'Affichage du commentaire',
+        'axfreetext'      => 'Commentaire AX',
         'photo'           => 'Photographie',
         'photo_pub'       => 'Affichage de la photographie',
         'addresses'       => 'Adresses',
@@ -171,6 +172,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;
@@ -364,6 +372,11 @@ class Profile implements PlExportable
         return $this->short_name;
     }
 
+    public function sortName()
+    {
+        return $this->sort_name;
+    }
+
     public function firstName()
     {
         return $this->firstname_ordinary;
@@ -492,7 +505,7 @@ class Profile implements PlExportable
         }
 
         XDB::execute("UPDATE  profiles
-                         SET  cv = NULL, freetext = NULL, freetext_pub = 'private',
+                         SET  cv = NULL, freetext = NULL, freetext_pub = 'private', axfreetext = NULL,
                               medals_pub = 'private', alias_pub = 'hidden',
                               email_directory = NULL
                        WHERE  pid = {?}",
@@ -724,6 +737,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;
@@ -977,6 +1018,22 @@ class Profile implements PlExportable
         }
     }
 
+    /* Hobbies
+     */
+    public function getHobbies() {
+        if ($this->visibility->isVisible(Visibility::EXPORT_PRIVATE)) {
+            return XDB::fetchAllAssoc('type', 'SELECT  type, GROUP_CONCAT(text)
+                                         FROM  profile_hobby
+                                        WHERE  pid = {?}
+                                     GROUP BY  type', $this->id());
+        } else {
+            return XDB::fetchAllAssoc('type', 'SELECT  type, GROUP_CONCAT(text)
+                                         FROM  profile_hobby
+                                        WHERE  pub = \'public\' AND pid = {?}
+                                      GROUP BY type', $this->id());
+        }
+    }
+
     /* Medals
      */
     private $medals = null;
@@ -1085,7 +1142,7 @@ class Profile implements PlExportable
                                      IF (ppn.firstname_ordinary = \'\', ppn.firstname_main, ppn.firstname_ordinary) AS firstname_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,
+                                     pd.directory_name, pd.public_name, pd.private_name, pd.sort_name,
                                      IF (pp.pub >= {?}, pp.display_tel, NULL) AS mobile,
                                      (ph.pub >= {?} AND ph.attach IS NOT NULL) AS has_photo, ph.pub as photo_pub,
                                      ph.x AS photo_width, ph.y AS photo_height,
@@ -1469,5 +1526,5 @@ class ProfileIterator implements PlIterator
     }
 }
 
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
 ?>