diff --git a/app/controllers/Admin.php b/app/controllers/Admin.php index bbaa79d2e41e5a927964cbee04bc46c706fe667c..f6a9719fc126b5d5111b7e7a5e068ff08fb24ab6 100644 --- a/app/controllers/Admin.php +++ b/app/controllers/Admin.php @@ -2,8 +2,8 @@ class Admin extends Controller { public function index() { - header('Location: /admin/dashboard'); - exit(); + header('Location: /404'); + exit(); } public function dashboard() { @@ -58,9 +58,12 @@ class Admin extends Controller { // Manage Languages else { + $data["pageTitle"] = "Admin manage"; $data["languages"] = $this->model("LanguageModel")->getAllLanguage(); - + + var_dump($_GET); + $this->view('header/index', $data); $this->view('navbar/index'); $this->view('admin/manage/index', $data); diff --git a/app/controllers/Learn.php b/app/controllers/Learn.php index 30156ec9c19a855a03c8332b908590bae475066f..c5281ae5882a6c61dd98203812cb214befcc2013 100644 --- a/app/controllers/Learn.php +++ b/app/controllers/Learn.php @@ -33,8 +33,15 @@ class Learn extends Controller { // List of modules else if (isset($languageId) && !empty($languageId)) { $data["pageTitle"] = "Keep learning!"; + $data["language"] = $this->model("LanguageModel")->getLanguageById($languageId); + $data["modules"] = $this->model("ModuleModel")->getModulesByLanguageId($languageId); + if (isset($_GET["find"]) && !empty($_GET["find"])) { + $find = "%" . $_GET["find"] . "%"; + $data["modules"] = $this->model("ModuleModel")->getModulesByLanguageIdSearched($languageId, $find); + } + for ($i = 0; $i < count($data["modules"]); $i++) { $data["modules"][$i]["videos"] = $this->model("VideoModel")->getVideosByModuleId($data["modules"][$i]["module_id"]); } diff --git a/app/core/App.php b/app/core/App.php index 73b24d872da8d858d101f8f7f9d2752a5513e7fa..1c6fc00d90f97dacd7867cbef4fda7d95e8be425 100644 --- a/app/core/App.php +++ b/app/core/App.php @@ -5,53 +5,48 @@ class App { protected $method = 'index'; protected $params = []; - public function __construct() - { - // Redirect to 'Home' + public function __construct() { $url = $this->parse_url(); - if (file_exists('app/controllers/' . $url[0] . '.php')) { - $this->controller = $url[0]; - unset($url[0]); - } - else if ($url[0] == '') { - $this->controller = 'Home'; - } - else { - $this->controller = 'Error404'; - } - // Load the controller + // === CONTROLLER === + + if ( isset($url[0]) ) { + if ( file_exists('app/controllers/' . $url[0] . '.php')) { + $this->controller = $url[0]; + unset($url[0]); + } + } + require_once 'app/controllers/' . $this->controller . '.php'; $this->controller = new $this->controller; - if (isset($url[1])) { - if (method_exists($this->controller, $url[1])) { + // === METHOD === + + if ( isset($url[1]) ) { + if ( method_exists($this->controller, $url[1]) ) { $this->method = $url[1]; unset($url[1]); } } - if ($url) { + // === PARAMETER === + + if ( !empty($url) ) { $this->params = array_values($url); } + // === RUN CONTROLLERS, METHODS, AND PARAMS === + call_user_func_array([$this->controller, $this->method], $this->params); } - - public function parse_url() - { - if (isset($_SERVER['REQUEST_URI'])) { - if ($_SERVER['REQUEST_URI'] == '/') { - return ['']; - } - $url = $_SERVER['REQUEST_URI']; - $url = preg_replace('#^/public/#', '/', $url); - $url = rtrim($url, '/'); - $url = explode('/', $url); - $url = array_values(array_filter($url)); - return $url; + public function parse_url() { + if ( isset($_GET['url']) ) { + $url = rtrim($_GET['url'], '/'); + $url = filter_var($url, FILTER_SANITIZE_URL); + $url = explode('/', $url); + return $url; + } } } - } \ No newline at end of file diff --git a/app/core/Controller.php b/app/core/Controller.php index 6640e8217fb18e2b533193e12dba52e97950a0e4..e97e0c669039fd4c21312dc174c71b20787cf848 100644 --- a/app/core/Controller.php +++ b/app/core/Controller.php @@ -2,13 +2,7 @@ class Controller { public function view($view, $data = []) { - // Check for view file - if (file_exists('app/views/' . $view . '.php')) { - require_once 'app/views/' . $view . '.php'; - } else { - // View does not exist - die('View does not exist'); - } + require_once 'app/views/' . $view . '.php'; } public function model($model) { diff --git a/app/models/ModuleModel.php b/app/models/ModuleModel.php index 18bb77af5c05fc09f55d01db4240cf0a5a7d8311..84e6ca0073b4991e941ecf95ecfc46af0fb44941 100644 --- a/app/models/ModuleModel.php +++ b/app/models/ModuleModel.php @@ -48,4 +48,11 @@ class ModuleModel { $this->db->bind('user_id', $user_id); return $this->db->resultSet(); } + + public function getModulesByLanguageIdSearched($language_id, $search) { + $this->db->query("SELECT * FROM " . $this->table . " WHERE language_id = :language_id AND (module_name like :search OR category like :search)"); + $this->db->bind('language_id', $language_id); + $this->db->bind('search', $search); + return $this->db->resultSet(); + } } \ No newline at end of file diff --git a/app/views/admin/manage/index.php b/app/views/admin/manage/index.php index 2be0d8156ef8635a92a994d0f11cbc78eb2b5e70..d7aef7f830be25bfff7291d7ec3a6288dd7b2fa1 100644 --- a/app/views/admin/manage/index.php +++ b/app/views/admin/manage/index.php @@ -8,8 +8,8 @@ </h1> <div class="search-bar"> - <form action="" method="GET"> - <input type="text" placeholder="Search languages" class="text-sm text-black font-reg"> + <form action="" method="get"> + <input name="find" type="text" placeholder="Search languages" class="text-sm text-black font-reg"> <button type="submit"> <img id="search-icon" src="/public/icons/search-icon.svg" alt="Search icon"> </button> diff --git a/app/views/lesson/index.php b/app/views/lesson/index.php index 4dd73150e632d834bfb3295ba4509dc9f4c1ec94..0f28afb114940b4106387334847aaca444736c23 100644 --- a/app/views/lesson/index.php +++ b/app/views/lesson/index.php @@ -7,9 +7,9 @@ <?= $data["language"]["language_name"] ?> </h1> - <form action="" method="GET"> + <form method="get"> <div class="search-bar"> - <input type="text" placeholder="Search modules or videos" class="text-sm text-black font-reg"> + <input name="find" type="text" placeholder="Search modules" class="text-sm text-black font-reg"> <button type="submit"> <img id="search-icon" src="/public/icons/search-icon.svg" alt="Search icon"> </button> @@ -17,7 +17,8 @@ <div class="filter-sort"> <select name="difficulty" id="difficulty-input" class="text-sm font-reg text-black"> - <option value="Beginner" selected>Beginner</option> + <option value="">Select Difficulty</option> + <option value="Beginner">Beginner</option> <option value="Intermediate">Intermediate</option> <option value="Advanced">Advanced</option> </select>