<commit_before><?php
/**
 * Copyright (c) 2011 <NAME> <<EMAIL>>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */

 
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');

$ids = OC_Contacts_Addressbook::activeIds(OCP\USER::getUser());
$contacts_alphabet = OC_Contacts_VCard::all($ids);
$active_addressbooks = OC_Contacts_Addressbook::active(OCP\USER::getUser());

// Our new array for the contacts sorted by addressbook
$contacts_addressbook = array();
foreach($contacts_alphabet as $contact) {
	if(!isset($contacts_addressbook[$contact['addressbookid']])) {
		$contacts_addressbook[$contact['addressbookid']] = array('contacts' => array());
	}
	$display = trim($contact['fullname']);
	if(!$display) {
		$vcard = OC_Contacts_App::getContactVCard($contact['id']);
		if(!is_null($vcard)) {
			$struct = OC_Contacts_VCard::structureContact($vcard);
			$display = isset($struct['EMAIL'][0])?$struct['EMAIL'][0]['value']:'[UNKNOWN]';
		}
	}
	$contacts_addressbook[$contact['addressbookid']]['contacts'][] = array('id' => $contact['id'], 'addressbookid' => $contact['addressbookid'], 'displayname' => htmlspecialchars($display));
}

foreach($contacts_addressbook as $addressbook_id => $contacts) {
	foreach($active_addressbooks as $addressbook) {
		if($addressbook_id == $addressbook['id']) {
			$contacts_addressbook[$addressbook_id]['displayname'] = $addressbook['displayname'];
		}
	}
}

$tmpl = new OCP\Template("contacts", "part.contacts");<commit_msg>Sort addressbooks.<commit_after><?php
/**
 * Copyright (c) 2011 <NAME> <<EMAIL>>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */

function cmp($a, $b)
{
    if ($a['displayname'] == $b['displayname']) {
        return 0;
    }
    return ($a['displayname'] < $b['displayname']) ? -1 : 1;
}
 
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');

$ids = OC_Contacts_Addressbook::activeIds(OCP\USER::getUser());
$contacts_alphabet = OC_Contacts_VCard::all($ids);
$active_addressbooks = OC_Contacts_Addressbook::active(OCP\USER::getUser());

// Our new array for the contacts sorted by addressbook
$contacts_addressbook = array();
foreach($contacts_alphabet as $contact) {
	if(!isset($contacts_addressbook[$contact['addressbookid']])) {
		$contacts_addressbook[$contact['addressbookid']] = array('contacts' => array());
	}
	$display = trim($contact['fullname']);
	if(!$display) {
		$vcard = OC_Contacts_App::getContactVCard($contact['id']);
		if(!is_null($vcard)) {
			$struct = OC_Contacts_VCard::structureContact($vcard);
			$display = isset($struct['EMAIL'][0])?$struct['EMAIL'][0]['value']:'[UNKNOWN]';
		}
	}
	$contacts_addressbook[$contact['addressbookid']]['contacts'][] = array('id' => $contact['id'], 'addressbookid' => $contact['addressbookid'], 'displayname' => htmlspecialchars($display));
}

foreach($contacts_addressbook as $addressbook_id => $contacts) {
	foreach($active_addressbooks as $addressbook) {
		if($addressbook_id == $addressbook['id']) {
			$contacts_addressbook[$addressbook_id]['displayname'] = $addressbook['displayname'];
		}
	}
}

usort($contacts_addressbook, 'cmp');

$tmpl = new OCP\Template("contacts", "part.contacts");
{'fraction_non_alphanumeric': 0.19121683440073192, 'fraction_numerical': 0.00518450747179018, 'mean_word_length': 7.282828282828283, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4530112', 'n_tokens_mistral': 1142, 'n_tokens_neox': 1104, 'n_words': 179}