Procházet zdrojové kódy

Add description filter see BT#9642

Julio Montoya před 10 roky
rodič
revize
a082730009

+ 15 - 9
main/inc/ajax/model.ajax.php

@@ -12,10 +12,10 @@ $libpath = api_get_path(LIBRARY_PATH);
 // 1. Setting variables needed by jqgrid
 
 $action = $_GET['a'];
-$page   = intval($_REQUEST['page']); //page
-$limit  = intval($_REQUEST['rows']); //quantity of rows
-$sidx   = $_REQUEST['sidx'];         //index (field) to filter
-$sord   = $_REQUEST['sord'];         //asc or desc
+$page = intval($_REQUEST['page']); //page
+$limit = intval($_REQUEST['rows']); //quantity of rows
+$sidx = $_REQUEST['sidx'];         //index (field) to filter
+$sord = $_REQUEST['sord'];         //asc or desc
 
 if (strpos(strtolower($sidx), 'asc') !== false) {
     $sidx = str_replace(array('asc', ','), '', $sidx);
@@ -289,7 +289,9 @@ switch ($action) {
         $count = get_count_exam_hotpotatoes_results($hotpot_path);
         break;
     case 'get_sessions_tracking':
-        $keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : null;
+        $keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : '';
+        $description = isset($_REQUEST['description']) ? $_REQUEST['description'] : '';
+
         if (api_is_drh()) {
             $count = SessionManager::get_sessions_followed_by_drh(
                 api_get_user_id(),
@@ -299,7 +301,8 @@ switch ($action) {
                 false,
                 false,
                 null,
-                $keyword
+                $keyword,
+                $description
             );
         } else {
             // Sessions for the coach
@@ -308,7 +311,8 @@ switch ($action) {
                 null,
                 null,
                 true,
-                $keyword
+                $keyword,
+                $description
             );
         }
         break;
@@ -720,7 +724,8 @@ switch ($action) {
                 false,
                 false,
                 null,
-                $keyword
+                $keyword,
+                $description
             );
         } else {
             // Sessions for the coach
@@ -729,7 +734,8 @@ switch ($action) {
                 $start,
                 $limit,
                 false,
-                $keyword
+                $keyword,
+                $description
             );
         }
 

+ 20 - 7
main/inc/lib/sessionmanager.lib.php

@@ -2827,6 +2827,8 @@ class SessionManager
      * @param bool $getOnlySessionId
      * @param bool $getSql
      * @param string $orderCondition
+     * @param string $description
+     *
      * @return array sessions
      */
     public static function get_sessions_followed_by_drh(
@@ -2837,7 +2839,8 @@ class SessionManager
         $getOnlySessionId = false,
         $getSql = false,
         $orderCondition = null,
-        $keyword = null
+        $keyword = '',
+        $description = ''
     ) {
         return self::getSessionsFollowedByUser(
             $userId,
@@ -2848,7 +2851,8 @@ class SessionManager
             $getOnlySessionId,
             $getSql,
             $orderCondition,
-            $keyword
+            $keyword,
+            $description
         );
     }
 
@@ -2862,6 +2866,7 @@ class SessionManager
      * @param bool $getSql
      * @param string $orderCondition
      * @param string $keyword
+     * @param string $description
      * @return array sessions
      */
     public static function getSessionsFollowedByUser(
@@ -2873,11 +2878,12 @@ class SessionManager
         $getOnlySessionId = false,
         $getSql = false,
         $orderCondition = null,
-        $keyword = null
+        $keyword = '',
+        $description = ''
     ) {
         // Database Table Definitions
-        $tbl_session 			= Database::get_main_table(TABLE_MAIN_SESSION);
-        $tbl_session_rel_user 	= Database::get_main_table(TABLE_MAIN_SESSION_USER);
+        $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
+        $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
         $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
         $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
 
@@ -2934,12 +2940,19 @@ class SessionManager
                 break;
         }
 
-        $keywordCondition = null;
+        $keywordCondition = '';
         if (!empty($keyword)) {
             $keyword = Database::escape_string($keyword);
             $keywordCondition = " AND (s.name LIKE '%$keyword%' ) ";
         }
-        $whereConditions .= $keywordCondition;
+
+        $descriptionCondition = '';
+        if (!empty($description)) {
+            $description = Database::escape_string($description);
+            $descriptionCondition = " AND (s.description LIKE '%$description%' ) ";
+        }
+
+        $whereConditions .= $descriptionCondition.$keywordCondition;
 
         $subQuery = $sessionQuery.$courseSessionQuery;
 

+ 19 - 4
main/inc/lib/tracking.lib.php

@@ -2910,7 +2910,8 @@ class Tracking
      * @param int $start
      * @param int $limit
      * @param bool $getCount
-     * @param null $keyword
+     * @param string $keyword
+     * @param string $description
      * @return mixed
      */
     public static function get_sessions_coached_by_user(
@@ -2918,7 +2919,8 @@ class Tracking
         $start = 0,
         $limit = 0,
         $getCount = false,
-        $keyword = null
+        $keyword = '',
+        $description = ''
     ) {
         // table definition
         $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
@@ -2941,6 +2943,12 @@ class Tracking
             $keywordCondition = " AND (name LIKE '%$keyword%' ) ";
         }
 
+        $descriptionCondition = '';
+        if (!empty($description)) {
+            $description = Database::escape_string($description);
+            $descriptionCondition = " AND (description LIKE '%$description%' ) ";
+        }
+
         $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
         $access_url_id = api_get_current_access_url_id();
 
@@ -2950,7 +2958,11 @@ class Tracking
                 SELECT DISTINCT id, name, date_start, date_end
                 FROM $tbl_session session INNER JOIN $tbl_session_rel_access_url session_rel_url
                 ON (session.id = session_rel_url.session_id)
-                WHERE id_coach = $coach_id AND access_url_id = $access_url_id $keywordCondition
+                WHERE
+                    id_coach = $coach_id AND
+                    access_url_id = $access_url_id
+                    $keywordCondition
+                    $descriptionCondition
             UNION
                 SELECT DISTINCT session.id, session.name, session.date_start, session.date_end
                 FROM $tbl_session as session
@@ -2960,7 +2972,10 @@ class Tracking
                     session_course_user.status=2
                 INNER JOIN $tbl_session_rel_access_url session_rel_url
                 ON (session.id = session_rel_url.session_id)
-                WHERE access_url_id = $access_url_id $keywordCondition
+                WHERE
+                    access_url_id = $access_url_id
+                    $keywordCondition
+                    $descriptionCondition
             ) as sessions $limitCondition
             ";
 

+ 3 - 0
main/install/configuration.dist.php

@@ -299,3 +299,6 @@ $_configuration['system_stable']     = NEW_VERSION_STABLE;
 // User block -> Add user
 // Course Sessions block -> Training session list
 $_configuration['limit_session_admin_role'] = false;
+// Show session description
+//$_configuration['show_session_description'] = false;
+

+ 12 - 3
main/mySpace/session.php

@@ -1,9 +1,11 @@
 <?php
 /* For licensing terms, see /license.txt */
-/*
+
+/**
  * Sessions reporting
  * @package chamilo.reporting
  */
+
 ob_start();
 // name of the language file that needs to be included
 $language_file = array('registration', 'index', 'trad4all', 'tracking', 'admin');
@@ -89,15 +91,22 @@ if (api_is_drh() || api_is_session_admin() || api_is_platform_admin()) {
 
 $form = new FormValidator('search_course', 'get', api_get_path(WEB_CODE_PATH).'mySpace/session.php');
 $form->addElement('text', 'keyword', get_lang('Keyword'));
+$setting = api_get_configuration_value('show_session_description');
+if ($setting) {
+    $form->addElement('text', 'description', get_lang('Description'));
+}
+
 $form->addElement('button', 'submit', get_lang('Search'));
 $form->addElement('hidden', 'session_id', $sessionId);
-$keyword = null;
+$keyword = '';
+$description = '';
 if ($form->validate()) {
     $keyword = $form->getSubmitValue('keyword');
+    $description = $form->getSubmitValue('description');
 }
 $form->setDefaults(array('keyword' => $keyword));
 
-$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions_tracking&keyword='.Security::remove_XSS($keyword);
+$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions_tracking&keyword='.Security::remove_XSS($keyword).'&description='.$description;
 
 $columns = array(
     get_lang('Title'),