Add UserFilter::getUser(), UserFilter::getProfile() to get a single user/profile.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 27 Feb 2010 20:54:23 +0000 (21:54 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 27 Feb 2010 20:54:23 +0000 (21:54 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/userfilter.php

index 63157e5..5a6e645 100644 (file)
@@ -1666,17 +1666,47 @@ class UserFilter extends PlFilter
         return $this->getUIDList(null, $limit);
     }
 
+    public function getUID($pos = 0)
+    {
+        $uids =$this->getUIDList(null, new PlFilter(1, $pos));
+        if (count($uids) == 0) {
+            return null;
+        } else {
+            return $uids[0];
+        }
+    }
+
     public function getPIDs($limit = null)
     {
         $limit = self::defaultLimit($limit);
         return $this->getPIDList(null, $limit);
     }
 
+    public function getPID($pos = 0)
+    {
+        $pids =$this->getPIDList(null, new PlFilter(1, $pos));
+        if (count($pids) == 0) {
+            return null;
+        } else {
+            return $pids[0];
+        }
+    }
+
     public function getUsers($limit = null)
     {
         return User::getBulkUsersWithUIDs($this->getUIDs($limit));
     }
 
+    public function getUser($pos = 0)
+    {
+        $uid = $this->getUID($pos);
+        if ($uid == null) {
+            return null;
+        } else {
+            return User::getWithUID($uid);
+        }
+    }
+
     public function iterUsers($limit = null)
     {
         return User::iterOverUIDs($this->getUIDs($limit));
@@ -1687,6 +1717,16 @@ class UserFilter extends PlFilter
         return Profile::getBulkProfilesWithPIDs($this->getPIDs($limit));
     }
 
+    public function getProfile($pos = 0)
+    {
+        $pid = $this->getPID($pos);
+        if ($pid == null) {
+            return null;
+        } else {
+            return Profile::get($pid);
+        }
+    }
+
     public function iterProfiles($limit = null)
     {
         return Profile::iterOverPIDs($this->getPIDs($limit));
@@ -1947,7 +1987,7 @@ class UserFilter extends PlFilter
     static public function assertGrade($grade)
     {
         if (!self::isGrade($grade)) {
-            Platal::page()->killError("Diplôme non valide");
+            Platal::page()->killError("Diplôme non valide: $grade");
         }
     }