Add Profile->displayEmail()
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Mon, 22 Mar 2010 21:53:11 +0000 (22:53 +0100)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Mon, 22 Mar 2010 22:02:52 +0000 (23:02 +0100)
    Either fetches it from the owner User, of from the
    profile.email_directory field in the DB

Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
classes/profile.php

index da54907..96cc71e 100644 (file)
@@ -151,6 +151,8 @@ class Profile
 
     private $pid;
     private $hrpid;
+    private $owner;
+    private $owner_fetched = false;
     private $data = array();
 
     private $visibility = null;
@@ -174,6 +176,15 @@ class Profile
         return $this->hrpid;
     }
 
+    public function owner()
+    {
+        if ($this->owner == null && !$this->owner_fetched) {
+            $this->owner_fetched = true;
+            $this->owner = User::getSilent($this);
+        }
+        return $this->owner;
+    }
+
     public function promo()
     {
         return $this->promo;
@@ -247,6 +258,16 @@ class Profile
         return ($this->deathdate != null);
     }
 
+    public function displayEmail()
+    {
+        $o = $this->owner();
+        if ($o != null) {
+            return $o->bestEmail();
+        } else {
+            return $this->email_directory;
+        }
+    }
+
     public function data()
     {
         $this->first_name;
@@ -628,11 +649,6 @@ class Profile
         return $this->medals->medals;
     }
 
-    public function owner()
-    {
-        return User::getSilent($this);
-    }
-
     public function compareNames($firstname, $lastname)
     {
         $_lastname  = mb_strtoupper($this->lastName());