Location: PHPKode > projects > EMIHR > emihr-0.1.3/includes/CUSTOMER/customerCollection.class.php
<?php
// +----------------------------------------------------------------------+
// | PHP Version 4                                                        |
// +----------------------------------------------------------------------+
// | Copyright (c) 2005 Ematic Interactive                                |
// +----------------------------------------------------------------------+
// | EMIHR is free software; you can redistribute it and/or modify	      |	
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation; either version 2 of the License, or    |
// | (at your option) any later version.								  |
// |																	  |
// | EMIHR 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 EMIHR; if not, write to the Free Software Foundation,     |
// | Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA		  |
// +----------------------------------------------------------------------+
// | Author: René de Kat <hide@address.com>                	              |
// +----------------------------------------------------------------------+
//
// $Id: customerCollection.class.php,v 1.00 2005/09/04 13:31:00 RdK Exp $
/**
 * CustomerCollection class. 
 * This class holds a collection of all the customers of a company. Limited by offSet,MAX_RECORDS_PER_PAGE 
 *
 * @category EMIHR
 * @package CUSTOMER
 * @version $Id: customerCollection.class.php,v 1.10 2005/02/04 13:31:00 RdK Exp $
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 * @copyright (c) 2005 Ematic Interactive
 * @author   René de Kat <hide@address.com> 
 */

/**
 * CustomerCollection class. 
 * This class holds a collection of all the customers of a company. Limited by offSet,MAX_RECORDS_PER_PAGE 
 *
 * @category EMIHR
 * @package CUSTOMER
 * @version $Id: customerCollection.class.php,v 1.10 2005/02/04 13:31:00 RdK Exp $
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 * @copyright (c) 2005 Ematic Interactive
 * @author   René de Kat <hide@address.com> 
 */
class CustomerCollection extends Collection
{
    // {{{ constructor

    /**
     * CustomerCollection constructor.
	 * @param int $companyId the id of the company	 
	 * @param int $offSet start index
	 * @param int $max_records Optional maximum nr of records to be loaded. If 0 all records will be returned. 
     * @access public
     */
	function CustomerCollection($companyId = 0, $offSet = 0, $max_records = 0)
	{
		//A litle variable initialization
		settype($companyId, "integer");
		settype($offSet, "integer");
		settype($max_records, "integer");
		$this->className = "Customer";

		//Initialize the SQL query
		$strLimit = '';
		if ($max_records > 0)
			$strLimit = sprintf('LIMIT %d,%d',$offSet,$max_records);				
		if ($companyId)
		{
			$strSQL = "SELECT customer.* FROM customer WHERE customer.companyId=%d ORDER BY customer.name %s";
			$strSQL = sprintf($strSQL, $companyId, $strLimit);
		}
		else
		{
			$strSQL = "SELECT customer.* FROM customer ORDER BY customer.name %s";
			$strSQL = sprintf($strSQL, $strLimit);
		}

		//Let's load the collection
		$this->loadElements($strSQL);
		
		//Free some memory
		unset($strSQL);
		unset($offSet);
		unset($companyId);
	}
	
	// }}}
}
?>
Return current item: EMIHR