Advertisement:

Author Topic: Alphabetical order of the inbox labels  (Read 3274 times)

Offline Wilcop™

  • Newbie
  • *
  • Posts: 9
Alphabetical order of the inbox labels
« on: November 30, 2013, 10:28:11 AM »
Is it possible to order of the inbox labels in alphabetical order?
I can't found any modification or topic for it.

I am using SMF 2.0.4.
« Last Edit: November 30, 2013, 11:50:49 AM by Wilcop™ »

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 58,317
  • Gender: Male
    • Kindred-999 on GitHub
Re: Alphabetical order of the inbox labels
« Reply #1 on: November 30, 2013, 10:29:18 AM »
no, I don't believe so.
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,210
    • StoryBB/StoryBB on GitHub
Re: Alphabetical order of the inbox labels
« Reply #2 on: November 30, 2013, 11:42:50 AM »
It's doable in 2.1 since the PM label system got rewritten, though.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Wilcop™

  • Newbie
  • *
  • Posts: 9
Re: Alphabetical order of the inbox labels
« Reply #3 on: November 30, 2013, 02:10:58 PM »
I may have found a solution...

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,210
    • StoryBB/StoryBB on GitHub
Re: Alphabetical order of the inbox labels
« Reply #4 on: November 30, 2013, 02:11:55 PM »
Yeah, but depending on what you did it might have other consequences. But without telling us, this is just pure speculation.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Wilcop™

  • Newbie
  • *
  • Posts: 9
Re: Alphabetical order of the inbox labels
« Reply #5 on: November 30, 2013, 02:28:10 PM »
I am testing it.
And it seems to work fine ;D.

This is what i have done:
Sources/PersonalMessage.php
Found:
Code: [Select]
);
$context['labels'][-1] = array(
'id' => -1,
'name' => $txt['pm_msg_label_inbox'],
'messages' => 0,
'unread_messages' => 0,
);

ApplyRules();

And replace with:
Code: [Select]
);
// Order them alphabetical...
$context['labels'] = record_sort($context['labels'], 'name');
$context['labels'][-1] = array(
'id' => -1,
'name' => $txt['pm_msg_label_inbox'],
'messages' => 0,
'unread_messages' => 0,
);

ApplyRules();

Also found:
Code: [Select]
);
$context['labels'][-1] = array(
'id' => -1,
'name' => $txt['pm_msg_label_inbox'],
'messages' => 0,
'unread_messages' => 0,
);

// Looks like we need to reseek!

And replace with:
Code: [Select]
);
// Order them alphabetical...
$context['labels'] = record_sort($context['labels'], 'name');
$context['labels'][-1] = array(
'id' => -1,
'name' => $txt['pm_msg_label_inbox'],
'messages' => 0,
'unread_messages' => 0,
);

// Looks like we need to reseek!

This is for de rules
Found:
Code: [Select]
// Load them... load them!!
LoadRules();

// Likely to need all the groups!

And replace with:
Code: [Select]
// Load them... load them!!
LoadRules();
// Order them alphabetical...
$context['rules'] = record_sort($context['rules'], 'name');

// Likely to need all the groups!

At the bottom of the file, i have created a function:
Code: [Select]
function record_sort($records, $field) {
    $hash = array();
   
    foreach($records as $record)
        $hash[$record[$field]] = $record;
   
    ksort($hash);
   
    $records = array();
   
    foreach($hash as $record)
        $records[]= $record;
   
    return $records;
}

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,210
    • StoryBB/StoryBB on GitHub
Re: Alphabetical order of the inbox labels
« Reply #6 on: November 30, 2013, 02:39:18 PM »
Yeah, I can see problems with this, like miscategorisation of things.

I'd also wonder why you're going such a long way around with the sorting when you could just replace the entire function with asort() to sort by the contents while maintaining the key/value associations.

If you keep the associations, it should actually work properly.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Wilcop™

  • Newbie
  • *
  • Posts: 9
Re: Alphabetical order of the inbox labels
« Reply #7 on: November 30, 2013, 02:55:51 PM »
asort will not work because it is an array in an array

I found one problem.
When you add or deleted a label :o.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,210
    • StoryBB/StoryBB on GitHub
Re: Alphabetical order of the inbox labels
« Reply #8 on: November 30, 2013, 03:09:06 PM »
Hmm, oh I see what you're doing, yes an asort won't work in that situation, I thought you were just pulling the ids and labels and sorting those in an overly complex way.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Wilcop™

  • Newbie
  • *
  • Posts: 9
Re: Alphabetical order of the inbox labels
« Reply #9 on: November 30, 2013, 03:16:25 PM »
Also that is resolved.
Found:
Code: [Select]
$context['sub_template'] = 'labels';

$the_labels = array();

Replace:
Code: [Select]
$context['sub_template'] = 'labels';

$the_labels = array();
// Order them back on id...
unset($context['labels'][-1]);
$context['labels'] = record_sort($context['labels'], 'id');

I'm continue to looking for a better and cleaner way.
When i found that i put it down here.