<commit_before><?php
/*

SUPER CONTROLLER WE ARE NO LONGER USING SEPERATE CONTROLLER FILES.

ALL GET, PUT, DELETE, POST calls go through here for the website
*/

include_once("model/Book.php");
include_once("model/Author.php");

class Controller {
	public $book_model;
	public $author_model;
	public $_routes = ['author', 'book', 'uml', 'documentation', 'query-builder', 'update-viewbook'];
	
	public function __construct()  
    {  
        $this->book_model = new Book();
        $this->author_model = new Author();

    } 
	
	public function invoke()
	{
		$noRequests = TRUE;

		for ($i = 0; $i < count($this->_routes); $i++)
		{
			
			if ( isset($_GET[$this->_routes[$i]]) )
			{
				$noRequests = FALSE;
			}
		}

		if($noRequests)
		{
			// no special book is requested, we'll show a list of all available books
			$books = $this->book_model->getBookList();
			include 'view/templates/header.php';
			include 'view/pages/booklist.php';
			include 'view/templates/footer.php';
		}

		$this->getRequestHandler();
		$this->postRequestHandler();



		
	}

	private function getRequestHandler()
	{
		if($_SERVER['REQUEST_METHOD'] == 'GET')
		{
			if(isset($_GET['book']))
			{
				// show the requested book
				$book = $this->book_model->getBook($_GET['book']);
				include 'view/templates/header.php';
				include 'view/pages/viewbook.php';
				include 'view/templates/footer.php';
			}

			if (isset($_GET['author']))
			{
				// no special book is requested, we'll show a list of all available books
				$books_by_author = $this->author_model->getBooksByAuthor($_GET['author']);
				include 'view/templates/header.php';
				include 'view/pages/authorsbooks.php';
				include 'view/templates/footer.php';
			}

			if (isset($_GET['uml']))
			{
				include 'view/templates/header.php';
				include 'UML.html';
				include 'view/templates/footer.php';
			}

			if (isset($_GET['documentation']))
			{
				include 'view/templates/header.php';
				include 'view/pages/documentation.php';
				include 'view/templates/footer.php';
			}

			if (isset($_GET['query-builder']))
			{
				include 'view/templates/header.php';
				include 'view/pages/query-builder.php';
				include 'view/templates/footer.php';
			}

		}
	}

	private function postRequestHandler()
	{
		if($_SERVER['REQUEST_METHOD'] == 'POST')
		{
			include 'view/templates/header.php';
			echo 'testing post request handler function';
			include 'view/templates/footer.php';			
		}

	}
}

?><commit_msg>modified controller, routes for loop mandatory<commit_after><?php
/*

SUPER CONTROLLER WE ARE NO LONGER USING SEPERATE CONTROLLER FILES.

ALL GET, PUT, DELETE, POST calls go through here for the website
*/

include_once("model/Book.php");
include_once("model/Author.php");

class Controller {
	public $book_model;
	public $author_model;
	public $_routes = ['author', 'book', 'uml', 'documentation', 'query-builder', 'update-viewbook'];
	
	public function __construct()  
    {  
        $this->book_model = new Book();
        $this->author_model = new Author();

    } 
	
	public function invoke()
	{
		$noRequests = TRUE;

		// this loop is mandatory since we could not use $_SERVER['REQUEST_METHOD']
		for ($i = 0; $i < count($this->_routes); $i++)
		{
			
			if ( isset($_GET[$this->_routes[$i]]) || isset($_POST[$this->_routes[$i]]) )
			{
				$noRequests = FALSE;
			}
		}

		if($noRequests)
		{
			// no special book is requested, we'll show a list of all available books
			$books = $this->book_model->getBookList();
			include 'view/templates/header.php';
			include 'view/pages/booklist.php';
			include 'view/templates/footer.php';
		}

		$this->getRequestHandler();
		$this->postRequestHandler();



		
	}

	private function getRequestHandler()
	{
		if($_SERVER['REQUEST_METHOD'] == 'GET')
		{
			if(isset($_GET['book']))
			{
				// show the requested book
				$book = $this->book_model->getBook($_GET['book']);
				include 'view/templates/header.php';
				include 'view/pages/viewbook.php';
				include 'view/templates/footer.php';
			}

			if (isset($_GET['author']))
			{
				// no special book is requested, we'll show a list of all available books
				$books_by_author = $this->author_model->getBooksByAuthor($_GET['author']);
				include 'view/templates/header.php';
				include 'view/pages/authorsbooks.php';
				include 'view/templates/footer.php';
			}

			if (isset($_GET['uml']))
			{
				include 'view/templates/header.php';
				include 'UML.html';
				include 'view/templates/footer.php';
			}

			if (isset($_GET['documentation']))
			{
				include 'view/templates/header.php';
				include 'view/pages/documentation.php';
				include 'view/templates/footer.php';
			}

			if (isset($_GET['query-builder']))
			{
				include 'view/templates/header.php';
				include 'view/pages/query-builder.php';
				include 'view/templates/footer.php';
			}

		}
	}

	private function postRequestHandler()
	{
		if($_SERVER['REQUEST_METHOD'] == 'POST')
		{
			include 'view/templates/header.php';
			echo 'testing post request handler function';
			include 'view/templates/footer.php';			
		}

	}
}

?>
{'fraction_non_alphanumeric': 0.1612839700669555, 'fraction_numerical': 0.00039385584875935406, 'mean_word_length': 3.3860103626943006, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4859910', 'n_tokens_mistral': 1950, 'n_tokens_neox': 1641, 'n_words': 350}