<?php
/**
 * 会员数据层
 *
 * @author Wzb
 *        
 */
class DAL_Member extends DAL_Base {
	
	/**
	 * 添加一个会员
	 *
	 * @param array $theArray
	 * @return int
	 */
	public static function add($theArray) {
		return parent::_add ( $theArray, 10 );
	}
	
	/**
	 * 修改一个会员
	 *
	 * @param array $theArray
	 * @return int
	 */
	public static function edit($theArray) {
		return parent::_edit ( $theArray, 10 );
	}
	
	/**
	 * 删除会员
	 *
	 * @param string $idList 多个必须用-分割开
	 * @return bool
	 */
	public static function delete($idList) {
		return parent::_delete ( $idList, 10 );
	}
	
	/**
	 * 获取一个会员
	 *
	 * @param array $theArray id|username|username、password
	 * @param string $code 需要的字段 默认值：*
	 * @return array
	 */
	public static function getOne($theArray, $code = '*') {
		global $conn;
		if (array_key_exists ( 'id', $theArray )) {
			$sql = "select $code from " . parent::_tableName ( 10 ) . " where id=$theArray[id]";
		} elseif (array_key_exists ( 'password', $theArray )) {
			$sql = "select $code from " . parent::_tableName ( 10 ) . " where username='$theArray[username]' and password='$theArray[password]'";
		} else {
			$sql = "select $code from " . parent::_tableName ( 10 ) . " where username='$theArray[username]'";
		}
		return $conn->GetRow ( $sql );
	}
	
	/**
	 * 获取所有会员
	 *
	 * @param string $code 需要的字段 默认值：*
	 * @param array $limitArr 包含两项值limit数组 默认值：array('begin'=>0,'num'=>0)
	 * @return array
	 */
	public static function getAllList($code = '*', $limitArr = array('begin'=>0,'num'=>0)) {
		return self::_getAllList ( 10, $limitArr, "id desc", $code );
	}
}
?>