PDA

View Full Version : Contacts Sort Order


trimble
19-04-05, 05:13 AM
I'm attempting to change the sort order for my Contacts page and believe I've found the section of code in contacts/index.php which controls this (lines 27-49):

$orderby = 'contact_order_by';
//$orderby = 'contact_last_name';


// Pull First Letters
$let = ":";
$q = new DBQuery;
$q->addTable('contacts');
$q->addQuery("DISTINCT UPPER(SUBSTRING($orderby,1,1)) as L");
$q->addWhere("contact_private=0 OR (contact_private=1 AND contact_owner=$AppUI->user_id)
OR contact_owner IS NULL OR contact_owner = 0");
$arr = $q->loadList();
foreach( $arr as $L ) {
$let .= $L['L'];
}

// optional fields shown in the list (could be modified to allow breif and verbose, etc)
$showfields = array(
// "test" => "concat(contact_first_name,' ',contact_last_name) as test", why do we want the name repeated?
"company_name" => "company_name",
"contact_phone" => "contact_phone",
"contact_email" => "contact_email"
);

As you can see, I've tried changing the $orderby value to 'contact_last_name', but this has no discernable affect on the page. I'm sure this is due to the

$q->addQuery("DISTINCT UPPER(SUBSTRING($orderby,1,1)) as L");

line, but at this point I don't yet understand what this line is doing and why.

Any help appreciated!

pedroa
19-04-05, 07:57 AM
Hi trimble,

I am sorry to say that you are mistaken. If you saw the line:
//Pull First Letters
carefully, you'd noticed that this particular sql statment is to erh... Pull First Letters
DISTINCT UPPER(SUBSTRING($orderby,1,1)) as L
means Pull First Letters out of contact_order_by field. DISTINCT because we don't want to pull the same letter twice (or more), UPPER because we want the letters Uppercase, SUBSTRING because we just want to pull the first one on the left please (1,1).

Then the letters are sent to $let and has you just might have guessed, the letters get blackened so that you can select a letter tab of contacts. Yeah those letters you see on top of the contacts.

Now that I am here, I am gonna change mine too by the way. Ah, much better now by first name.

Hey, when I select a letter it shows zip.

trimble I'm on your boat man, we got to get out of here.

But, there is this $q that starts at line 54, let me see....
ah, line 60 and 70, thought you could escape me hah?

Line 60 makes sure the contacts appear in the correct letter erh ... tab,
$q->addWhere("(contact_first_name LIKE '$where%' $additional_filter)");

Line 70 takes care of the order within that letter tab (or in the All tab).
$q->addOrder('contact_first_name');

Well just saved myself how about you?

Pedro A.

trimble
19-04-05, 08:34 AM
Your always there Pedroa!

I'm sailing again with a contact_last_name, contact_first_name sort order.

I even managed to change the name display to Last Name, First Name.

Don't need to worry about the Contacts page any more!

Fair winds and following seas, mate!

amitk
26-04-05, 03:55 PM
Hi,

I still didn't get much of it...can you tell once again what all is needed to be done?

Regards,

Amit K

pedroa
01-05-05, 11:03 AM
On file contacts/index.php, change line 27 and select here the field of your first letter pulling choice, for example:

$orderby = 'contact_first_name';

Now change line 60 according to your choice above, for example:

$q->addWhere("(contact_first_name LIKE '$where%' $additional_filter)");

Notice the contact_first_name just like on line 27. Now change line 70 according to your choice above, for example:

$q->addOrder('contact_first_name');

File contacts/index.php, lines 27, 60 and 70, you just can't miss it.

Pedro A.