<?php
/**
 * 右侧浮动逻辑层
 *
 * @author Wzb
 *        
 */
class BLL_Float {
	/**
	 * 添加一条右侧浮动
	 *
	 * @param array $theArray
	 * @return int
	 */
	public static function add($theArray) {
		$newArray = array ();
		$newArray = COM_OftenFunction::makeArray ( $theArray );
		$newArray ['serialNum'] = 0;
		return DAL_Float::add ( $newArray );
	}
	
	/**
	 * 修改一条右侧浮动
	 *
	 * @param array $theArray
	 * @return int
	 */
	public static function edit($theArray) {
		$newArray = array ();
		$newArray = COM_OftenFunction::makeArray ( $theArray );
		$newArray ['id'] = intval ( $theArray ['theId'] );
		return DAL_Float::edit ( $newArray );
	}
	
	/**
	 * 删除指定条右侧浮动
	 *
	 * @param string $idList 多个必须用-分割开
	 * @return string string error1 id字符串为空|error2 删除失败|ok 删除成功
	 */
	public static function delete($idList) {
		if (empty ( $idList )) {
			return 'error1';
		}
		if (DAL_Float::delete ( $idList )) {
			return 'ok';
		} else {
			return 'error2';
		}
	}
	
	/**
	 * 获取一条右侧浮动
	 *
	 * @param int $id
	 * @param string $code 需要的字段 默认值：*
	 * @return array
	 */
	public static function getOne($id, $code = '*') {
		return DAL_Float::getOne ( intval ( $id ), $code );
	}
	
	/**
	 * 获取所有右侧浮动列表
	 *
	 * @param string $code 需要的字段 默认值：*
	 * @param array $limitArr 默认值： array('begin'=>0,'num'=>0)
	 * @return array()
	 */
	public static function getAllList($code = '*', $limitArr = array('begin'=>0,'num'=>0)) {
		return DAL_Float::getAllList ( $code, $limitArr );
	}
	
	/**
	 * 获取类别列表
	 *
	 * @return array
	 */
	public static function getSortList() {
		$dataList = array ();
		$dataList [] = array ("id" => 0,"sortName" => "类别" );
		$dataList [] = array ("id" => 1,"sortName" => "QQ" );
		$dataList [] = array ("id" => 2,"sortName" => "邮箱" );
		$dataList [] = array ("id" => 3,"sortName" => "Msn" );
		$dataList [] = array ("id" => 4,"sortName" => "Skype" );
		$dataList [] = array ("id" => 5,"sortName" => "电话" );
		return $dataList;
	}
	
	/**
	 * 交换两个右侧浮动的序号
	 *
	 * @param string $idStr
	 */
	public static function swapSerial($idStr) {
		$theArray = explode ( "-", $idStr );
		for($i = 0; $i < 4; $i ++) {
			$theArray [$i] = intval ( $theArray [$i] );
		}
		DAL_Float::edit ( array ("id" => $theArray [0],"serialNum" => $theArray [3] ) );
		DAL_Float::edit ( array ("id" => $theArray [1],"serialNum" => $theArray [2] ) );
	}
	
	/**
	 * 获取一组右侧浮动的上一条与下一条
	 *
	 * @param array $theList 需要排序的链接的二维数组
	 * @return array
	 */
	public static function getPreNext($theList) {
		if (count ( $theList ) == 0) {
			return array ();
		}
		$allList = DAL_Float::getAllList ( 'id,serialNum', array ('begin' => 0,'num' => 0 ) );
		$begin = 0;
		for($j = 0; $j < count ( $allList ); $j ++) {
			if (intval ( $allList [$j] ['id'] ) == intval ( $theList [0] ['id'] )) {
				$begin = $j;
				break;
			}
		}
		for($i = $begin; $i < $begin + count ( $theList ); $i ++) {
			$theList [$i - $begin] ['preStr'] = '';
			$theList [$i - $begin] ['nextStr'] = '';
			if ($i > 0) {
				$theList [$i - $begin] ['preStr'] = $theList [$i - $begin] ['id'] . '-' . $allList [$i - 1] ['id'] . '-' . $theList [$i - $begin] ['serialNum'] . '-' . $allList [$i - 1] ['serialNum'];
			}
			if ($i < count ( $allList ) - 1) {
				$theList [$i - $begin] ['nextStr'] = $theList [$i - $begin] ['id'] . '-' . $allList [$i + 1] ['id'] . '-' . $theList [$i - $begin] ['serialNum'] . '-' . $allList [$i + 1] ['serialNum'];
			}
		}
		return $theList;
	}
}
?>