Browse Source

Change to Twig template - refs #7275

Angel Fernando Quiroz Campos 10 years ago
parent
commit
4df84f1ee7

+ 54 - 2
main/auth/courses.php

@@ -100,7 +100,7 @@ if ($action == 'display_random_courses' || $action == 'display_courses' ) {
 }
 
 if ($action == 'display_sessions') {
-    $nameTools = get_lang('CourseManagement');
+    $nameTools = get_lang('Sessions');
 }
 
 // Breadcrumbs.
@@ -221,7 +221,59 @@ switch ($action) {
         break;
     case 'display_sessions':
         $date = isset($_POST['date']) ? $_POST['date'] : date('Y-m-d');
+        $hiddenLinks = intval($_GET['hidden_links']) == 1;
+
+        $userInfo = api_get_user_info();
+
+        $authModel = new Auth();
+        $sessions = $authModel->browseSessions($date);
+        $courseCategories = $authModel->browse_course_categories();
+
+        $sessionsBlocks = array();
+
+        foreach ($sessions as $session) {
+            $sessionsBlocks[] = array(
+                'id' => $session['id'],
+                'name' => $session['name'],
+                'nbr_courses' => $session['nbr_courses'],
+                'nbr_users' => $session['nbr_users'],
+                'coach_name' => $session['coach_name'],
+                'is_subscribed' => $session['is_subscribed'],
+                'icon' => $courses_controller->getSessionIcon($session['name']),
+                'date' => SessionManager::getSessionFormattedDate($session),
+                'subscribe_button' => $courses_controller->getRegisterInSessionButton($session['name'], $userInfo)
+            );
+        }
 
-        $courses_controller->sessions($action, $date);
+        $tpl = new Template();
+        $tpl->assign('action', $action);
+        $tpl->assign('showCourses', CoursesAndSessionsCatalog::showCourses());
+        $tpl->assign('showSessions', CoursesAndSessionsCatalog::showSessions());
+        
+        $tpl->assign('coursesCategoriesList', $courses_controller->getCoursesCategoriesBlock());
+        
+        $tpl->assign('texts', array(
+            'search' => get_lang('Search'),
+            'randomPick' => get_lang('RandomPick'),
+            'courseCategories' => get_lang('CourseCategories'),
+            'courseList' => get_lang('CourseList'),
+            'sessions' => get_lang('Sessions'),
+            'sessionList' => $nameTools,
+            'searchSessions' => get_lang('SearchSessions')
+        ));
+
+        $tpl->assign('api_get_self', api_get_self());
+        $tpl->assign('hiddenLinks', $hiddenLinks);
+        $tpl->assign('searchToken', Security::get_token());
+        $tpl->assign('searchTerm', empty($_POST['search_term']) ? '' : api_htmlentities(Security::remove_XSS($_POST['search_term'])));
+
+        $tpl->assign('searchDate', $date);
+        $tpl->assign('web_session_courses_ajax_url', api_get_path(WEB_AJAX_PATH) . 'course.ajax.php');
+        $tpl->assign('sessions_blocks', $sessionsBlocks);
+        $tpl->assign('already_subscribed_label', $courses_controller->getAlreadyRegisterInSessionLabel());
+
+        $conentTemplate = $tpl->get_template('auth/sessions_catalog.tpl');
+
+        $tpl->display($conentTemplate);
         break;
 }

+ 141 - 0
main/auth/courses_controller.php

@@ -329,4 +329,145 @@ class CoursesController { // extends Controller {
         $this->view->render();
     }
 
+    /**
+     * Get the html block for courses categories
+     * @param string $code Current category code
+     * @param boolean $hiddenLinks Whether hidden links
+     * @return string The HTML block
+     */
+    public function getCoursesCategoriesBlock($code = null, $hiddenLinks = false)
+    {
+        $categories = $this->model->browse_course_categories();
+
+        $html = '';
+
+        if (!empty($categories)) {
+
+            foreach ($categories[0] as $category) {
+                $categoryName = $category['name'];
+                $categoryCode = $category['code'];
+                $categoryCourses = $category['count_courses'];
+
+                if ($code == $categoryCode) {
+                    $html .= '<li><strong>';
+                    $html .= "$categoryName ($categoryCourses)";
+                    $html .= '</strong><li>';
+                } else {
+                    if (!empty($categoryCourses)) {
+                        $html .= '<li><a href="' . api_get_self() . '"?action=display_courses&category_code=' . $categoryCode . '&hidden_links=' . $hiddenLinks . '">';
+                        $html .= "$categoryName ($categoryCourses)";
+                        $html .= '</a></li>';
+                    } else {
+                        $html .= "<li>$categoryName ($categoryCourses)</li>";
+                    }
+                }
+
+                if (!empty($categories[$categoryCode])) {
+                    foreach ($categories[$categoryCode] as $subCategory1) {
+                        $subCategory1Name = $subCategory1['name'];
+                        $subCategory1Code = $subCategory1['code'];
+                        $subCategory1Courses = $subCategory1['count_courses'];
+
+                        if ($code == $subCategory1Code) {
+                            $html .= '<li style="margin-left: 20px">';
+                            $html .= "<strong>$subCategory1Name ($subCategory1Courses)</strong>";
+                            $html .= '</li>';
+                        } else {
+                            $html .= '<li style="margin-left: 20px"><a href="' . api_get_self() . '?action=display_courses&category_code=' . $subCategory1Code . '&hidden_links=' . $hiddenLinks . '">';
+                            $html .= "$subCategory1Name ($subCategory1Courses)";
+                            $html .= '</a></li>';
+                        }
+
+                        if (!empty($categories[$subCategory1Code])) {
+                            foreach ($categories[$subCategory1Code] as $subCategory2) {
+                                $subCategory2Name = $subCategory2['name'];
+                                $subCategory2Code = $subCategory2['code'];
+                                $subCategory2Courses = $subCategory2['count_courses'];
+
+                                if ($code == $subCategory2Code) {
+                                    $html .= '<li style="margin-left: 40px">';
+                                    $html .= "<strong>$subCategory2Name ($subCategory2Courses)</strong>";
+                                    $html .= '</li>';
+                                } else {
+                                    $html .= '<li style="margin-left: 40px"><a href="' . api_get_self() . '?action=display_courses&category_code=' . $subCategory2Code . '&hidden_links=' . $hiddenLinks . '">';
+                                    $html .= "$subCategory2Name ($subCategory2Courses)";
+                                    $html .= '</a></li>';
+                                }
+
+                                if (!empty($categories[$subCategory2Code])) {
+                                    foreach ($categories[$subCategory2Code] as $subCategory3) {
+                                        $subCategory3Name = $subCategory3['name'];
+                                        $subCategory3Code = $subCategory3['code'];
+                                        $subCategory3Courses = $subCategory3['count_courses'];
+
+                                        if ($code == $subCategory3Code) {
+                                            $html .= '<li style="margin-left: 40px">';
+                                            $html .= "<strong>$subCategory3Name ($subCategory3Courses)</strong>";
+                                            $html .= '</li>';
+                                        } else {
+                                            $html .= '<li style="margin-left: 40px"><a href="' . api_get_self() . '?action=display_courses&category_code=' . $subCategory3Code . '&hidden_links=' . $hiddenLinks . '">';
+                                            $html .= "$subCategory3Name ($subCategory3Courses)";
+                                            $html .= '</a></li>';
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        return $html;
+    }
+
+    /**
+     * Get a HTML button for subscribe to session
+     * @param string $sessionName The session name
+     * @param array $userInfo The user information
+     * @return string The button
+     */
+    public function getRegisterInSessionButton($sessionName, $userInfo)
+    {
+        $mailSubject = get_lang('SubscribeToSession') . " '$sessionName'";
+
+        $mailMessage = get_lang('PleaseSubscribeToSession') . PHP_EOL . PHP_EOL;
+        $mailMessage = get_lang('Session') . ": $sessionName" . PHP_EOL . PHP_EOL;
+        $mailMessage.= get_lang('ContactInformation') . ':' . PHP_EOL;
+        $mailMessage.= get_lang('Name') . ": {$userInfo['complete_name']}" . PHP_EOL;
+        $mailMessage.= get_lang('Username') . ": {$userInfo['username']}" . PHP_EOL;
+        $mailMessage.= get_lang('Email') . ": {$userInfo['email']}" . PHP_EOL;
+
+        $mailParams = http_build_query(array(
+            'email_title' => $mailSubject,
+            'email_text' => $mailMessage
+        ));
+
+        return Display::tag('a', get_lang('Subscribe'), array(
+                    'class' => 'btn btn-primary clickable_email_link',
+                    'href' => "mailto:angelfqc.18@gmail.com&$mailParams"
+        ));
+    }
+
+    /**
+     * Generate a label if the user has been  registered in session
+     * @return string The label
+     */
+    public function getAlreadyRegisterInSessionLabel()
+    {
+        $icon = Display::return_icon('students.gif', get_lang('Student'));
+
+        return Display::label($icon . ' ' . get_lang("AlreadyRegisteredToSession"), "info");
+    }
+
+    /**
+     * Get a icon for a session
+     * @param string $sessionName The session name
+     * @return string The icon
+     */
+    public function getSessionIcon($sessionName)
+    {
+        return Display::return_icon('window_list.png', $sessionName, null, ICON_SIZE_LARGE);
+    }
+
 }

+ 29 - 0
main/inc/lib/sessionmanager.lib.php

@@ -4882,4 +4882,33 @@ class SessionManager
         return false;
     }
 
+    /**
+     * Get the formatted date of a session by its start and end date
+     * @param array $sessionInfo The session information containing the start and end date
+     * @return string The formatted date
+     */
+    public static function getSessionFormattedDate($sessionInfo)
+    {
+        if ($sessionInfo['date_start'] == '0000-00-00' && $sessionInfo['date_end'] == '0000-00-00') {
+            return get_lang('NoTimeLimits');
+        } else {
+            $startDate = '';
+            $endDate = '';
+
+            if ($sessionInfo['date_start'] != '0000-00-00') {
+                $startDate = get_lang('From') . ' ' . api_format_date($sessionInfo['date_start'], DATE_FORMAT_LONG_NO_DAY);
+            } else {
+                $startDate = '';
+            }
+
+            if ($sessionInfo['date_end'] == '0000-00-00') {
+                $endDate = '';
+            } else {
+                $endDate = get_lang('Until') . ' ' . api_format_date($sessionInfo['date_end'], DATE_FORMAT_LONG_NO_DAY);
+            }
+
+            return "$startDate $endDate";
+        }
+    }
+
 }

+ 0 - 70
main/template/default/auth/courses_categories.php

@@ -211,45 +211,6 @@ $userInfo = api_get_user_info();
     </div>
 
     <div class="span9">
-        <?php if ($showSessions && $action == 'display_sessions') { ?>
-            <?php
-                if (!empty($browseSessions)) {
-                    foreach ($browseSessions as $session) {
-                        $sessionId = $session['id'];
-                        ?>
-                        <div class="well_border">
-                            <div class="row">
-                                <div class="span1">
-                                    <span class="thumbnail"><?php
-                                        $sessionIconParams = array(
-                                            'id' => 'session_img_' . $sessionId
-                                        );
-
-                                        echo Display::return_icon('window_list.png', $session['name'], $sessionIconParams, ICON_SIZE_LARGE);
-                                        ?></span>
-                                </div>
-                                <div class="span7 categories-course-description">
-                                    <h3><?php echo $session['name'] ?></h3>
-                                    <p><?php echo $session['coach_name'] ?></p>
-                                    <div>
-                                        <div class="course-list"></div>
-                                        <a class="btn btn-link courses-list-btn" id="showsesion_<?php echo $sessionId ?>" href="#"><?php echo Display::display_icon('nolines_plus.gif'); ?> <?php echo get_lang('Courses') ?></a>
-                                        <?php if ($session['is_subscribed']) { ?>
-                                            <?php echo displayAlreadyRegisterInSessionLabel(); ?>
-                                        <?php } else { ?>
-                                            <?php echo displayRegisterInSessionButton($session['name'], $userInfo); ?>
-                                        <?php } ?>
-                                    </div>
-                                </div>
-                            </div>
-                        </div>
-                        <?php
-                    }
-                } else {
-                    Display::display_warning_message(get_lang('ThereAreNoCoursesInThisCategory'));
-                }
-            ?>
-        <?php } ?>
         <?php if ($showCourses && $action != 'display_sessions') { ?>
         <?php if (!empty($message)) { Display::display_confirmation_message($message, false); }
         if (!empty($error)) { Display::display_error_message($error, false); }
@@ -456,35 +417,4 @@ function display_unregister_button($course, $stok, $search_term, $code)
     echo ' <a class="btn btn-primary" href="'. api_get_self().'?action=unsubscribe&amp;sec_token='.$stok.'&amp;unsubscribe='.$course['code'].'&amp;search_term='.$search_term.'&amp;category_code='.$code.'">'.get_lang('Unsubscribe').'</a>';
 }
 
-/**
- * Generate a label if the user has been  registered in session
- * @return string The label
- */
-function displayAlreadyRegisterInSessionLabel()
-{
-    $icon = Display::return_icon('students.gif', get_lang('Student'));
-
-    return Display::label($icon . ' ' . get_lang("AlreadyRegisteredToSession"), "info");
-}
 
-function displayRegisterInSessionButton($sessionName, $userInfo)
-{
-    $mailSubject = get_lang('SubscribeToSession') . " '$sessionName'";
-    
-    $mailMessage = get_lang('PleaseSubscribeToSession') . PHP_EOL . PHP_EOL;
-    $mailMessage = get_lang('Session') . ": $sessionName" . PHP_EOL . PHP_EOL;
-    $mailMessage.= get_lang('ContactInformation') . ':' . PHP_EOL;
-    $mailMessage.= get_lang('Name') . ": {$userInfo['complete_name']}" . PHP_EOL;
-    $mailMessage.= get_lang('Username') . ": {$userInfo['username']}" . PHP_EOL;
-    $mailMessage.= get_lang('Email') . ": {$userInfo['email']}" . PHP_EOL;
-
-    $mailParams = http_build_query(array(
-        'email_title' => $mailSubject,
-        'email_text' => $mailMessage
-    ));
-
-    return Display::tag('a', get_lang('Subscribe'), array(
-                'class' => 'btn btn-primary clickable_email_link',
-                'href' => "mailto:angelfqc.18@gmail.com&$mailParams"
-    ));
-}

+ 147 - 0
main/template/default/auth/sessions_catalog.tpl

@@ -0,0 +1,147 @@
+{% extends "default/layout/main.tpl" %}
+
+{% block body %}
+    <script type="text/javascript">
+        $(document).on('ready', function() {
+            $('#date').datepicker({
+                dateFormat: 'yy-mm-dd'
+            });
+
+            $('.accordion').on('show', function(e) {
+                var $target = $(e.target);
+                var $targetContent = $target.find('.accordion-inner');
+
+                $targetContent.empty();
+
+                var idParts = $target.attr('id').split('-');
+
+                var sessionId = parseInt(idParts[1], 10);
+
+                $.ajax('{{ web_session_courses_ajax_url }}', {
+                    data: {
+                        a: 'display_sessions_courses',
+                        session: sessionId
+                    },
+                    dataType: 'json',
+                    success: function(response) {
+                        var coursesUL = '';
+
+                        $.each(response, function(index, course) {
+                            coursesUL += '<li><strong>' + course.name + '</strong> ';
+
+                            if (course.coachName != '') {
+                                coursesUL += '(' + course.coachName + ')';
+                            }
+
+                            coursesUL += '</li>';
+                        });
+
+                        $targetContent.html('<ul>' + coursesUL + '</ul>');
+                    }
+                });
+            });
+        });
+    </script>
+
+    <div class="span3">
+        {% if showCourses %}
+            <div class="well">
+                {% if not hiddenLinks %}
+                    <form class="form-search" method="post" action="{{ api_get_self }}?action=subscribe&amp;hidden_links=0">
+                        <fieldset>
+                            <input type="hidden" name="sec_token" value="{{ searchToken }}">
+                            <input type="hidden" name="search_course" value="1" />
+                            <div class="control-group">
+                                <div class="controls">
+                                    <div class="input-append">
+                                        <input class="span2" type="text" name="search_term" value="{{ searchTerm }}" />
+                                        <button class="btn" type="submit">{{ texts.search }}</button>
+                                    </div>
+                                </div>
+                            </div>
+                        </fieldset>
+                    </form>
+                {% endif %}
+
+                {% if coursesCategoriesList is not empty %}
+                    <a class="btn" href="{{ api_get_self }}?action=display_random_courses">{{ texts.randomPick }}</a>
+                {% endif %}
+            </div>
+
+            {% if coursesCategoriesList is not empty %}
+                <div class="well">
+                    <ul class="nav nav-list">
+                        <li class="nav-header">{{ texts.courseCategories}}</li>
+
+                        {{ coursesCategoriesList }}
+                    </ul>
+                </div>
+            {% endif %}
+        {% endif %}
+
+        {% if showSessions %}
+            <div class="well">
+                <ul class="nav nav-list">
+                    <li class="nav-header">{{ texts.sessions }}</li>
+                    <li>
+                        <strong>{{ texts.sessionList }}</strong>
+                    </li>
+                    <li class="nav-header">{{ texts.searchSessions }}</li>
+                </ul>
+                <form class="form-search" method="post" action="{{ api_get_self }}?action=display_sessions">
+                    <div class="input-append">
+                        <input type="date" name="date" id="date" class="span2" value="{{ searchDate }}" readonly>
+                        <button class="btn" type="submit">{{ texts.search }}</button>
+                    </div>
+                </form>
+            </div>
+        {% endif %}
+    </div>
+    <div class="span9">
+        <div class="page-header">
+            <h2>{{ texts.sessionList }}</h2>
+        </div>
+
+        {% for session in sessions_blocks %}
+            <div class="well" id="session-{{ session.id }}">
+                <div class="row">
+                    <div class="span6">
+                        <div class="row">
+                            <div class="span1">
+                                <span class="thumbnail">
+                                    {{ session.icon }}
+                                </span>
+                            </div>
+                            <div class="span5">
+                                <h3>{{ session.name }}</h3>
+                                <p>{{ session.coach_name }}</p>
+                            </div>
+                        </div>
+                        <br>
+                        <div class="accordion" id="session-{{ session.id }}-accordion" style="margin-bottom: 0px;">
+                            <div class="accordion-group">
+                                <div class="accordion-heading">
+                                    <a class="accordion-toggle" data-toggle="collapse" data-parent="#session-{{ session.id }}-accordion" href="#session-{{ session.id }}-courses">
+                                        {{ texts.courseList }}
+                                    </a>
+                                </div>
+                                <div id="session-{{ session.id }}-courses" class="accordion-body collapse in">
+                                    <div class="accordion-inner"></div>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                    <div class="span2">
+                        <p class="lead">{{ session.date }}</p>
+                        {% if session.is_subscribed %}
+                            {{ already_subscribed_label }}
+                        {% else %}
+                            {{ session.subscribe_button }}
+                        {% endif %}
+                    </div>
+                </div>
+            </div>
+        {% endfor %}
+    </div>
+
+{% endblock %}