DragonPrime - LoGD Resource Community
Welcome Guest
  • Good afternoon, Guest.
    Please log in, or register.
  • May 19, 2013, 04:38:44 PM
Home Forums News Links Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Login
 
 
Resource Pages
IRC Channels
Search

Pages: [1]   Go Down
  Print  
Author Topic: Preferences  (Read 250 times)
0 Members and 1 Guest are viewing this topic.
Aeo
Mod God
*****
Offline Offline

Posts: 1077


Doctor.. Who?


View Profile WWW
« on: September 05, 2012, 03:45:30 PM »

How might I go about getting a player's preferences to order themself alphabetically? After --

Code:
$form = array_merge($form, $msettings);
$prefs = array_merge($prefs, $mdata);

-- And before --

Code:
$info = showform($form,$prefs);

-- I tried adding in --

Code:
asort($form);
asort($prefs);

-- But while that may sort the headers into alphabetical order, it kinda just screws things up, and puts the preferences themselves under the wrong headers. o.o It's just so that player's can find their preferences easier. Anyone? ^^
Logged


Time Lords Online - A Doctor Who RPG! Open Now!
~ My Modules: PM me if you'd like me to code something! Smiley ~
Afkamm
Mod God
*****
Offline Offline

Posts: 1563

MarcTheSlayer


View Profile WWW
« Reply #1 on: September 05, 2012, 04:56:40 PM »

You need to understand how the data is organised inside the $form array. Though I would perform the sort on $msettings to leave the original $form intact.

There are the values that have 'title' in them. These are used as the tab name. Everything after this up until the next 'title' is displayed under this tab.

You need to remove everything in between the 'title' values so you end up with just an array of values with 'title' in them. This can no be sorted using asort(). Then reinsert the bits you removed back into the array, but after the correct 'title' values.

Sound easy? Smiley
Logged

Aeo
Mod God
*****
Offline Offline

Posts: 1077


Doctor.. Who?


View Profile WWW
« Reply #2 on: September 06, 2012, 05:48:32 AM »

Sound easy? Smiley

Not really. xD But I'll give it a shot and see what I come out with. Thanks for the help. ^^;

* EDIT:

For those who are interested, the code goes as thus:

-- FIND IN prefs.php:

Code:
<?php
$form 
array_merge($form$msettings);
$prefs array_merge($prefs$mdata);
?>

-- INSERT AFTER:
Code:
<?php
// BEGIN ALPHABETICAL ORDER
$forma $form;
$formkeys array_keys($forma);
for ($i 0$i count($forma); $i++){
$x $formkeys[$i];
if (is_array($forma[$x])) $forma[$x] = $forma[$x][0];
}
$rearranged = array();
$form2 explode("||",implode("||",$forma));
for ($i 0$i count($form2); $i++){
$form2[$i] = $form2[$i]."//".$formkeys[$i];
if (strstr($form2[$i],",title") || strstr($form2[$i],", title")){
$rearranged[$form2[$i]] = array();
$keys $form2[$i];
} else {
$rearranged[$keys][] = $form2[$i];
}
}
$rearrangedkeys array_keys($rearranged);
sort($rearrangedkeys);
$rearranged2 = array();
for ($i 0$i count($rearrangedkeys); $i++){
$x $rearrangedkeys[$i];
$rearranged2[$x] = $rearranged[$x];
$rearranged2[$x] = implode("||",$rearranged2[$x]);
$rearranged2[$x] = $rearrangedkeys[$i]."||".$rearranged2[$x];
}
$formb explode("||",implode("||",$rearranged2));
$formc = array();
for ($i 0$i count($formb); $i++){
$x explode("//",$formb[$i]);
$x2 $formkeys[$i];
$formc[$x[1]] = $x[0];
if (strstr($formc[$x2],"%s")) $formc[$x2] = $form[$x2];
}
$form $formc;
// END ALPHABETICAL ORDER
?>

It probably could be tidied up a bit, but that works perfectly for now.
« Last Edit: September 06, 2012, 01:47:47 PM by Aeolus » Logged


Time Lords Online - A Doctor Who RPG! Open Now!
~ My Modules: PM me if you'd like me to code something! Smiley ~
Pages: [1]   Go Up
  Print  
 
Jump to:  


*
DragonPrime Notices
Version 1.1.2 is the current supported version and is available for download.

Support Us
$100 raised this year
Your help is greatly appreciated!
Who's Online
26 Guests, 2 Users
wilsonbl1994, supermingo
DragonPrime LoGD
Recent Topics
Home Forums News Links Downloads Login Register Advanced Search