SimplePortal

Customization => Custom Coding => Topic started by: ♦ Ninja ZX-10RR ♦ on November 25, 2014, 06:23:19 AM

Title: Staff list order, once again
Post by: ♦ Ninja ZX-10RR ♦ on November 25, 2014, 06:23:19 AM
Hi all :) some of you might know me from sm.org, some might not.

So I have read all the documentation, I have read all the similar topics but I can't figure out the query I would need to sort the staff list by member id, I mean, not just order like member 1 will come before member 2, I mean that I would have to manually type EACH member id in the query. That would be the best thing to me as I have too many customizations and I can't possibly use the other queries that had been provided.
Thanks in advance :)

P.s. I beg you, I really do, please make the captcha easier or get rid of it... It's useless anyway, bots can easily read them nowadays :/
Title: Re: Staff list order, once again
Post by: ♦ Ninja ZX-10RR ♦ on November 27, 2014, 06:07:21 AM
Tiny bump please?
Title: Re: Staff list order, once again
Post by: [SiNaN] on November 28, 2014, 05:26:30 PM
This is difficult to get right with something simple, but here's the easiest that I came up with:

PortalBlocks.php

Code: (Find) [Select]
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$colorids[$row['id_member']] = $row['id_member'];

Code: (Replace) [Select]
$orderids = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$colorids[$row['id_member']] = $row['id_member'];
$orderids[$row['id_member']] = 100 + $row['id_member'];

Code: (Find) [Select]
$staff_list[$row['type'] . '-' . $row['id_member']] = array(
Code: (Replace) [Select]
$staff_list[$row['id_member']] = array(
Code: (Find) [Select]
ksort($staff_list);
Code: (Replace) [Select]
array_multisort($orderids, SORT_ASC, $staff_list);
Now with the changes above, all the members will be sorted by their member ids. If you want fine tuning, you can edit the $orderids array. For instance, if I wanted to have the member with the id of 5476 appear the first and member with the id of 128 to appear second, I would do this:

Code: (Find) [Select]
array_multisort($orderids, SORT_ASC, $staff_list);
Code: (Replace) [Select]
$orderids[5476] = 1;
$orderids[128] = 2;
array_multisort($orderids, SORT_ASC, $staff_list);

You can do pretty much whatever you want using array_multisort but it's not easy to get it right at first. You can have a look at the related section at the PHP Manual for that: http://php.net/array_multisort
Title: Re: Staff list order, once again
Post by: ♦ Ninja ZX-10RR ♦ on November 28, 2014, 05:30:48 PM
Oh jeez this is seriously a mess. Thanks I will try this when I will have some time and report you back, I hope I will be able to get that right with all those edits >_<
Many thanks again.
Title: Re: Staff list order, once again
Post by: [SiNaN] on November 28, 2014, 05:35:54 PM
You're welcome. I think you will manage that. I've actually quite liked how customizable it turned out to be, so I'll probably include the first three changes in the next version of SimplePortal. Then anyone who would like to modify the default sorting can just push their changes to $orderids array as in my example with the last change. Overall, it's difficult to come up with a sorting method that works for everyone. The best we can rely on is the access levels for the groups but even then people still want to customize the order within those groups.
Title: Re: Staff list order, once again
Post by: ♦ Ninja ZX-10RR ♦ on November 28, 2014, 05:42:52 PM
Yeah I can *understand* how much complicated it might be trying to please everyone with just a single solution (included in the mod or even with Underdog's permission tweak)... Thank you for trying so hard, I really appreciate that.
As a sidenote I am posting a feature request in the proper board, you might consider it, I think it would be awesome, but it's just my humble opinion, I am not a coder - just a supporter, always was, always will be :)
Title: Re: Staff list order, once again
Post by: [SiNaN] on November 28, 2014, 05:59:50 PM
Well, you're welcome, thank you and keep those feature requests coming. ;)
Title: Re: Staff list order, once again
Post by: ♦ Ninja ZX-10RR ♦ on November 29, 2014, 11:56:16 AM
I have troubles with the edits, there are many places that look identical in the file... Already the first edit I can't understand where it is that, you are a coder and you know where the stuff is but I have no idea about how the mod was coded >_< and also if I have to edit those things multiple times or not since there are a few identical places, could you point me the lines? I didn't make any custom edits to the file so they should match...
Sorry for not understanding it clearly :/
Title: Re: Staff list order, once again
Post by: [SiNaN] on November 29, 2014, 12:01:34 PM
The second and third edits are certainly unique. The first one is unique as well, unless your edit does not multiple searching for multiple lines. If you still have problems, you can attach your file here and I can apply the first three edits for you. Then you can customize it to your liking as I had shown with the fourth edit above.
Title: Re: Staff list order, once again
Post by: ♦ Ninja ZX-10RR ♦ on November 29, 2014, 12:05:29 PM
Perhaps yes, I would do a compare and see where I was wrong, if you could do it I would appreciate it a lot, sorry again >_< and yes I am trying to edit it with the notepad++ but it finds a ton of results already for the first edit... I really want to see where it should have been placed though, always happy to learn, especially if I have never seen a mod's code.
Thanks in advance once again so helpful!
Title: Re: Staff list order, once again
Post by: [SiNaN] on November 29, 2014, 12:10:29 PM
I have attached the file with the edits. I should note that you seem to have installed something that is supposed to change sorting for that block but I had to remove some lines related to that to make my changes work. Perhaps you should revert all the changes related to modifying the sorting for that block and just use the one I gave above.
Title: Re: Staff list order, once again
Post by: ♦ Ninja ZX-10RR ♦ on November 29, 2014, 12:17:31 PM
It's the staff permission for SimplePortal by Underdog --> http://simpleportal.net/index.php?topic=10209.0 so I uninstall it and then use your file? Or should I uninstall and then re-attach the file? I just don't want to have my error log filled with some errors for uninstalling half of that package or something like that.
Installed since I don't want the administrator membergroup to show up in that block.

EDIT: just noticed that there are 7 edits to that file, it might be a problem if I just replace it with yours given that you removed some pieces of it. IMHO I should uninstall and then ask you to make the edits again >_<
Title: Re: Staff list order, once again
Post by: [SiNaN] on November 29, 2014, 12:27:07 PM
Yeah, first uninstall the mod, then attach your file. While I'm at it, I can add a line of code that would exclude Administrator group from staff list (group id 1) if you want.
Title: Re: Staff list order, once again
Post by: ♦ Ninja ZX-10RR ♦ on November 29, 2014, 12:31:25 PM
Yes if you can please exclude the administrator group from being automatically shown. Thanks in advance once again, sorry for the misunderstanding.
Title: Re: Staff list order, once again
Post by: [SiNaN] on November 29, 2014, 12:43:56 PM
The change for excluding certain groups:

Code: (Find) [Select]
WHERE m.id_member IN ({array_int:staff_list})',
array(

Code: (Replace) [Select]
WHERE m.id_member IN ({array_int:staff_list})
AND m.id_group NOT IN ({array_int:exclude_groups})',
array(
'exclude_groups' => array(1, 2, 3),

You just need to change 1, 2, 3 as the id of member groups you want to exclude separated by commas. This change is already applied to the attached file as well, with only group with the id of 1 excluded.
Title: Re: Staff list order, once again
Post by: ♦ Ninja ZX-10RR ♦ on November 29, 2014, 12:47:44 PM
This is *EXACTLY* what I wanted! Awesome I'm going to do it in a few minutes, still need to sort some .css stuff out and then I will be tackling this one :) Thanks again, I will either edit the message or post again to report the result :)
Title: Re: Staff list order, once again
Post by: ♦ Ninja ZX-10RR ♦ on November 29, 2014, 01:30:32 PM
Damn, I must be doing something wrong.

Quote
http://vige.altervista.org/forum/index.php
2: array_multisort() [<a href='function.array-multisort'>function.array-multisort</a>]: Array sizes are inconsistent
File: /Sources/PortalBlocks.php
Line: 2353

So the code I am using is this one:
Code: [Select]
$smcFunc['db_free_result']($request);
$orderids[2] = 1; /*Ninja*/
$orderids[1] = 2; /*Nayabinghi93*/
$orderids[70] = 3; /*BurkeKnight*/
$orderids[6] = 4; /*Virtual Anubis*/
$orderids[37] = 5; /*Wolf*/
array_multisort($orderids, SORT_ASC, $staff_list);
$staff_count = count($staff_list);
$count = 0;
$icons = array(1 => 'admin', 'gmod', 'lmod');

What's am I doing wrong? Thanks in advance, again. >_<
Maybe 1 2 3 4 5 were supposed to be the admin, gmod or lmod icons and the order is granted by the sorting? I tried to read the documentation but I'm in a hurry and it's *very* complicated... :(

Note: I'm off for dinner so I will reply in a bit more than half an hour.
Title: Re: Staff list order, once again
Post by: [SiNaN] on November 29, 2014, 02:42:04 PM
The only case in which you would get that error is when you set an orderid for a user that does not get listed in the staff list. In the code you quoted, try making the following change:

Code: (Find) [Select]
array_multisort($orderids, SORT_ASC, $staff_list);
Code: (Replace) [Select]
foreach ($orderids as $key => $dummy)
if (!isset($staff_list[$key]))
unset($orderids[$key]);
array_multisort($orderids, SORT_ASC, $staff_list);

That should prevent the error from happening by unsetting orderid members that are not listed in the staff list. But you should check and see which members do not appear and if they really should not appear, then you should make sure that you don't set an orderid value for them.
Title: Re: Staff list order, once again
Post by: ♦ Ninja ZX-10RR ♦ on November 29, 2014, 02:49:00 PM
It did the trick indeed! Nice one :) thanks a lot, it now shows things the way I wanted them! *very happy*
SimplePortal 2.3.8 © 2008-2024, SimplePortal