
/*
 * CourseList class
 *
 * @package classes
 * @copyright Copyright 2009, Lastbyte VOF
 * @version 1.0
 */
var CourseList = new Class(
{
	Implements: Options,

	options:
	{
	},

  /*
   * Constructor
   */
	initialize: function ()
	{
		this.courses = new Array();
	},

	/*
	 * Method to add a course to this list
	 *
	 * @param Course course
	 */
	addCourse: function (course)
	{
		if ($type(course) == 'object')
			this.courses.push(course);
	},
	
	/*
	 * Returns the course with the specified index
	 *
	 * @param integer index
	 * @return Course
	 */	
	getCourse: function (index)
	{
		return this.courses[index];
	},
	
	/*
	 * Returns all the courses
	 *
	 * @return Array
	 */	
	getCourses: function (course)
	{
		return this.courses;
	},
	
	/*
	 * Returns the number of courses in the list
	 *
	 * @return Array
	 */	
	getLength: function ()
	{
		return this.courses.length;
	},
	
	/* 
	 * This method returns a new CourseList object with all the courses filtered that do not match specified attributes
	 *
	 * @param Hash parameters
	 * @return CourseList
	 */
	filter: function (parameters)
	{
		var list = new CourseList();
		this.courses.each(function (course)
		{
			var include = true;
			parameters.each(function (value, key)
			{
				if (course.hasAttribute(key))
				{
					var hasValue = false;
					value.each(function (item)
					{
						if (course.hasValue(key, item))
							hasValue = true;
					}.bind(this));
					if (!hasValue)
						include = false;
				}
			}.bind(this));
			if (include)
				list.addCourse(course);
		}.bind(this));
		
		return list;
	}

});
