Search session by their courses tag - refs BT#9887 #TMI

1.10.x
Angel Fernando Quiroz Campos 10 years ago
parent e337fb4a6d
commit 257ffbba6b
  1. 6
      main/auth/courses.php
  2. 86
      main/auth/courses_controller.php
  3. 64
      main/inc/lib/auth.lib.php
  4. 35
      main/template/default/auth/session_catalog.tpl

@ -48,7 +48,8 @@ $actions = array(
'display_random_courses',
'subscribe_user_with_password',
'display_sessions',
'subscribe_to_session'
'subscribe_to_session',
'search_tag'
);
$action = CoursesAndSessionsCatalog::is(CATALOG_SESSIONS) ? 'display_sessions' : 'display_random_courses';
@ -233,4 +234,7 @@ switch ($action) {
}
//else show error message?
break;
case 'search_tag':
$courses_controller->sessionsListByCoursesTag($limit);
break;
}

@ -633,4 +633,90 @@ class CoursesController
$tpl->display($contentTemplate);
}
/**
* Show the Session Catalogue with filtered session by course tags
* @param array $limit Limit info
*/
public function sessionsListByCoursesTag(array $limit)
{
$searchTag = isset($_POST['search_tag']) ? $_POST['search_tag'] : null;
$searchDate = isset($_POST['date']) ? $_POST['date'] : date('Y-m-d');
$hiddenLinks = isset($_GET['hidden_links']) ? intval($_GET['hidden_links']) == 1 : false;
$courseUrl = getCourseCategoryUrl(1, $limit['length'], null, 0, 'subscribe');
$userId = api_get_user_id();
$sessionsBlocks = array();
$sessions = $this->model->browseSessionsByTags($searchTag, $limit);
$key = 'name';
$catalogSessionAutoSubscriptionAllowed = false;
if (api_get_setting('catalog_allow_session_auto_subscription') === 'true') {
$key = 'id';
$catalogSessionAutoSubscriptionAllowed = true;
}
foreach ($sessions as $session) {
$sessionDates = SessionManager::parseSessionDates([
'display_start_date' => $session->getDisplayStartDate(),
'display_end_date' => $session->getDisplayEndDate(),
'access_start_date' => $session->getAccessStartDate(),
'access_end_date' => $session->getAccessEndDate(),
'coach_access_start_date' => $session->getCoachAccessStartDate(),
'coach_access_end_date' => $session->getCoachAccessEndDate()
]);
$sessionsBlock = array(
'id' => $session->getId(),
'name' => $session->getName(),
'nbr_courses' => $session->getNbrCourses(),
'nbr_users' => $session->getNbrUsers(),
'coach_name' => $session->getGeneralCoach()->getCompleteName(),
'is_subscribed' => SessionManager::isUserSubscribedAsStudent($session->getId(), $userId),
'icon' => $this->getSessionIcon($session->getName()),
'date' => $sessionDates['display'],
'subscribe_button' => $this->getRegisteredInSessionButton(
$key === 'id' ? $session->getId() : $session->getName(),
$catalogSessionAutoSubscriptionAllowed
),
'show_description' => $session->getShowDescription(),
);
/** @var \Chamilo\CoreBundle\Entity\Repository\SequenceRepository $repo */
$repo = Database::getManager()->getRepository('ChamiloCoreBundle:SequenceResource');
$requirementAndDependencies = $repo->getRequirementAndDependencies(
$session->getId(),
SequenceResource::SESSION_TYPE
);
$sessionsBlock = array_merge($sessionsBlock, $requirementAndDependencies);
$sessionsBlocks[] = $sessionsBlock;
}
$tpl = new Template();
$tpl->assign('show_courses', CoursesAndSessionsCatalog::showCourses());
$tpl->assign('show_sessions', CoursesAndSessionsCatalog::showSessions());
$tpl->assign('show_tutor', (api_get_setting('show_session_coach')==='true' ? true : false));
$tpl->assign('course_url', $courseUrl);
$tpl->assign('course_category_list', $this->getCoursesCategoriesBlock(null, false, $limit));
$tpl->assign('already_subscribed_label', $this->getAlreadyRegisteredInSessionLabel());
$tpl->assign('hidden_links', $hiddenLinks);
$tpl->assign('search_date', Security::remove_XSS($searchDate));
$tpl->assign('search_tag', Security::remove_XSS($searchTag));
$tpl->assign('sessions', $sessionsBlocks);
if (empty($sessionsBlocks)) {
$tpl->assign('message', Display::return_message(get_lang('NoResults'), 'warning'));
}
$contentTemplate = $tpl->get_template('auth/session_catalog.tpl');
$tpl->display($contentTemplate);
}
}

@ -720,4 +720,68 @@ SQL;
return $count;
}
/**
* Search sessions by the tags in their courses
* @param string $termTag Term for search in tags
* @param array $limit Limit info
* @return array The sessions
*/
public function browseSessionsByTags($termTag, array $limit)
{
$em = Database::getManager();
$qb = $em->createQueryBuilder();
$sessions = $qb->select('s')
->distinct(true)
->from('ChamiloCoreBundle:Session', 's')
->innerJoin(
'ChamiloCoreBundle:SessionRelCourse',
'src',
\Doctrine\ORM\Query\Expr\Join::WITH,
's.id = src.session'
)
->innerJoin(
'ChamiloCoreBundle:ExtraFieldRelTag',
'frt',
\Doctrine\ORM\Query\Expr\Join::WITH,
'src.course = frt.itemId'
)
->innerJoin(
'ChamiloCoreBundle:Tag',
't',
\Doctrine\ORM\Query\Expr\Join::WITH,
'frt.tagId = t.id'
)
->innerJoin(
'ChamiloCoreBundle:ExtraField',
'f',
\Doctrine\ORM\Query\Expr\Join::WITH,
'frt.fieldId = f.id'
)
->where(
$qb->expr()->like('t.tag', ":tag")
)
->andWhere(
$qb->expr()->eq('f.extraFieldType', Chamilo\CoreBundle\Entity\ExtraField::COURSE_FIELD_TYPE)
)
->setFirstResult($limit['start'])
->setMaxResults($limit['length'])
->setParameter('tag', "$termTag%")
->getQuery()
->getResult();
$sessionsToBrowse = [];
foreach ($sessions as $session) {
if ($session->getNbrCourses() === 0) {
continue;
}
$sessionsToBrowse[] = $session;
}
return $sessionsToBrowse;
}
}

@ -17,7 +17,7 @@
if (courseList.length === 0) {
var getCourseList = $.getJSON(
'{{ web_session_courses_ajax_url }}',
'{{ _p.web_ajax }}course.ajax.php',
{
a: 'display_sessions_courses',
session: sessionId
@ -77,7 +77,7 @@
{% if course_category_list is not empty %}
<br>
<a class="btn btn-block btn-default" href="{{ api_get_self }}?action=display_random_courses">{{ 'RandomPick'|get_lang }}</a>
<a class="btn btn-block btn-default" href="{{ _p.web_self }}?action=display_random_courses">{{ 'RandomPick'|get_lang }}</a>
{% endif %}
</div>
</div>
@ -107,13 +107,28 @@
<div class="panel-body">
<div class="row">
<div class="col-xs-12">
<form class="form-search" method="post" action="{{ api_get_self }}?action=display_sessions">
<div class="input-group">
<input type="date" name="date" id="date" class="form-control" value="{{ search_date }}" readonly>
<span class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="fa fa-search"></i> {{ 'Search'|get_lang }}</button>
</span>
</div>
<form class="form-search" method="post" action="{{ _p.web_self }}?action=display_sessions">
<fieldset>
<legend>{{ "ByDate"|get_lang }}</legend>
<div class="input-group">
<input type="date" name="date" id="date" class="form-control" value="{{ search_date }}" readonly>
<span class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="fa fa-search"></i> {{ 'Search'|get_lang }}</button>
</span>
</div>
</fieldset>
</form>
<br>
<form class="form-search" method="post" action="{{ _p.web_self }}?action=search_tag">
<fieldset>
<legend>{{ "ByTag"|get_lang }}</legend>
<div class="input-group">
<input type="text" name="search_tag" class="form-control" value="{{ search_tag }}" />
<span class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="fa fa-search"></i> {{ 'Search'|get_lang }}</button>
</span>
</div>
</fieldset>
</form>
</div>
</div>
@ -192,6 +207,8 @@
</div>
</div>
</div>
{% else %}
{{ message }}
{% endfor %}
{{ catalog_pagination }}
</div>

Loading…
Cancel
Save