Add DirEnum for corps/corpsranks
[platal.git] / include / googleapps.inc.php
index d107e5e..5cf6eb6 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2009 Polytechnique.org                              *
+ *  Copyright (C) 2003-2010 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -23,7 +23,7 @@
 function post_queue_u_create($job) {
     global $globals;
 
-    // Retrieves the user parameters (GoogleApps username and user_id).
+    // Retrieves the user parameters (GoogleApps username and uid).
     $parameters = json_decode($job['j_parameters'], true);
     $username = isset($parameters['username']) ? $parameters['username'] : null;
     if (!($user = User::getSilent($username))) {
@@ -107,6 +107,9 @@ class GoogleAppsAccount
     public $r_last_webmail;
     public $reporting_date;
 
+    // Nicknames (aliases) registered for that user, lazily loaded.
+    public $nicknames;
+
     // Pending requests in the gappsd job queue (cf. top note).
     public $pending_create;
     public $pending_delete;
@@ -260,6 +263,21 @@ class GoogleAppsAccount
         return $this->g_status == 'disabled';
     }
 
+    // Loads and returns the list of nicknames for the user.
+    public function nicknames()
+    {
+        if ($this->nicknames == null) {
+            $res = XDB::query(
+                "SELECT  g_nickname
+                   FROM  gapps_nicknames
+                  WHERE  g_account_name = {?}
+               ORDER BY  g_nickname",
+                $this->g_account_name);
+            $this->nicknames = $res->fetchColumn();
+        }
+        return $this->nicknames;
+    }
+
 
     // Changes the GoogleApps password.
     public function set_password($password) {
@@ -339,17 +357,7 @@ class GoogleAppsAccount
 
         if (!$this->pending_update_suspension) {
             if ($this->sync_password) {
-                $res = XDB::query(
-                    "SELECT  password
-                       FROM  accounts
-                      WHERE  uid = {?}", $this->user->id());
-                $password = ($res->numRows() > 0 ? $res->fetchOneCell() : false);
-            } else {
-                $password = false;
-            }
-
-            if ($password) {
-                $this->create_queue_job('u_update', array('suspended' => false, 'password' => $password));
+                $this->create_queue_job('u_update', array('suspended' => false, 'password' => $this->user->password()));
             } else {
                 $this->create_queue_job('u_update', array('suspended' => false));
             }
@@ -368,13 +376,12 @@ class GoogleAppsAccount
 
         if (!$this->pending_create) {
             // Retrieves information on the new account.
-            // TODO: retreive first_name and last_name from the profile.
-            if (!$user->hasProfile()) {
-                $prenom = $user->displayName();
-                $nom    = $user->fullName();
+            if (!$this->user->hasProfile()) {
+                $prenom = $this->user->displayName();
+                $nom    = $this->user->fullName();
             } else {
-                $prenom = $user->profile()->firstName();
-                $nom    = $user->profile()->lastName();
+                $prenom = $this->user->profile()->firstName();
+                $nom    = $this->user->profile()->lastName();
             }
 
             // Adds an 'unprovisioned' entry in the gapps_accounts table.