View Full Version : Reorder User Ranks
PGAmerica
12-05-2008, 02:32 PM
I have added about a dozen user ranks in my acp and they are working fine. However, on a user's post, when it shows the ranks, it does not list them in the order I have them entered. The way I have it setup, a user can have multiple rankings (eg. Administrator, over 300 posts, etc).
What determines the order the ranks are shown in?
How do I force the system to list ranks in a particular order?
Is there a mod out there that allows me to do this? I searched, but did not find anything.
PGAmerica
12-08-2008, 03:16 PM
Anybody? Anybody?
Lynne
12-08-2008, 03:33 PM
I think you need to actually change the code. It looks like this is done in includes/functions_ranks.php at the very bottom where it says "Begin Build Ranks PHP Code function"
PGAmerica
12-08-2008, 03:53 PM
The problem is that I am not a programmer. I have no idea how to do that. Is there anybody that can give me the "find this, replace with this" instructions?
Lynne
12-08-2008, 04:09 PM
Sorry, I can't tell you exactly. I'm a trial and error coder and I don't have enough ranks on my test site to be able to test this out myself.
PGAmerica
12-08-2008, 04:24 PM
Well, if it is a test site, can't you just make more ranks? You can also use my test site if you wish.
In the function is the line that says "ORDER BY ranks.usergroupid DESC, minposts DESC". Obviously, it is displaying the ranks by usergroup id. However, not being a programmer, I am just guessing here, but if we add a new column to the ranks table in the database and then connect it to the ranks area of the acp for "display order" we can then change that line to "ORDER BY ranks.displayorderid DESC, minposts DESC" or something like this.
Am I right?
For simplicity sake, can I change the line to something that just replaces "usergroupid" with the rankid? or even list the rank ids in the order I want them displayed?
Lynne
12-08-2008, 04:34 PM
The ranks table has a field called rankid. So yes, you can order by rank.rankid . You can always try that and see. If it doesn't work, then you go back to default (just keep a copy). I think after you change it in the code, you will need to go to the Ranks area in the Admin CP and Save something to get it to rebuild the ranks list.
If you were to write a modification for this, you would probably want to add a column for order. Then you could order by rank.order.
And I don't want to add more ranks to my test site because I'm trying to keep it as close to my live site as possible since I want to make the big jump from 3.6 to 3.8 as soon as it goes Gold.
PGAmerica
12-08-2008, 04:43 PM
Well, knowing that I want to add a rank.order option in the acp and being able to actually do it are two different things. I will wait to see if anybody can do this for me.
Do you know the mysql command to add a column to an existing table?
Lynne
12-08-2008, 04:57 PM
I just add them in phpMyAdmin. But, I did write a product that I shared with someone and this is the query I used to add a new column to the thread table:
$db->query("ALTER TABLE " . TABLE_PREFIX . "thread ADD verify_status SMALLINT(5) UNSIGNED DEFAULT '0' NOT NULL");That was to add a new column of type smallint which is probably what you want. Default is '0' and it's not null.
If you go for this approach of adding a new 'order' column, don't forget you need to modify the /admincp/ranks.php page to include it on your User Rank page in the Admin CP
PGAmerica
12-08-2008, 05:37 PM
That looks like the command to add to a php file. What is the command I use in phpMyAdmin?
Lynne
12-08-2008, 05:41 PM
In phpMyAdmin you just go to the table and after it lists all the columns, it says:
Add 1 fields(s)
The 1 is in an input box. At End of Table is the default, click on Go and fill in the information.
I would strongly suggest you do this on your test site before you do it on a live site.
PGAmerica
12-08-2008, 05:58 PM
Got it and done. Thank you for your help. At least this way I can manually change the order, that is, until a hack is written.
--------------- Added 08 Dec 2008 at 13:12 ---------------
Well, I created a new column in my "ranks" table named "order_id". I then modified the "functions_ranks.php" file and changed the bottom section from
// #################### Begin Build Ranks PHP Code function ################
function &build_ranks()
{
global $vbulletin;
$ranks = $vbulletin->db->query_read_slave("
SELECT ranklevel AS l, minposts AS m, rankimg AS i, type AS t, stack AS s, display AS d, ranks.usergroupid AS u
FROM " . TABLE_PREFIX . "ranks AS ranks
LEFT JOIN " . TABLE_PREFIX . "usergroup AS usergroup USING (usergroupid)
ORDER BY ranks.usergroupid DESC, minposts DESC
");
$rankarray = array();
while ($rank = $vbulletin->db->fetch_array($ranks))
{
$rankarray[] = $rank;
}
build_datastore('ranks', serialize($rankarray), 1);
return $rankarray;
}to
// #################### Begin Build Ranks PHP Code function ################
function &build_ranks()
{
global $vbulletin;
$ranks = $vbulletin->db->query_read_slave("
SELECT ranklevel AS l, minposts AS m, rankimg AS i, type AS t, stack AS s, display AS d, ranks.order_id AS u
FROM " . TABLE_PREFIX . "ranks AS ranks
LEFT JOIN " . TABLE_PREFIX . "usergroup AS usergroup USING (usergroupid)
ORDER BY ranks.order_id DESC, minposts DESC
");
$rankarray = array();
while ($rank = $vbulletin->db->fetch_array($ranks))
{
$rankarray[] = $rank;
}
build_datastore('ranks', serialize($rankarray), 1);
return $rankarray;
}I just replaced "ranks.usergroupid" with "ranks.order_id".
I went to the "Update Counters" area in the ACP and updated the titles and ranks. It is still displaying the same way.
Ideas?
PGAmerica
12-10-2008, 10:33 PM
Well, it turns out that when I made that minor change and added the new column to the database, it broke the ranking system. Everybody had ranks that were not their own. In other words, we suddenly had tons of people that showed rankings that are only earned from a specified amount of posts. There is no way they should have that rank. When I removed the DB column and undid the minor changes I made to the file, it all reverted to working properly.
I don't get it.
Ideas?
Lynne
12-10-2008, 10:37 PM
My guess is it's a datastore issue. You probably need to add the column to the rank array in order for it to get used. Look at ranks.php around line 174 where the array is assigned. I'll bet you 'broke' things by not adding the column in there and putting it all in there.
PGAmerica
12-10-2008, 10:50 PM
The rank array code looks like
$ranks = array(
'ranklevel' => 1,
'usergroupid' => -1,
'minposts' => 10,
'rankimg' => 'images/',
);
How do I add a reference to the new table column "order_id"?
All I did was order it by rankid. I added my ranks in a certain order so the rankid was all I needed.
$ranks = $vbulletin->db->query_read_slave("
SELECT ranklevel AS l, minposts AS m, rankimg AS i, type AS t, stack AS s, display AS d, ranks.usergroupid AS u
FROM " . TABLE_PREFIX . "ranks AS ranks
LEFT JOIN " . TABLE_PREFIX . "usergroup AS usergroup USING (usergroupid)
ORDER BY rankid DESC, minposts DESC
It doesn't show up immediately even if you update the ranks in the ACP. It took around 15-30 minutes for my ranks to reorder the way I wanted.
DragonBlade has found a solution.
https://vborg.vbsupport.ru/showthread.php?t=109292&page=2
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.