Fix networking with new network_type issues introduced by previous commit
authorPascal Corpet <pascal.corpet@m4x.org>
Tue, 22 Jun 2010 22:40:41 +0000 (00:40 +0200)
committerPascal Corpet <pascal.corpet@m4x.org>
Tue, 22 Jun 2010 22:40:41 +0000 (00:40 +0200)
classes/direnum.php
classes/userfilter.php
include/profilefields.inc.php
modules/profile.php
modules/profile/general.inc.php
templates/profile/profile.tpl

index 90fb331..e0b485d 100644 (file)
@@ -617,12 +617,12 @@ class DE_JobDescription extends DirEnumeration
 // {{{ class DE_Networking
 class DE_Networking extends DirEnumeration
 {
-    protected $idfield  = 'profile_networking_enum.network_type';
+    protected $idfield  = 'profile_networking_enum.nwid';
     protected $valfield = 'profile_networking_enum.name';
     protected $from     = 'profile_networking_enum';
 
 
-    protected $ac_join   = 'INNER JOIN profile_networking ON (profile_networking.network_type = profile_networking_enum.network_type)';
+    protected $ac_join   = 'INNER JOIN profile_networking ON (profile_networking.nwid = profile_networking_enum.nwid)';
     protected $ac_unique = 'profile_networking.pid';
 }
 // }}}
index 18bdadd..035ee25 100644 (file)
@@ -1048,7 +1048,7 @@ class UFC_Networking implements UserFilterCondition
         $conds = array();
         $conds[] = $sub . '.address ' . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->value);
         if ($this->type != -1) {
-            $conds[] = $sub . '.network_type = ' . XDB::format('{?}', $this->type);
+            $conds[] = $sub . '.nwid = ' . XDB::format('{?}', $this->type);
         }
         return implode(' AND ', $conds);
     }
index fc18b11..d2de132 100644 (file)
@@ -477,7 +477,7 @@ class ProfileNetworking extends ProfileField
 
     public static function fetchData(array $pids, ProfileVisibility $visibility)
     {
-        $data = XDB::iterator('SELECT  pid, id, address, pne.network_type, pne.filter, pne.link
+        $data = XDB::iterator('SELECT  pid, id, address, pne.nwid, pne.network_type, pne.link, pne.name
                                  FROM  profile_networking AS pn
                             LEFT JOIN  profile_networking_enum AS pne USING(nwid)
                                 WHERE  pid IN {?} AND pub IN {?}
@@ -502,7 +502,7 @@ class ProfileNetworking extends ProfileField
                 ($flags & Profile::NETWORKING_ALL)) {
                 $nws[$id] = $nw;
                 ++$nb;
-                if ($nb >= $limit) {
+                if (isset($limit) && $nb >= $limit) {
                     break;
                 }
             }
index dbfc7d2..beb6c5d 100644 (file)
@@ -134,7 +134,7 @@ class ProfileModule extends PLModule
     {
         $res = XDB::query("SELECT  icon
                              FROM  profile_networking_enum
-                            WHERE  network_type = {?}",
+                            WHERE  nwid = {?}",
                           $mid);
         $img  = dirname(__FILE__) . '/../htdocs/images/networking/' . $res->fetchOneCell();
         $type = mime_content_type($img);
@@ -758,7 +758,7 @@ class ProfileModule extends PLModule
     function handler_admin_networking(&$page, $action = 'list', $id = null) {
         $page->assign('xorg_title', 'Polytechnique.org - Administration - Networking');
         $page->assign('title', 'Gestion des types de networking');
-        $table_editor = new PLTableEditor('admin/networking', 'profile_networking_enum', 'network_type');
+        $table_editor = new PLTableEditor('admin/networking', 'profile_networking_enum', 'nwid');
         $table_editor->describe('name', 'intitulĂ©', true);
         $table_editor->describe('icon', 'nom de l\'icĂ´ne', false);
         $table_editor->describe('filter', 'filtre', true);
index c7f780b..e80a593 100644 (file)
@@ -334,16 +334,15 @@ class ProfileSettingNetworking implements ProfileSetting
     public function value(ProfilePage &$page, $field, $value, &$success)
     {
         if (is_null($value)) {
-            $value = XDB::fetchAllAssoc("SELECT  n.address, n.network_type AS type, n.pub, m.name
+            $value = XDB::fetchAllAssoc("SELECT  n.address, n.pub, n.nwid AS type
                                            FROM  profile_networking AS n
-                                     INNER JOIN  profile_networking_enum AS m ON (n.network_type = m.network_type)
                                           WHERE  n.pid = {?}",
                                          $page->pid());
         }
         if (!is_array($value)) {
             $value = array();
         }
-        $filters = XDB::fetchAllAssoc('type', 'SELECT  filter, network_type AS type
+        $filters = XDB::fetchAllAssoc('type', 'SELECT  filter, nwid AS type, name
                                                  FROM  profile_networking_enum;');
         $success = true;
         foreach($value as $i=>&$network) {
@@ -356,11 +355,12 @@ class ProfileSettingNetworking implements ProfileSetting
                 $network['error'] = false;
                 $network['pub'] = $this->pub->value($page, 'pub', $network['pub'], $s);
                 $s = true;
-                if ($filters[$network['type']] == 'web') {
+                $network['name'] = $filters[$network['type']]['name'];
+                if ($filters[$network['type']]['filter'] == 'web') {
                     $network['address'] = $this->web->value($page, 'address', $network['address'], $s);
-                } elseif ($filters[$network['type']] == 'email') {
+                } elseif ($filters[$network['type']]['filter'] == 'email') {
                     $network['address'] = $this->email->value($page, 'address', $network['address'], $s);
-                } elseif ($filters[$network['type']] == 'number') {
+                } elseif ($filters[$network['type']]['filter'] == 'number') {
                     $network['address'] = $this->number->value($page, 'address', $network['address'], $s);
                 }
                 if (!$s) {
@@ -382,7 +382,7 @@ class ProfileSettingNetworking implements ProfileSetting
         }
         $insert = array();
         foreach ($value as $id=>$network) {
-            XDB::execute("INSERT INTO  profile_networking (pid, nwid, network_type, address, pub)
+            XDB::execute("INSERT INTO  profile_networking (pid, id, nwid, address, pub)
                                VALUES  ({?}, {?}, {?}, {?}, {?})",
                          $page->pid(), $id, $network['type'], $network['address'], $network['pub']);
         }
@@ -600,7 +600,7 @@ class ProfileSettingGeneral extends ProfilePage
         require_once "emails.combobox.inc.php";
         fill_email_combobox($page, $this->owner, $this->profile);
 
-        $res = XDB::query("SELECT  nw.network_type AS type, nw.name
+        $res = XDB::query("SELECT  nw.nwid AS type, nw.name
                              FROM  profile_networking_enum AS nw
                          ORDER BY  name");
         $page->assign('network_list', $res->fetchAllAssoc());
index 411a59f..1c8c058 100644 (file)
@@ -66,11 +66,9 @@ function chgMainWinLoc(strPage)
     {if count($networking) > 0}
       <h2>Sur le web...</h2>
       {foreach from=$networking item=network}
-        <img style="width: auto; padding: 0" src="profile/networking/{$network.network_type}" alt="{$network.name}" title="{$network.name}"/>
-        {if $network.filter == 'web'}
-          <a href="{$network.address}">{$network.address}</a>
-        {elseif $network.link != ''}
-          <a href="{$network.link}">{$network.address}</a>
+        <img style="width: auto; padding: 0" src="profile/networking/{$network.nwid}" alt="{$network.name}" title="{$network.name}"/>
+        {if $network.link}
+          <a href="{$network.link|replace:'%s':$network.address}">{$network.address}</a>
         {else}
           {$network.address}
         {/if}