Location: PHPKode > projects > ConPortal > conportal/inc/sort.php
<?php
/*
 *  ConPortal - Pomona College ITS scheduling appplication
 *  Copyright (C) 2005-2006  Pomona College
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of version 2 of the GNU General Public License
 *  as published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

/* CALLBACK FUNCTIONS
 * These callback functions can be passed to usort() when
 * getting the information about a specific group (user, group, perm)
 */
function sort_last_first_insensitive_cb ($a, $b)
{
    $tmp = strcasecmp($a['last'], $b['last']);
    if ($tmp)
        return $tmp;

    return strcasecmp($a['first'], $b['first']);
}

function sort_name_insensitive_cb ($a, $b)
{
    return strcasecmp($a['name'], $b['name']);
}

function sort_start_time_cb ($a, $b)
{
	return (time_part($a['start_time']) < time_part($b['start_time'])) ? -1 :
		(time_part($a['start_time']) == time_part($b['start_time'])) ? 0 : 1;
}

function sort_start_date_start_time_cb ($a, $b)
{
	list($aStartDate) = xlate_shiftdate($a['day_of_week'], $a['start_date'], $a['end_date'], $a['pid']);
	list($bStartDate) = xlate_shiftdate($b['day_of_week'], $b['start_date'], $b['end_date'], $b['pid']);
	if ($aStartDate == $bStartDate)
		return (time_part($a['start_time']) < time_part($b['start_time'])) ? -1 :
			(time_part($a['start_time']) == time_part($b['start_time'])) ? 0 : 1;

	return ($aStartDate < $bStartDate) ? -1 : 1;
}

/*
 * Sorting functions (call these from the rest of the code)
 */

function sortUsersByName ($array)
{
	usort($array, "sort_last_first_insensitive_cb");
	return $array;
}

function sortGroupsByName ($array)
{
	usort($array, "sort_name_insensitive_cb");
	return $array;
}

function sortPermissionsByName ($array)
{
	usort($array, "sort_name_insensitive_cb");
	return $array;
}

function sortShiftsByDateTime ($array)
{
	usort($array, "sort_start_date_start_time_cb");
	return $array;
}

function sortShiftsByTime ($array)
{
	usort($array, "sort_start_time_cb");
	return $array;
}

?>
Return current item: ConPortal