Skip to content

Commit 4b5f86c

Browse files
committed
Add pending surveys page - refs BT#11913
1 parent ad649f4 commit 4b5f86c

File tree

4 files changed

+131
-0
lines changed

4 files changed

+131
-0
lines changed

main/survey/pending.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/* For licensing terms, see /license.txt */
3+
4+
use Chamilo\CourseBundle\Entity\CSurvey;
5+
use Chamilo\CourseBundle\Entity\CSurveyInvitation;
6+
use Chamilo\CoreBundle\Entity\Course;
7+
use Chamilo\CoreBundle\Entity\Session;
8+
9+
$cidReset = true;
10+
11+
require_once __DIR__.'/../inc/global.inc.php';
12+
13+
api_block_anonymous_users(true);
14+
15+
$em = Database::getManager();
16+
17+
$currentUser = api_get_user_entity(api_get_user_id());
18+
$avatarPath = UserManager::getUserPicture($currentUser->getId());
19+
$pending = SurveyUtil::getUserPendingInvitations($currentUser->getId());
20+
21+
$surveysData = [];
22+
23+
foreach ($pending as $i => $item) {
24+
if (is_a($item, 'Chamilo\CourseBundle\Entity\CSurveyInvitation')) {
25+
continue;
26+
}
27+
28+
/** @var CSurvey $survey */
29+
$survey = $item;
30+
/** @var CSurveyInvitation invitation */
31+
$invitation = $pending[$i + 1];
32+
/** @var Course $course */
33+
$course = $em->find('ChamiloCoreBundle:Course', $survey->getCId());
34+
/** @var Session $session */
35+
$session = $em->find('ChamiloCoreBundle:Session', $survey->getSessionId());
36+
37+
$surveysData[$survey->getSurveyId()] = [
38+
'title' => $survey->getTitle(),
39+
'invitation_code' => $invitation->getInvitationCode(),
40+
'avail_from' => $survey->getAvailFrom(),
41+
'avail_till' => $survey->getAvailTill(),
42+
'course' => $course
43+
? ['id' => $course->getId(), 'title' => $course->getTitle(), 'code' => $course->getCode()]
44+
: null,
45+
'session' => $session
46+
? ['id' => $session->getId(), 'name' => $session->getName()]
47+
: null
48+
];
49+
}
50+
51+
$toolName = get_lang('PendingSurveys');
52+
53+
$template = new Template($toolName);
54+
$template->assign('user', $currentUser);
55+
$template->assign('user_avatar', $avatarPath);
56+
$template->assign('surveys', $surveysData);
57+
$layout = $template->get_template('survey/pending.tpl');
58+
$content = $template->fetch($layout);
59+
$template->assign('header', $toolName);
60+
$template->assign('content', $content);
61+
$template->display_one_col_template();

main/survey/surveyUtil.class.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3757,4 +3757,31 @@ public static function checkIfSurveyHasAnswers($surveyId)
37573757

37583758
return $response > 0;
37593759
}
3760+
3761+
/**
3762+
* Get the pending surveys for a user
3763+
*
3764+
* @param int $userId
3765+
*
3766+
* @return array
3767+
*/
3768+
public static function getUserPendingInvitations($userId)
3769+
{
3770+
$now = api_get_utc_datetime(null, false, true);
3771+
3772+
$dql = "
3773+
SELECT s, si FROM ChamiloCourseBundle:CSurvey s
3774+
INNER JOIN ChamiloCourseBundle:CSurveyInvitation si
3775+
WITH (s.code = si.surveyCode AND s.cId = si.cId AND s.sessionId = si.sessionId )
3776+
WHERE si.user = :user_id AND s.availFrom <= :now AND s.availTill >= :now
3777+
ORDER BY s.availTill ASC
3778+
";
3779+
3780+
$pendingSurveys = Database::getManager()
3781+
->createQuery($dql)
3782+
->setParameters(['user_id' => $userId, 'now' => $now->format('Y-m-d')])
3783+
->getResult();
3784+
3785+
return $pendingSurveys;
3786+
}
37603787
}

main/template/default/layout/menu.tpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@
7070
<em class="fa fa-envelope" aria-hidden="true"></em> {{ "Inbox"|get_lang }}
7171
</a>
7272
</li>
73+
<li class="user-body">
74+
<a href="{{ _p.web_main ~ 'survey/pending.php' }}">
75+
<em class="fa fa-pie-chart"></em> {{ 'PendingSurveys'|get_lang }}
76+
</a>
77+
</li>
7378
{% if certificate_url %}
7479
<li class="user-body">
7580
<a title="{{ "MyCertificates"|get_lang }}" href="{{ certificate_url }}">
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<div class="media">
2+
<div class="media-left">
3+
<a href="#">
4+
<img class="media-object" src="{{ user_avatar }}" alt="{{ user.completeName }}">
5+
</a>
6+
</div>
7+
<div class="media-body">
8+
<h3 class="media-heading">{{ user.completeName }}</h3>
9+
<p>{{ user.username }}</p>
10+
</div>
11+
</div>
12+
<br>
13+
{% for survey in surveys %}
14+
{% set course_code = survey.course ? survey.course.code : '' %}
15+
{% set session_id = survey.session ? survey.session.id : 0 %}
16+
17+
<div class="panel panel-default">
18+
{% if survey.course %}
19+
<div class="panel-heading">
20+
<h3 class="panel-title">
21+
{{ survey.course.title }}
22+
23+
{% if survey.session %}
24+
({{ survey.session.name }})
25+
{% endif %}
26+
</h3>
27+
</div>
28+
{% endif %}
29+
<div class="panel-body">
30+
<div>
31+
<a href="{{ _p.web_main ~ 'survey/fillsurvey.php?' ~ {'course': course_code, 'invitationcode': survey.invitation_code, 'cidReq': course_code, 'id_session': session_id}|url_encode }}">
32+
{{ survey.title }}
33+
</a>
34+
<p>{{ 'FromDateXToDateY'|get_lang|format(survey.avail_from|api_convert_and_format_date(2), survey.avail_till|api_convert_and_format_date(2)) }}</p>
35+
</div>
36+
</div>
37+
</div>
38+
{% endfor %}

0 commit comments

Comments
 (0)