Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: Wilcop™ on November 30, 2013, 10:28:11 AM

Title: Alphabetical order of the inbox labels
Post by: Wilcop™ 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.
Title: Re: Alphabetical order of the inbox labels
Post by: Kindred on November 30, 2013, 10:29:18 AM
no, I don't believe so.
Title: Re: Alphabetical order of the inbox labels
Post by: Arantor on November 30, 2013, 11:42:50 AM
It's doable in 2.1 since the PM label system got rewritten, though.
Title: Re: Alphabetical order of the inbox labels
Post by: Wilcop™ on November 30, 2013, 02:10:58 PM
I may have found a solution...
Title: Re: Alphabetical order of the inbox labels
Post by: Arantor 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.
Title: Re: Alphabetical order of the inbox labels
Post by: Wilcop™ 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;
}
Title: Re: Alphabetical order of the inbox labels
Post by: Arantor 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.
Title: Re: Alphabetical order of the inbox labels
Post by: Wilcop™ 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.
Title: Re: Alphabetical order of the inbox labels
Post by: Arantor 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.
Title: Re: Alphabetical order of the inbox labels
Post by: Wilcop™ 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.