Port survey.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 13 Feb 2009 21:21:14 +0000 (22:21 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 13 Feb 2009 21:21:14 +0000 (22:21 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/user.php
include/notifs.inc.php
modules/profile.php
modules/survey/survey.inc.php
templates/carnet/panel.tpl
templates/carnet/rss.tpl

index ba271dd..8d06c94 100644 (file)
@@ -521,8 +521,8 @@ class User extends PlUser
             $table[$list['uid']] = User::getSilentWithValues(null, $list);
         }
         $users = array();
-        foreach ($uids as $uid) {
-            $users[] = $table[$uid];
+        foreach ($uids as $key=>$uid) {
+            $users[$key] = $table[$uid];
         }
         return $users;
     }
index 5e8d8ae..6601c1e 100644 (file)
@@ -21,6 +21,8 @@
 
 abstract class WatchOperation
 {
+    protected $date;
+
     public function getTitle($count = 0)
     {
         if ($count == 1) {
@@ -32,14 +34,15 @@ abstract class WatchOperation
 
     public function getCondition(PlUser &$user, $date)
     {
+        $this->date = $date;
         if (!$user->watch($this->flag)) {
             return new UFC_False();
         } else {
-            return $this->buildCondition($user, $date);
+            return $this->buildCondition($user);
         }
     }
 
-    abstract protected function buildCondition(PlUser &$user, $date);
+    abstract protected function buildCondition(PlUser &$user);
     abstract public function getOrder();
     abstract public function getDate(PlUser &$user);
 
@@ -71,9 +74,9 @@ class WatchProfileUpdate extends WatchOperation
                      $profile->id(), $field);
     }
 
-    protected function buildCondition(PlUser &$user, $date)
+    protected function buildCondition(PlUser &$user)
     {
-        return new UFC_And(new UFC_ProfileUpdated('>', $date),
+        return new UFC_And(new UFC_ProfileUpdated('>', $this->date),
                            new UFC_WatchContact($user));
     }
 
@@ -86,6 +89,41 @@ class WatchProfileUpdate extends WatchOperation
     {
         return $user->profile()->last_change;
     }
+
+    static private $descriptions = array('search_names' => 'L\'un de ses noms',
+                                         'freetext'     => 'Le texte libre',
+                                         'mobile'       => 'Son numéro de téléphone portable',
+                                         'nationalite'  => 'Sa nationalité',
+                                         'nationalite2' => 'Sa seconde nationalité',
+                                         'nationalite3' => 'Sa troisième nationalité',
+                                         'nick'         => 'Son surnom',
+                                         'networking'   => 'La liste de ses adresses de networking',
+                                         'edus'         => 'Ses formations',
+                                         'addresses'    => 'Ses adresses',
+                                         'section'      => 'Sa section sportive',
+                                         'binets'       => 'La liste de ses binets',
+                                         'medals'       => 'Ses décorations',
+                                         'cv'           => 'Son Curriculum Vitae',
+                                         'corps'        => 'Son Corps d\'État',
+                                         'jobs'         => 'Ses informations professionnelles',
+                                         'photo'        => 'Sa photographie');
+    public function getData(PlUser &$user)
+    {
+        $data = XDB::fetchColumn('SELECT  field
+                                    FROM  watch_profile
+                                   WHERE  uid = {?} AND ts > FROM_UNIXTIME({?}) AND field != \'\'
+                                ORDER BY  ts',
+                                 $user->id(), $this->date);
+        if (count($data) == 0) {
+            return null;
+        } else {
+            $text = array();
+            foreach ($data as $f) {
+                $text[] = self::$descriptions[$f];
+            }
+            return $text;
+        }
+    }
 }
 
 class WatchRegistration extends WatchOperation
@@ -93,9 +131,9 @@ class WatchRegistration extends WatchOperation
     public $flag  = 'registration';
     public $title = 'Inscription$s';
 
-    protected function buildCondition(PlUser &$user, $date)
+    protected function buildCondition(PlUser &$user)
     {
-        return new UFC_And(new UFC_Registered(false, '>', $date),
+        return new UFC_And(new UFC_Registered(false, '>', $this->date),
                            new UFC_Or(new UFC_WatchContact($user),
                                       new UFC_WatchPromo($user)));
     }
@@ -116,9 +154,9 @@ class WatchDeath extends WatchOperation
     public $flag  = 'death';
     public $title = 'Décès';
 
-    protected function buildCondition(PlUser &$user, $date)
+    protected function buildCondition(PlUser &$user)
     {
-        return new UFC_And(new UFC_Dead('>', $date, true),
+        return new UFC_And(new UFC_Dead('>', $this->date, true),
                            new UFC_Or(new UFC_WatchPromo($user),
                                       new UFC_WatchContact($user)));
     }
@@ -151,11 +189,11 @@ class WatchBirthday extends WatchOperation
     public $flag  = 'birthday';
     public $title = 'Anniversaire$s';
 
-    protected function buildCondition(PlUser &$user, $date)
+    protected function buildCondition(PlUser &$user)
     {
         return new UFC_And(new UFC_OR(new UFC_Birthday('=', time()),
                                       new UFC_And(new UFC_Birthday('<=', time() + self::WATCH_LIMIT),
-                                                  new UFC_Birthday('>', $date + self::WATCH_LIMIT))),
+                                                  new UFC_Birthday('>', $this->date + self::WATCH_LIMIT))),
                            new UFC_Or(new UFC_WatchPromo($user),
                                       new UFC_WatchContact($user)));
     }
index 72f81a6..c77b67e 100644 (file)
@@ -366,16 +366,6 @@ class ProfileModule extends PLModule
             }
         }
 
-        // AX Synchronization
-        require_once 'synchro_ax.inc.php';
-        if (is_ax_key_missing()) {
-            $page->assign('no_private_key', true);
-        }
-        if (Env::v('synchro_ax') == 'confirm' && !is_ax_key_missing()) {
-            ax_synchronize(S::user()->login(), S::v('uid'));
-            $page->trigSuccess('Ton profil a été synchronisé avec celui du site polytechniciens.com');
-        }
-
         // Build the page
         $page->addJsLink('ajax.js');
         $page->addJsLink('education.js');
index c50cc12..5d5087a 100644 (file)
@@ -189,16 +189,11 @@ class Survey
         $nbf = count($line);
         $users = array();
         if ($this->isMode(self::MODE_XIDENT)) { // if the mode is non anonymous
-            $sql = 'SELECT v.id AS vid, a.nom, a.prenom, a.promo
-                      FROM survey_votes AS v
-                INNER JOIN auth_user_md5 AS a
-                        ON a.user_id=v.user_id
-                     WHERE v.survey_id={?}
-                  ORDER BY vid ASC;';
-            $res = XDB::iterator($sql, $this->id); // retrieves all users data
-            for ($u = $res->next(); $u != null; $u = $res->next()) {
-                $users[$u['vid']] = array('nom' => $u['nom'], 'prenom' => $u['prenom'], 'promo' => $u['promo']);
-            }
+            $users = User::getBulkUsersWithUIDs(XDB::fetchAllAssoc('vid', 'SELECT  v.id AS vid, v.user_id
+                                                                             FROM  survey_votes AS v
+                                                                            WHERE  v.survey_id = {?}
+                                                                         ORDER BY  vid ASC',
+                                                                    $this->id));
         }
         $sql = 'SELECT v.id AS vid, a.question_id AS qid, a.answer AS answer
                   FROM survey_votes AS v
@@ -207,20 +202,19 @@ class Survey
                  WHERE v.survey_id={?}
               ORDER BY vid ASC, qid ASC, answer ASC;';
         $res = XDB::iterator($sql, $this->id); // retrieves all answers from database
-        $cur = $res->next();
         $vid = -1;
         $vid_ = 0;
-        while ($cur != null) {
+        while (($cur = $res->next()) != null) {
             if ($vid != $cur['vid']) { // if the vote id changes, then starts a new line
                 fputcsv($csv, $line, $sep, $enc); // stores the former line into $csv_output
                 $vid = $cur['vid'];
                 $line = array_fill(0, $nbf, ''); // creates an array full of empty string
                 $line[0] = $vid_; // the first field is a 'clean' vote id (not the one stored in database)
                 if ($this->isMode(self::MODE_XIDENT)) { // if the mode is non anonymous
-                    if (array_key_exists($vid, $users) && is_array($users[$vid])) { // and if the user data can be found
-                        $line[1] = $users[$vid]['nom']; // adds the user data (in the first fields of the line)
-                        $line[2] = $users[$vid]['prenom'];
-                        $line[3] = $users[$vid]['promo'];
+                    if (array_key_exists($vid, $users)) { // and if the user data can be found
+                        $line[1] = $users[$vid]->lastName(); // adds the user data (in the first fields of the line)
+                        $line[2] = $users[$vid]->firstName();;
+                        $line[3] = $users[$vid]->promo();
                     }
                 }
                 $vid_++;
@@ -239,7 +233,6 @@ class Survey
                 }
                 $line[$fid] .= $a; // adds the current answer to the correct field
             }
-            $cur = $res->next(); // gets next answer
         }
         fputcsv($csv, $line, $sep, $enc); // stores the last line into $csv_output
         return $csv_output;
index 3ba7edb..167432f 100644 (file)
@@ -61,6 +61,14 @@ Il faut pour cela se rendre sur la page de <a href='carnet/notifs'>configuration
       {if $cat.operation->seen($user,$smarty.session.watch_last)}<strong>{/if}
       {profile user=$user promo=true}
       {if $cat.operation->seen($user,$smarty.session.watch_last)}</strong>{/if}
+      {assign var=data value=$cat.operation->getData($user)}
+      {if $data}
+      <ul>
+        {foreach from=$data item=a}
+        <li>{$a}</li>
+        {/foreach}
+      </ul>
+      {/if}
     </li>
     {/foreach}
   </ul>
index 6e3984a..0630157 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-{if $article->data}{profile user=$article->user promo=false link=false} a mis à jours les données suivantes&nbsp;:<br />{$article->data}<br />{/if}
+{if $article->data}
+<p>{profile user=$article->user promo=false link=false} a mis à jours les données suivantes&nbsp;:</p>
+<ul>
+{foreach from=$article->data item=f}
+  <li>{$f}</li>
+{/foreach}
+</ul>
+{/if}
 {if !$article->contact and !$article->dead}
 <a href="{#globals.baseurl#}/carnet/contacts?action=ajouter&amp;user={$article->hruid}&amp;token={$rss_hash}">
   {icon name=add title="Ajouter" full=true} Ajouter &agrave; mes contacts