From 043b104b5cee2d3eb5777a1ed129288a6ca5ca8f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Sun, 24 Jan 2010 13:35:30 +0100 Subject: [PATCH] Add support for returning Profiles instead of Users MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- classes/userfilter.php | 73 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/classes/userfilter.php b/classes/userfilter.php index 098abc6..64f310b 100644 --- a/classes/userfilter.php +++ b/classes/userfilter.php @@ -1298,6 +1298,24 @@ class UserFilter extends PlFilter return $fetched; } + private function getPIDList($pids = null, PlLimit &$limit) + { + $this->requireProfiles(); + $this->buildQuery(); + $lim = $limit->getSql(); + $cond = ''; + if (!is_null($pids)) { + $cond = ' AND p.pid IN ' . XDB::formatArray($pids); + } + $fetched = XDB::fetchColumn('SELECT SQL_CALC_FOUND_ROWS p.pid + ' . $this->query . $cond . ' + GROUP BY p.pid + ' . $this->orderby . ' + ' . $lim); + $this->lastcount = (int)XDB::fetchOneCell('SELECT FOUND_ROWS()'); + return $fetched; + } + /** Check that the user match the given rule. */ public function checkUser(PlUser &$user) @@ -1309,10 +1327,28 @@ class UserFilter extends PlFilter return $count == 1; } - /** Filter a list of user to extract the users matching the rule. + /** Check that the profile match the given rule. + */ + public function checkProfile(Profile &$profile) + { + $this->requireProfiles(); + $this->buildQuery(); + $count = (int)XDB::fetchOneCell('SELECT COUNT(*) + ' . $this->query . XDB::format(' AND p.pid = {?}', $profile->id())); + return $count == 1; + } + + /** Default filter is on users */ public function filter(array $users, PlLimit &$limit) { + return $this->filterUsers($users, $limit); + } + + /** Filter a list of users to extract the users matching the rule. + */ + public function filterUsers(array $users, PlLimit &$limit) + { $this->requireAccounts(); $this->buildQuery(); $table = array(); @@ -1334,16 +1370,51 @@ class UserFilter extends PlFilter return $output; } + /** Filter a list of profiles to extract the users matching the rule. + */ + public function filterProfiles(array $profiles, PlLimit &$limit) + { + $this->requireProfiles(); + $this->buildQuery(); + $table = array(); + $pids = array(); + foreach ($profiles as $profile) { + if ($profile instanceof Profile) { + $pid = $profile->id(); + } else { + $pid = $profile; + } + $pids[] = $pid; + $table[$pid] = $profile; + } + $fetched = $this->getPIDList($pids, $limit); + $output = array(); + foreach ($fetched as $pid) { + $output[] = $table[$pid]; + } + return $output; + } + public function getUIDs(PlLimit &$limit) { return $this->getUIDList(null, $limit); } + public function getPIDs(PlLimit &$limit) + { + return $this->getPIDList(null, $limit); + } + public function getUsers(PlLimit &$limit) { return User::getBulkUsersWithUIDs($this->getUIDs($limit)); } + public function getProfiles(PlLimit &$limit) + { + return Profile::getBulkProfilesWithPIDs($this->getPIDs($limit)); + } + public function get(PlLimit &$limit) { return $this->getUsers($limit); -- 2.1.4