<?php
/**
 * Edit repository
 *
 * @author Lucas Dantas <lucas@caju.nu>
 * @package classes
 * @subpackage list
 * @version 1.0
 * @since 2018/04/09 19:25
 */
Class EditRepositoryDBR{

	/**
	 * Connection's object
	 *
	 * @access private
	 * @var PDO
	 */
	private $connection;

	/**
	 * Showing or not the exception
	 *
	 * @access private
	 * @var boolean
	 */
	private $exception	= true;

	/**
	 * Instance
	 *
	 * @access private
	 * @static
	 * @var ListRepositoryDBR
	 */
	private static $instance = null;

	/**
	 * Class constructor
	 *
	 * @access public
	 * @uses ConnectionDBR::getInstance Defining the instance
	 */
	public function __construct(){

		$this->connection	= ConnectionDBR::getInstance()->getConnection();

	}

	/**
	 * Defining the instance
	 *
	 * @access public
	 * @return EditRepositoryDBR
	 */
	public static function getInstance(){

		//Checking
		if( is_null( self::$instance ) )
			//Defining
			self::$instance	= new self();

		//Returning
		return self::$instance;

	}

	/**
	 * Editing the answer's date by your identifier and destination
	 *
	 * @access public
	 * @param integer $id Identifier
	 * @param integer $destino Destination
	 * @uses Util::defineDestinationOptions Defining the destination's options
	 * @throws Exception
	 */
	public function statusByIdByDestination( $id, $destination ){

		try{

			//Defining the object
			$object	= Util::defineDestinationOptions( $destination );

			//Preparing
			$resSql	= $this->connection->prepare( 'UPDATE ' . $object->table . ' SET status = :status WHERE id = :id' );

			//Defining
			$resSql->bindValue( ':status', STATUS_WAITING, PDO::PARAM_INT );
			$resSql->bindValue( ':id', $id, PDO::PARAM_INT );

			//Executing
			$resSql->execute();

		}catch( PDOException $e ){

			//Throw the exception
			throw new Exception( 'Ocorreu um erro durante a edição. Por favor, tente novamente mais tarde.' );

		}

	}

}