/** * Return an associative array with limit of 4 rows from db * the total count of rows is at the index 'count' in the array */ protected function do_get() { if (isset($_GET['trainer-id']) && isset($_GET['page'])) { $param1 = explode("/", $_GET['trainer-id']); $param2 = explode("/", $_GET['page']); $id = $param1[0]; $currentPage = $param2[0]; $rows = ProjectModel::getCurrentProjects($id, $currentPage, 4); $rows['totalProjects'] = count(ProjectModel::getAllProjects($id)); // add count of rows to the array $rows['currentPage'] = $currentPage; $this->statusCode = 200; // Produce utf8 encoded json $this->headers[] = "Content-type: text/json; charset=utf-8"; $this->body = json_encode($rows); } }
for ($int = 0; $int < count($listOfTeams); $int++) { $teamID = $listOfTeams[$int]['team_id']; $content .= "<div class=\"col-md-3 portfolio-item\">\n <a href=\"team-id-{$teamID}\">\n <img class=\"img-responsive\" src=\"images/team.jpg\" alt=\"\">\n </a>\n <p style='text-align: center'>Team {$teamID}</p>\n </div>"; } } $pagination = WebFunctions::pagination($currentPage, $totalNumberOfPages); // add pagination // add view include_once "../view/home-student.php"; } else { if ($isTrainer == "true") { $trainerID = $_SESSION['trainer_id']; // get id $trainerName = $_SESSION['name']; // get name $totalNumberOfProjects = count(ProjectModel::getAllProjects($trainerID)); // get total amount $totalNumberOfPages = ceil($totalNumberOfProjects / $projectPerPage); // calc number of pages $currentPage = isset($_GET['current_page']) ? (int) $_GET['current_page'] : 1; // if currentPage var isset else default 1 $startPage = ($currentPage - 1) * $projectPerPage; // calc start page ex. 1 = 0 - 4 projects // set content: $listOfTeams = ProjectModel::getCurrentProjects($trainerID, $startPage, $projectPerPage); // get projects $content = ""; for ($int = 0; $int < count($listOfTeams); $int++) { $name = $listOfTeams[$int]['Title']; $project_id = $listOfTeams[$int]['project_id']; $content .= "<div class=\"col-md-3 portfolio-item\">\n <a href=\"project-id-{$project_id}\">\n <img class=\"img-responsive\" src=\"images/project.png\" alt=\"\">\n </a>\n <p style='text-align: center'> {$name} </p>\n </div>";