<?php
/**
 * List class
 *
 * @author Lucas Dantas <lucas@caju.nu>
 * @package classes
 * @subpackage list
 * @version 1.0
 * @since 05/02/2015 16:58
 */
Class ListController{

	/**
	 * Defining the repository
	 *
	 * @access public
	 * @static
	 * @param string $type Instance's type
	 * @uses ListRepositoryDBR::getInstance Defining the instance
	 * @return mixed
	 */
	public static function getRepository( $type = null ){

		//Returning
		return ListRepositoryDBR::getInstance( $type );

	}

	/**
	 * Listing orderly and by quantity
	 *
	 * @access public
	 * @static
	 * @param string $type Type
	 * @param string $order Order
	 * @param integer $quantity Quantity
	 * @param boolean $exception Showing or not the exception
	 * @uses self::getRepository Defining the repository
	 * @uses ListRepositoryDBR->orderlyByQuantity Listing orderly and by quantity
	 * @return mixed
	 */
	public static function orderlyByQuantity( $type = 'banner', $order = null, $quantity = 6, $exception = true ){

		//Defining
		$repository	= self::getRepository( $type );

		//Showing or not the exception
		$repository->exception = $exception;

		//Returning
		return $repository->orderlyByQuantity( $order, $quantity );

	}

	/**
	 * Listing orderly
	 *
	 * @access public
	 * @static
	 * @param string $type Type
	 * @param string $order Order
	 * @param boolean $exception Showing or not the exception
	 * @uses self::getRepository Defining the repository
	 * @uses ListRepositoryDBR->orderly Listing orderly
	 * @return mixed
	 */
	public static function orderly( $type = 'banner', $order = null, $exception = true ){

		//Defining
		$repository	= self::getRepository( $type );

		//Showing or not the exception
		$repository->exception = $exception;

		//Returning
		return $repository->orderly( $order );

	}

	/**
	 * Listing the not active and orderly
	 *
	 * @access public
	 * @static
	 * @param string $type Type
	 * @param integer $id Identifier
	 * @param string $order Order
	 * @param boolean $exception Showing or not the exception
	 * @uses Validation::numericFields Validating the numeric fields
	 * @uses self::getRepository Defining the repository
	 * @uses ListRepositoryDBR->notActiveOrderly Listing the not actives and orderly
	 * @return mixed
	 */
	public static function notActiveOrderly( $type = 'product', $id = null, $order = 'random', $exception = false ){

		//Validating
		Validation::numericFields( [ 'identificador' => $id ] );

		//Defining
		$repository	= self::getRepository( $type );

		//Showing or not the exception
		$repository->exception = $exception;

		//Returning
		return $repository->notActiveOrderly( $id, $order );

	}

	/**
	 * Listing the not active, by category and orderly
	 *
	 * @access public
	 * @static
	 * @param string $type Type
	 * @param integer $id Identifier
	 * @param integer $category Category
	 * @param string $order Order
	 * @param boolean $exception Showing or not the exception
	 * @uses Validation::numericFields Validating the numeric fields
	 * @uses self::getRepository Defining the repository
	 * @uses ListRepositoryDBR->notActiveByCategoryOrderly Listing the not actives, by category and orderly
	 * @return mixed
	 */
	public static function notActiveByCategoryOrderly( $type = 'product', $id = null, $category = null, $order = 'random', $exception = false ){

		//Validating
		Validation::numericFields( [ 'identificador' => $id, 'categoria' => $category ] );

		//Defining
		$repository	= self::getRepository( $type );

		//Showing or not the exception
		$repository->exception = $exception;

		//Returning
		return $repository->notActiveByCategoryOrderly( $id, $category, $order );

	}

	/**
	 * Listing by category and orderly
	 *
	 * @access public
	 * @static
	 * @param string $type Type
	 * @param integer $category Category
	 * @param string $order Order
	 * @param boolean $exception Showing or not the exception
	 * @uses Validation::numericFields Validating the numeric fields
	 * @uses self::getRepository Defining the repository
	 * @uses ListRepositoryDBR->byCategoryOrderly Listing  by category and orderly
	 * @return mixed
	 */
	public static function byCategoryOrderly( $type = 'product', $category = null, $order = 'random', $exception = false ){

		//Validating
		Validation::numericFields( [ 'categoria' => $category ] );

		//Defining
		$repository	= self::getRepository( $type );

		//Showing or not the exception
		$repository->exception = $exception;

		//Returning
		return $repository->byCategoryOrderly( $category, $order );

	}

	/**
	 * Listing by form and orderly
	 *
	 * @access public
	 * @static
	 * @param string $type Type
	 * @param integer $form Form
	 * @param string $order Order
	 * @param boolean $exception Showing or not the exception
	 * @uses self::getRepository Defining the repository
	 * @uses ListRepositoryDBR->byFormOrderly Listing by form and orderly
	 * @return mixed
	 */
	public static function byFormOrderly( $type = null, $form = null, $order = 'date', $exception = false ){

		//Defining the repository
		$repository				= self::getRepository( $type );

		//Showing or not the exception
		$repository->exception	= $exception;

		//Returning
		return $repository->byFormOrderly( $form, $order );

	}

	/**
	 * Listing by destination
	 *
	 * @access public
	 * @param integer $destination Destination
	 * @uses Validation::numericFields Validating the numeric fields
	 * @uses self::getRepository Defining the repository
	 * @uses ListRepositoryDBR->listByDestination Listing by destination
	 * @return mixed
	 */
	public static function listByDestination( $destination = null ){

		//Validating
		Validation::numericFields( [ 'destino' => $destination ] );

		//Returning
		return self::getRepository()->listByDestination( $destination );

	}

}