parent
8f46c81032
commit
78bb332e99
@ -0,0 +1,78 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
use Doctrine\Common\Collections\Criteria; |
||||
use Doctrine\ORM\Tools\Pagination\Paginator; |
||||
|
||||
require_once __DIR__.'/../../main/inc/global.inc.php'; |
||||
|
||||
$plugin = StudentFollowUpPlugin::create(); |
||||
|
||||
$currentUserId = api_get_user_id(); |
||||
$studentId = isset($_GET['student_id']) ? (int) $_GET['student_id'] : api_get_user_id(); |
||||
$currentPage = isset($_GET['page']) ? (int) $_GET['page'] : 1; |
||||
|
||||
if (empty($studentId)) { |
||||
api_not_allowed(true); |
||||
} |
||||
$permissions = StudentFollowUpPlugin::getPermissions($studentId, $currentUserId); |
||||
$isAllow = $permissions['is_allow']; |
||||
$showPrivate = $permissions['show_private']; |
||||
|
||||
if ($isAllow === false) { |
||||
api_not_allowed(true); |
||||
} |
||||
|
||||
$em = Database::getManager(); |
||||
$qb = $em->createQueryBuilder(); |
||||
$criteria = Criteria::create(); |
||||
$criteria->where(Criteria::expr()->eq('user', $studentId)); |
||||
|
||||
if ($showPrivate == false) { |
||||
$criteria->andWhere(Criteria::expr()->eq('private', false)); |
||||
} |
||||
|
||||
$pageSize = 2; |
||||
|
||||
$qb |
||||
->select('p') |
||||
->from('ChamiloPluginBundle:StudentFollowUp\CarePost', 'p') |
||||
->addCriteria($criteria) |
||||
->setFirstResult($pageSize * ($currentPage-1)) |
||||
->setMaxResults($pageSize) |
||||
->orderBy('p.createdAt', 'desc') |
||||
; |
||||
|
||||
$query = $qb->getQuery(); |
||||
|
||||
$posts = new Paginator($query, $fetchJoinCollection = true); |
||||
|
||||
$totalItems = count($posts); |
||||
$pagesCount = ceil($totalItems / $pageSize); |
||||
$pagination = ''; |
||||
$url = api_get_self().'?student_id='.$studentId; |
||||
$pagination .= '<ul class="pagination">'; |
||||
for ($i = 0; $i < $pagesCount; $i++) { |
||||
$newPage = $i + 1; |
||||
if ($currentPage == $newPage) { |
||||
$pagination .= '<li class="active"><a href="'.$url.'&page='.$newPage.'">'.$newPage.'</a></li>'; |
||||
} else { |
||||
$pagination .= '<li><a href="'.$url.'&page='.$newPage.'">'.$newPage.'</a></li>'; |
||||
} |
||||
} |
||||
$pagination .= '</ul>'; |
||||
|
||||
$tpl = new Template($plugin->get_lang('plugin_title')); |
||||
$tpl->assign('posts', $posts); |
||||
$tpl->assign('current_url', $url); |
||||
|
||||
$url = api_get_path(WEB_PLUGIN_PATH).'studentfollowup/post.php?student_id='.$studentId; |
||||
$tpl->assign('post_url', $url); |
||||
$tpl->assign('information_icon', Display::return_icon('info.png')); |
||||
|
||||
$tpl->assign('pagination', $pagination); |
||||
$content = $tpl->fetch('/'.$plugin->get_name().'/view/posts.html.twig'); |
||||
// Assign into content |
||||
$tpl->assign('content', $content); |
||||
// Display |
||||
$tpl->display_one_col_template(); |
||||
@ -0,0 +1,13 @@ |
||||
{% import 'studentfollowup/view/post.html.twig' as template %} |
||||
|
||||
<h1>Care detail view</h1> |
||||
{% if posts %} |
||||
{% for post in posts %} |
||||
{{ template.post_template(post, information_icon, post_url, current_url) }} |
||||
|
||||
|
||||
{% endfor %} |
||||
<div> |
||||
{{ pagination }} |
||||
</div> |
||||
{% endif %} |
||||
Loading…
Reference in new issue