Support of networking in profile.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 5 Mar 2009 21:33:42 +0000 (22:33 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 5 Mar 2009 21:33:42 +0000 (22:33 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/profile.php
templates/include/minifiche.tpl

index 22f4833..d68c959 100644 (file)
@@ -45,6 +45,11 @@ class Profile
     const JOBS_FINISHED      = 0x004000;
     const JOBS_CURRENT       = 0x008000;
 
+    const NETWORKING_ALL     = 0x000000;
+    const NETWORKING_WEB     = 0x010000;
+    const NETWORKING_IM      = 0x020000;
+    const NETWORKING_SOCIAL  = 0x040000;
+
     private $pid;
     private $hrpid;
     private $data = array();
@@ -247,6 +252,40 @@ class Profile
     }
 
 
+    /** Networking
+     */
+
+    public function getNetworking($flags, $limit = null)
+    {
+        $where = XDB::format('pn.uid = {?}', $this->id());
+        if ($flags & self::NETWORKING_WEB) {
+            $where .= ' AND pn.network_type = 0'; // XXX hardcoded reference to web site index
+        }
+        if ($this->visibility) {
+            $where .= ' AND pn.pub IN ' . XDB::formatArray($this->visibility);
+        }
+        $limit = is_null($limit) ? '' : XDB::format('LIMIT {?}', (int)$limit);
+        return XDB::iterator('SELECT  pne.name, pne.icon,
+                                      IF (LENGTH(pne.link) > 0, REPLACE(pne.link, \'%s\', pn.address),
+                                                                pn.address) AS address
+                                FROM  profile_networking AS pn
+                          INNER JOIN  profile_networking_enum AS pne ON (pn.network_type = pne.network_type)
+                               WHERE  ' . $where . '
+                            ORDER BY  pn.network_type, pn.nwid
+                                      ' . $limit);
+    }
+
+    public function getWebSite()
+    {
+        $site = $this->getNetworking(self::NETWORKING_WEB, 1);
+        if ($site->total() != 1) {
+            return null;
+        }
+        $site = $site->next();
+        return $site['address'];
+    }
+
+
     public function owner()
     {
         return User::getSilent($this);
index 57a1ab3..4135d20 100644 (file)
   <div class="long">
   {if !$dead}
     {assign var=address value=$profile->getMainAddress()}
-    {if $c.web || $profile->mobile || $address.country || $c.entreprise || (!$dead && !$registered)}
+    {assign var=web     value=$profile->getWebSite()}
+    {if $web || $profile->mobile || $address.country || $c.entreprise || (!$dead && !$registered)}
     <table cellspacing="0" cellpadding="0">
-      {if $c.web}
+      {if $web}
       <tr>
         <td class="lt">Page web&nbsp;:</td>
-        <td class="rt"><a href="{$c.web}">{$c.web}</a></td>
+        <td class="rt"><a href="{$web}">{$web}</a></td>
       </tr>
       {/if}
       {if $address.country}