<?php

/**
 Insert copyright here
 */

/**
 *
 * @package CRM
 * @author Marshal Newrock <marshal@idealso.com>
 * $Id$
 */

require_once 'CRM/Core/DAO/LineItem.php';

/**
 * Business objects for Line Items generated by monetary transactions
 */
class CRM_Core_BAO_LineItem extends CRM_Core_DAO_LineItem {

    /**
     * Creates a new entry in the database.
     *
     * @param array $params (reference) an assoc array of name/value pairs
     *
     * @return object CRM_Core_DAO_LineItem object
     * @access public
     * @static
     */
    static function create (&$params)
    {
        $lineItemBAO =& new CRM_Core_BAO_LineItem();
        $lineItemBAO->copyValues($params);
        return $lineItemBAO->save();
    }

    /**
     * Takes a bunch of params that are needed to match certain criteria and
     * retrieves the relevant objects.  Typically, the valid params are only
     * price_field_id.  This is the inverse function of create.  It also
     * stores all of the retrieved values in the default array.
     *
     * @param array $params   (reference ) an assoc array of name/value pairs
     * @param array $defaults (reference ) an assoc array to hold the flattened values
     *
     * @return object CRM_Core_BAO_LineItem object
     * @access public
     * @static
     */
    static function retrieve( &$params, &$defaults )
    {
        $lineItem =& new CRM_Core_DAO_LineItem( );
        $lineItem->copyValues( $params );
        if ( $lineItem->find( true ) ) {
            CRM_Core_DAO::storeValues( $lineItem, $defaults );
            return $lineItem;
        }
        return null;
    }

}

