News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Alphabetical order of the inbox labels

Started by Wilcop™, November 30, 2013, 10:28:11 AM

Previous topic - Next topic

Wilcop™

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.

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Arantor

It's doable in 2.1 since the PM label system got rewritten, though.

Wilcop™


Arantor

Yeah, but depending on what you did it might have other consequences. But without telling us, this is just pure speculation.

Wilcop™

I am testing it.
And it seems to work fine ;D.

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

ApplyRules();


And replace with:
);
// 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:
);
$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:
);
// 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:
// Load them... load them!!
LoadRules();

// Likely to need all the groups!


And replace with:
// 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:

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;
}

Arantor

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.

Wilcop™

asort will not work because it is an array in an array

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

Arantor

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.

Wilcop™

Also that is resolved.
Found:
$context['sub_template'] = 'labels';

$the_labels = array();


Replace:
$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.

Advertisement: