/** * Select Users For Global Ranking. * @param int $count * @param int $from * @return array */ private function selectUsers($count, $from) { $db = gdo_db(); $count = (int) $count; $from = (int) $from; $regat = GDO::table('WC_RegAt')->getTableName(); $users = GDO::table('GWF_User')->getTableName(); $query = "SELECT user_id,user_name,user_level,SUM(regat_score) AS lts, COUNT(regat_score) AS nlinks, regat_langid,user_countryid FROM {$regat} AS B JOIN (SELECT user_id,user_name,user_level,user_countryid FROM {$users} WHERE user_options&0x10000000=0 ORDER BY user_level DESC, user_id ASC LIMIT {$from}, {$count}) AS C ON user_id=regat_uid GROUP by user_id,regat_langid ORDER BY user_level DESC, user_id ASC"; $back = array(); if (false === ($result = $db->queryRead($query))) { return $back; } $current = false; while (false !== ($row = $db->fetchAssoc($result))) { if ($current === false) { $current = new GWF_User($row); $current->setVar('nlinks', 0); $back[] = $current; } elseif ($current->getVar('user_id') !== $row['user_id']) { if (count($back) === $count) { break; } $current = new GWF_User($row); $current->setVar('nlinks', 0); $back[] = $current; } $current->setVar('grank_' . $row['regat_langid'], $row['lts']); $current->setVar('nlinks', $current->getVar('nlinks') + $row['nlinks']); // var_dump($current->getGDOData()); } $db->free($result); // var_dump($back); return $back; }
private function getUserStuff(array $row, GDO_Database $db, $bits) { $back = new GWF_User($row); $regat = GWF_TABLE_PREFIX . 'wc_regat'; $uid = $row['user_id']; $query = "SELECT regat_sid, regat_solved FROM {$regat} WHERE regat_uid={$uid} AND regat_tagbits&{$bits} AND regat_options&4=0"; if (false === ($result = $db->queryRead($query))) { return $back; } while (false !== ($row = $db->fetchRow($result))) { $back->setVar('site_' . $row[0], $row[1]); } $db->free($result); return $back; }