package net.fdms.Database 
{
	import net.fdms.Function.Convert.XMLtoOBJECT;
	/**
	 * 2011/5/12 9:44
	 * @author Dawnboy
	 */
	public class DiaryData 
	{
		private static var _diaryData:Array = [];
		
		public function DiaryData() 
		{
			
			/**
			 * _diaryData = [
			 *	[
			 *		{id:"", title:"日志分类" },
			 *		[
			 *			{id:"", title:"", time:"", src:"" },
			 *			{id:"", title:"", time:"", src:"" },
			 *			{id:"", title:"", time:"", src:"" },
			 *			{id:"", title:"", time:"", src:"" }
			 *		]
			 *	],
			 *	[
			 *		{id:"", title:"日志分类" },
			 *		[
			 *			{id:"", title:"", time:"", src:"" },
			 *			{id:"", title:"", time:"", src:"" },
			 *			{id:"", title:"", time:"", src:"" },
			 *			{id:"", title:"", time:"", src:"" }
			 *		]
			 *	]
			 *]
			 */
			
		}
		
		/**
		 * 初始化日志数据
		 * @param	diarySets
		 */
		public static function init(diarySets:XMLList):void {
			var n:int = diarySets.children().length();
			//trace(XMLtoOBJECT.convert(diarySets.sort[1].diary[2]).id);
			if (n) {
				for (var a:int = 0; a < n; a++) {
					_diaryData.push([]);
					_diaryData[a].push(XMLtoOBJECT.convert(diarySets.type[a]));
					_diaryData[a].push([]);
					var sn:int = diarySets.type[a].children().length();
					if (sn) {
						for (var b:int = 0; b < sn; b++) {
							_diaryData[a][1].push(XMLtoOBJECT.convert(diarySets.type[a].item[b]));
						}
					}
				}
				
			}
			//trace(_diaryData[0][0].title);
			//debug();
			
		}
		
		/**
		 * 获取完整日志数据
		 * @return
		 */
		public static function getAllDiaryData():Array {
			return _diaryData;
		}
		
		/**
		 * 获取文章分类列表
		 * @return
		 */
		public static function getSorts():Array {
			var n:int = _diaryData.length;
			var foo:Array = [];			
			for (var a:int = 0; a < n; a++) {
				foo.push(_diaryData[a][0]);
			}
			
			return foo;
		}
		
		/**
		 * 获取文章列表,默认获取所有文章列表
		 * @param	sortID
		 * @return
		 */
		public static function getDiaryList(sortID:int = NaN):Array {
			var n:int = _diaryData.length;
			var foo:Array = [];
			var a:int = 0;
			if (sortID) {
				for (a; a < n; a++) {
					if (sortID == _diaryData[a][0].id) {
						foo = _diaryData[a][1];
						break;
					}
				}
			}else {
				for (a; a < n; a++) {
					var tmp:int = _diaryData[a][1].length;
					for (var b:int = 0; b < tmp; b++) {
						foo.push(_diaryData[a][1][b]);
					}
				}
			}
			return foo;
		}
		
		private static function debug():void {
			var n:int = _diaryData.length;
			for (var a:int = 0; a < n; a++) {
				trace("[" + _diaryData[a][0].title + "] ID:" + _diaryData[a][0].id + " 共 " + _diaryData[a][1].length + " 条文章");
			}
			trace("---------------------------------")
			
		}
	}

}