Course catalog: format + clean code - refs BT#19827

pull/4232/head
Angel Fernando Quiroz Campos 4 years ago
parent a5874c1d06
commit 6191cf7f8c
  1. 14
      main/auth/courses.php
  2. 110
      main/inc/lib/CoursesAndSessionsCatalog.class.php
  3. 104
      main/template/default/catalog/session_catalog.tpl

@ -59,7 +59,6 @@ if (empty($nameTools)) {
$auth = new Auth();
$userId = api_get_user_id();
$currentUrl = api_get_path(WEB_CODE_PATH).'auth/courses.php?category_code='.$categoryCode.'&search_term='.$searchTerm;
$content = '';
$toolTitle = get_lang('CourseCatalog');
$courseCatalogSettings = [
@ -121,7 +120,6 @@ switch ($action) {
header('Location: '.$currentUrl);
exit;
break;
case 'subscribe_course':
$courseCodeToSubscribe = isset($_GET['course_code']) ? Security::remove_XSS($_GET['course_code']) : '';
if (api_is_anonymous()) {
@ -182,6 +180,9 @@ switch ($action) {
exit;
}
$template = new Template($toolTitle, true, true, false, false, false);
$template->assign('content', $content);
$template->display_one_col_template();
break;
case 'subscribe':
if (!$userCanViewPage) {
@ -189,7 +190,6 @@ switch ($action) {
}
header('Location: '.api_get_self());
exit;
break;
case 'display_random_courses':
case 'display_courses':
case 'search_course':
@ -577,7 +577,6 @@ switch ($action) {
$template->display($template->get_template('catalog/course_catalog.tpl'));
exit;
break;
case 'display_sessions':
if (!$userCanViewPage) {
api_not_allowed(true);
@ -585,7 +584,6 @@ switch ($action) {
CoursesAndSessionsCatalog::sessionList($limit);
exit;
break;
case 'subscribe_to_session':
if (!$userCanViewPage) {
api_not_allowed(true);
@ -666,7 +664,6 @@ switch ($action) {
CoursesAndSessionsCatalog::sessionsListByCoursesTag($limit);
exit;
break;
case 'search_session_title':
if (!$userCanViewPage) {
api_not_allowed(true);
@ -674,9 +671,4 @@ switch ($action) {
CoursesAndSessionsCatalog::sessionsListByName($limit);
exit;
break;
}
$template = new Template($toolTitle, true, true, false, false, false);
$template->assign('content', $content);
$template->display_one_col_template();

@ -18,57 +18,32 @@ class CoursesAndSessionsCatalog
/**
* Check the configuration for the courses and sessions catalog.
*
* @global array $_configuration Configuration
*
* @param int $value The value to check
*
* @return bool Whether the configuration is $value
*/
public static function is($value = CATALOG_COURSES)
public static function is(int $value = CATALOG_COURSES): bool
{
$showCoursesSessions = (int) api_get_setting('catalog_show_courses_sessions');
if ($showCoursesSessions == $value) {
return true;
}
return false;
return $showCoursesSessions == $value;
}
/**
* Check whether to display the sessions list.
*
* @global array $_configuration Configuration
*
* @return bool whether to display
*/
public static function showSessions()
public static function showSessions(): bool
{
$catalogShow = (int) api_get_setting('catalog_show_courses_sessions');
if ($catalogShow == CATALOG_SESSIONS || $catalogShow == CATALOG_COURSES_SESSIONS) {
return true;
}
return false;
return $catalogShow == CATALOG_SESSIONS || $catalogShow == CATALOG_COURSES_SESSIONS;
}
/**
* Check whether to display the courses list.
*
* @global array $_configuration Configuration
*
* @return bool whether to display
*/
public static function showCourses()
public static function showCourses(): bool
{
$catalogShow = (int) api_get_setting('catalog_show_courses_sessions');
if ($catalogShow == CATALOG_COURSES || $catalogShow == CATALOG_COURSES_SESSIONS) {
return true;
}
return false;
return $catalogShow == CATALOG_COURSES || $catalogShow == CATALOG_COURSES_SESSIONS;
}
/**
@ -1034,40 +1009,29 @@ class CoursesAndSessionsCatalog
}
/**
* Display the course catalog image of a course.
*
* @param array $course
*
* @return string HTML string
* Get the image of a course for the catalog.
*/
public static function returnThumbnail($course)
public static function returnThumbnail(array $course): string
{
$course_path = api_get_path(SYS_COURSE_PATH).$course['directory'];
if (file_exists($course_path.'/course-pic.png')) {
// redimensioned image 85x85
$courseMediumImage = api_get_path(WEB_COURSE_PATH).$course['directory'].'/course-pic.png';
} else {
// without picture
$courseMediumImage = Display::return_icon(
'session_default.png',
null,
null,
null,
null,
true
);
return api_get_path(WEB_COURSE_PATH).$course['directory'].'/course-pic.png';
}
return $courseMediumImage;
// without picture
return Display::return_icon(
'session_default.png',
null,
null,
null,
null,
true
);
}
/**
* @param array $courseInfo
*
* @return string
*/
public static function return_teacher($courseInfo)
public static function return_teacher(array $courseInfo): string
{
$teachers = CourseManager::getTeachersFromCourse($courseInfo['real_id']);
$length = count($teachers);
@ -1340,23 +1304,6 @@ class CoursesAndSessionsCatalog
);
}
/**
* Get a icon for a session.
*
* @param string $sessionName The session name
*
* @return string The icon
*/
public static function getSessionIcon($sessionName)
{
return Display::return_icon(
'window_list.png',
$sessionName,
null,
ICON_SIZE_MEDIUM
);
}
public static function getSessionPagination($action, $countSessions, $limit)
{
$pageTotal = ceil($countSessions / $limit['length']);
@ -1382,8 +1329,8 @@ class CoursesAndSessionsCatalog
*/
public static function sessionList($limit = [])
{
$date = isset($_POST['date']) ? $_POST['date'] : '';
$limit = isset($limit) ? $limit : self::getLimitArray();
$date = $_POST['date'] ?? '';
$limit = $limit ?? self::getLimitArray();
$countSessions = self::browseSessions($date, [], false, true);
$sessions = self::browseSessions($date, $limit);
@ -1425,7 +1372,7 @@ class CoursesAndSessionsCatalog
*/
public static function sessionsListByName(array $limit)
{
$keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : null;
$keyword = $_REQUEST['keyword'] ?? null;
$courseUrl = self::getCatalogUrl(
1,
$limit['length'],
@ -1518,8 +1465,8 @@ class CoursesAndSessionsCatalog
*/
public static function sessionsListByCoursesTag(array $limit)
{
$searchTag = isset($_REQUEST['search_tag']) ? $_REQUEST['search_tag'] : '';
$searchDate = isset($_REQUEST['date']) ? $_REQUEST['date'] : date('Y-m-d');
$searchTag = $_REQUEST['search_tag'] ?? '';
$searchDate = $_REQUEST['date'] ?? date('Y-m-d');
$courseUrl = self::getCatalogUrl(
1,
$limit['length'],
@ -1672,7 +1619,12 @@ class CoursesAndSessionsCatalog
'coach_name' => $coachName,
'coach_avatar' => UserManager::getUserPicture($coachId, USER_IMAGE_SIZE_SMALL),
'is_subscribed' => SessionManager::isUserSubscribedAsStudent($session->getId(), $userId),
'icon' => self::getSessionIcon($session->getName()),
'' => Display::return_icon(
'window_list.png',
$session->getName(),
[],
ICON_SIZE_MEDIUM
),
'date' => $sessionDates['display'],
'price' => !empty($isThisSessionOnSale['html']) ? $isThisSessionOnSale['html'] : '',
'subscribe_button' => isset($isThisSessionOnSale['buy_button']) ? $isThisSessionOnSale['buy_button'] : self::getRegisteredInSessionButton(
@ -1863,7 +1815,7 @@ class CoursesAndSessionsCatalog
$action = isset($action) ? Security::remove_XSS($action) : $requestAction;
$searchTerm = isset($_REQUEST['search_term']) ? Security::remove_XSS($_REQUEST['search_term']) : '';
$keyword = isset($_REQUEST['keyword']) ? Security::remove_XSS($_REQUEST['keyword']) : '';
$searchTag = isset($_REQUEST['search_tag']) ? $_REQUEST['search_tag'] : '';
$searchTag = $_REQUEST['search_tag'] ?? '';
if ($action === 'subscribe_user_with_password') {
$action = 'subscribe';

@ -8,13 +8,11 @@
});
});
</script>
<div class="row">
<div class="col-md-12">
{{ actions }}
<!-- header catalog session -->
<div class="search-session">
<div class="row">
{% if catalog_settings.sessions.by_title %}
{{ actions }}
<!-- header catalog session -->
<div class="search-session">
<div class="row">
{% if catalog_settings.sessions.by_title %}
<div class="col-md-4">
<form method="post" action="{{ _p.web_self }}?action=search_session_title">
<label>{{ "Name"|get_lang }}</label>
@ -29,53 +27,43 @@
</div>
</form>
</div>
{% endif %}
{% endif %}
{% if catalog_settings.sessions.by_date %}
{% if show_courses %}
<div class="col-md-4">
{% else %}
<div class="col-md-4">
{% endif %}
<form method="post" action="{{ _p.web_self }}?action=display_sessions">
<div class="form-group">
<label>{{ "ByDate"|get_lang }}</label>
<div class="input-group">
<input type="date" name="date" id="date" title="{{ 'Date'|get_lang }}"
class="form-control" value="{{ search_date }}" readonly>
<span class="input-group-btn">
<button class="btn btn-default" type="submit">
<em class="fa fa-search"></em> {{ 'Search'|get_lang }}
</button>
</span>
</div>
{% if catalog_settings.sessions.by_date %}
<div class="col-md-4">
<form method="post" action="{{ _p.web_self }}?action=display_sessions">
<div class="form-group">
<label>{{ "ByDate"|get_lang }}</label>
<div class="input-group">
<input type="date" name="date" id="date" title="{{ 'Date'|get_lang }}"
class="form-control" value="{{ search_date }}" readonly>
<span class="input-group-btn">
<button class="btn btn-default" type="submit">
<em class="fa fa-search"></em> {{ 'Search'|get_lang }}
</button>
</span>
</div>
</form>
</div>
{% endif %}
</div>
</form>
</div>
{% endif %}
{% if catalog_settings.sessions.by_tag %}
{% if show_courses %}
<div class="col-md-4">
{% else %}
<div class="col-md-4">
{% endif %}
<form method="post" action="{{ _p.web_self }}?action=search_tag">
<label>{{ "ByTag"|get_lang }}</label>
<div class="input-group">
<input type="text" name="search_tag" title="{{ 'ByTag'|get_lang }}" class="form-control"
value="{{ search_tag }}"/>
<span class="input-group-btn">
<button class="btn btn-default" type="submit">
<em class="fa fa-search"></em> {{ 'Search'|get_lang }}
</button>
</span>
</div>
</form>
{% if catalog_settings.sessions.by_tag %}
<div class="col-md-4">
<form method="post" action="{{ _p.web_self }}?action=search_tag">
<label>{{ "ByTag"|get_lang }}</label>
<div class="input-group">
<input type="text" name="search_tag" title="{{ 'ByTag'|get_lang }}" class="form-control"
value="{{ search_tag }}"/>
<span class="input-group-btn">
<button class="btn btn-default" type="submit">
<em class="fa fa-search"></em> {{ 'Search'|get_lang }}
</button>
</span>
</div>
</div>
{% endif %}
</div>
</form>
</div>
{% endif %}
</div>
</div>
<!-- new view session grib -->
@ -87,7 +75,8 @@
<div id="session-{{ item.id }}" class="items items-courses items-sessions">
<div class="image">
<a href="{{ _p.web ~ 'session/' ~ item.id ~ '/about/' }}" title="{{ item.name }}">
<img class="img-responsive" src="{{ item.image ? _p.web_upload ~ item.image : 'session_default.png'|icon() }}">
<img class="img-responsive" src="{{ item.image ? _p.web_upload ~ item.image : 'session_default.png'|icon() }}"
alt="{{ item.name }}">
</a>
{% if item.category != '' %}
<span class="category">{{ item.category }}</span>
@ -116,7 +105,7 @@
<div class="block-author">
<div class="author-card">
<a href="{{ item.coach_url }}" class="ajax" data-title="{{ item.coach_name }}">
<img src="{{ item.coach_avatar }}"/>
<img src="{{ item.coach_avatar }}" alt="{{ item.coach_name }}">
</a>
<div class="teachers-details">
<h5>
@ -180,8 +169,9 @@
html: true,
trigger: 'click',
content: function () {
var content = '';
{% if item.sequences %}
var content = '';
{% for sequence in item.sequences %}
content += '<p class="lead">{{ sequence.name }}</p>';
{% if sequence.requirements %}
@ -214,11 +204,11 @@
content += '<hr>';
{% endif %}
{% endfor %}
return content;
{% else %}
content = "{{ 'NoDependencies'|get_lang }}";
return "{{ 'NoDependencies'|get_lang }}";
{% endif %}
return content;
}
});
</script>
@ -238,4 +228,4 @@
<!-- end view session grib -->
{{ catalog_pagination }}
{% endblock %}
{% endblock %}

Loading…
Cancel
Save