Merge commit 'origin/fusionax' into account
[platal.git] / classes / userfilter.php
index a2e616e..ebe69f4 100644 (file)
@@ -161,6 +161,14 @@ class UFC_Or extends UFC_NChildren
     }
 }
 
+class UFC_Profile implements UserFilterCondition
+{
+    public function buildCondition(UserFilter &$uf)
+    {
+        return '$PID IS NOT NULL';
+    }
+}
+
 class UFC_Promo implements UserFilterCondition
 {
 
@@ -460,7 +468,7 @@ class UFC_WatchRegistration extends UFC_UserRelated
         if (count($uids) == 0) {
             return UserFilterCondition::COND_FALSE;
         } else {
-            return '$UID IN (' . implode(', ', $uids) . ')';
+            return '$UID IN ' . XDB::formatArray($uids);
         }
     }
 }
@@ -482,7 +490,7 @@ class UFC_WatchPromo extends UFC_UserRelated
         } else {
             $sube = $uf->addEducationFilter(true, $this->grade);
             $field = 'pe' . $sube . '.' . UserFilter::promoYear($this->grade);
-            return $field . ' IN (' . implode(', ', $promos) . ')';
+            return $field . ' IN ' . XDB::formatArray($promos);
         }
     }
 }
@@ -674,8 +682,8 @@ class UserFilter
             $where = $this->root->buildCondition($this);
             $joins = $this->buildJoins();
             $this->query = 'FROM  accounts AS a
-                      INNER JOIN  account_profiles AS ap ON (ap.uid = a.uid AND FIND_IN_SET(\'owner\', ap.perms))
-                      INNER JOIN  profiles AS p ON (p.pid = ap.pid)
+                       LEFT JOIN  account_profiles AS ap ON (ap.uid = a.uid AND FIND_IN_SET(\'owner\', ap.perms))
+                       LEFT JOIN  profiles AS p ON (p.pid = ap.pid)
                                ' . $joins . '
                            WHERE  (' . $where . ')';
         }
@@ -718,14 +726,14 @@ class UserFilter
         $limit = '';
         if (!is_null($count)) {
             if (!is_null($offset)) {
-                $limit = XDB::format('LIMIT {?}, {?}', $offset, $count);
+                $limit = XDB::format('LIMIT {?}, {?}', (int)$offset, (int)$count);
             } else {
-                $limit = XDB::format('LIMIT {?}', $count);
+                $limit = XDB::format('LIMIT {?}', (int)$count);
             }
         }
         $cond = '';
         if (!is_null($uids)) {
-            $cond = ' AND a.uid IN (' . implode(', ', $uids) . ')';
+            $cond = ' AND a.uid IN ' . XDB::formatArray($uids);
         }
         $fetched = XDB::fetchColumn('SELECT SQL_CALC_FOUND_ROWS  a.uid
                                     ' . $this->query . $cond . '
@@ -754,8 +762,13 @@ class UserFilter
         $table = array();
         $uids  = array();
         foreach ($users as $user) {
-            $uids[] = $user->id();
-            $table[$user->id()] = $user;
+            if ($user instanceof PlUser) {
+                $uid = $user->id();
+            } else {
+                $uid = $user;
+            }
+            $uids[] = $uid;
+            $table[$uid] = $user;
         }
         $fetched = $this->getUIDList($uids, $count, $offset);
         $output = array();
@@ -813,6 +826,16 @@ class UserFilter
         return new UserFilter(new UFC_And($min, $max));
     }
 
+    static public function sortByName()
+    {
+        return array(new UFO_Name(self::LASTNAME), new UFO_Name(self::FIRSTNAME));
+    }
+
+    static public function sortByPromo()
+    {
+        return array(new UFO_Promo(), new UFO_Name(self::LASTNAME), new UFO_Name(self::FIRSTNAME));
+    }
+
     static private function getDBSuffix($string)
     {
         return preg_replace('/[^a-z0-9]/i', '', $string);