Skip to content

Commit 39bbae3

Browse files
committed
Add "session_list_order" setting see BT#13750
- Requires to uncomment the "position" variable in: Session.php entity - Requires DB change.
1 parent f947126 commit 39bbae3

File tree

6 files changed

+100
-4
lines changed

6 files changed

+100
-4
lines changed

main/inc/ajax/session.ajax.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,25 @@
2323
unset($list_sessions);
2424
}
2525
break;
26+
case 'order':
27+
api_protect_admin_script();
28+
$allowOrder = api_get_configuration_value('session_list_order');
29+
if ($allowOrder) {
30+
$order = isset($_GET['order']) ? $_GET['order'] : [];
31+
$order = json_decode($order);
32+
if (!empty($order)) {
33+
$table = Database::get_main_table(TABLE_MAIN_SESSION);
34+
foreach ($order as $data) {
35+
if (isset($data->order) && isset($data->id)) {
36+
$orderId = (int)$data->order;
37+
$sessionId = (int)$data->id;
38+
$sql = "UPDATE $table SET position = $orderId WHERE id = $sessionId ";
39+
Database::query($sql);
40+
}
41+
}
42+
}
43+
}
44+
break;
2645
case 'search_session':
2746
if (api_is_platform_admin()) {
2847
$sessions = SessionManager::get_sessions_list(

main/inc/lib/sessionmanager.lib.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,11 @@ public static function get_sessions_admin(
541541
if ($showCountUsers) {
542542
$query .= ' GROUP by s.id';
543543
}
544+
$allowOrder = api_get_configuration_value('session_list_order');
545+
if ($allowOrder) {
546+
$order = ' ORDER BY position ASC';
547+
}
548+
544549
$query .= $order;
545550
$query .= $limit;
546551
$result = Database::query($query);
@@ -7821,6 +7826,7 @@ public static function getGridColumns(
78217826
switch ($list_type) {
78227827
case 'simple':
78237828
$columns = array(
7829+
'#',
78247830
get_lang('Name'),
78257831
get_lang('Category'),
78267832
get_lang('SessionDisplayStartDate'),
@@ -7832,6 +7838,13 @@ public static function getGridColumns(
78327838
);
78337839

78347840
$column_model = array(
7841+
array(
7842+
'name' => 'id',
7843+
'index' => 's.id',
7844+
'width' => '160',
7845+
'width' => '160',
7846+
'hidden' => 'true',
7847+
),
78357848
array(
78367849
'name' => 'name',
78377850
'index' => 's.name',

main/inc/lib/usermanager.lib.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2785,7 +2785,13 @@ public static function get_sessions_by_category(
27852785
$ignoreTimeLimit = false
27862786
) {
27872787
if ($user_id != strval(intval($user_id))) {
2788-
return array();
2788+
return [];
2789+
}
2790+
2791+
$allowOrder = api_get_configuration_value('session_list_order');
2792+
$position = '';
2793+
if ($allowOrder) {
2794+
$position = ', s.position AS position ';
27892795
}
27902796

27912797
// Get the list of sessions per user
@@ -2806,6 +2812,7 @@ public static function get_sessions_by_category(
28062812
sc.dateEnd AS session_category_date_end,
28072813
s.coachAccessStartDate AS coach_access_start_date,
28082814
s.coachAccessEndDate AS coach_access_end_date
2815+
$position
28092816
FROM ChamiloCoreBundle:Session AS s
28102817
LEFT JOIN ChamiloCoreBundle:SessionRelCourseRelUser AS scu WITH scu.session = s
28112818
INNER JOIN ChamiloCoreBundle:AccessUrlRelSession AS url WITH url.sessionId = s.id
@@ -2817,6 +2824,11 @@ public static function get_sessions_by_category(
28172824
if ($showAllSessions) {
28182825
$order = "ORDER BY s.accessStartDate";
28192826
}
2827+
2828+
if ($allowOrder) {
2829+
$order = "ORDER BY s.position";
2830+
}
2831+
28202832
$dql .= $order;
28212833

28222834
$dql = Database::getManager()
@@ -2832,10 +2844,8 @@ public static function get_sessions_by_category(
28322844
foreach ($sessionData as $row) {
28332845
$session_id = $row['id'];
28342846
$coachList = SessionManager::getCoachesBySession($session_id);
2835-
28362847
$categoryStart = $row['session_category_date_start'] ? $row['session_category_date_start']->format('Y-m-d') : '';
28372848
$categoryEnd = $row['session_category_date_end'] ? $row['session_category_date_end']->format('Y-m-d') : '';
2838-
28392849
$courseList = self::get_courses_list_by_session(
28402850
$user_id,
28412851
$session_id

main/install/configuration.dist.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,10 @@
717717
// Add user extra fields in report: main/mySpace/exercise_category_report.php
718718
//$_configuration['exercise_category_report_user_extra_fields'] = ['fields' => ['skype', 'rssfeeds']];
719719

720+
// Order sessions
721+
// Requires DB change: ALTER TABLE session ADD COLUMN position INT DEFAULT 0;
722+
// Requires edit Entity Session: src/Chamilo/CoreBundle/Entity/Session.php uncomment "position" variable.
723+
//$_configuration['session_list_order'] = false;
720724

721725
// ------ Custom DB changes
722726
// Add user activation by confirmation email

main/session/session_list.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@
152152
}';
153153

154154
$urlAjaxExtraField = api_get_path(WEB_AJAX_PATH).'extra_field.ajax.php?1=1';
155+
$allowOrder = api_get_configuration_value('session_list_order');
156+
$orderUrl = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=order';
155157

156158
?>
157159
<script>
@@ -193,7 +195,6 @@ function show_cols(grid, added_cols) {
193195
var second_filters = [];
194196

195197
$(function() {
196-
197198
date_pick_today = function(elem) {
198199
$(elem).datetimepicker({dateFormat: "yy-mm-dd"});
199200
$(elem).datetimepicker('setDate', (new Date()));
@@ -286,6 +287,29 @@ function show_cols(grid, added_cols) {
286287

287288
original_cols = grid.jqGrid('getGridParam', 'colModel');
288289

290+
<?php if ($allowOrder) { ?>
291+
options = {
292+
update: function (e, ui) {
293+
var rowNum = jQuery("#sessions").getGridParam('rowNum');
294+
var page = jQuery("#sessions").getGridParam('page');
295+
page = page - 1;
296+
var start = rowNum * page;
297+
var list = jQuery('#sessions').jqGrid('getRowData');
298+
var orderList = [];
299+
$(list).each(function(index, e) {
300+
index = index + start;
301+
orderList.push({'order':index, 'id': e.id});
302+
});
303+
orderList = JSON.stringify(orderList);
304+
$.get("<?php echo $orderUrl ?>", "order="+orderList, function (result) {
305+
console.log(result);
306+
});
307+
}
308+
};
309+
// Sortable rows
310+
grid.jqGrid('sortableRows', options);
311+
<?php } ?>
312+
289313
grid.jqGrid('navGrid','#sessions_pager',
290314
{edit:false,add:false,del:false},
291315
{height:280,reloadAfterSubmit:false}, // edit options

src/Chamilo/CoreBundle/Entity/Session.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ class Session
158158
*/
159159
private $coachAccessEndDate;
160160

161+
/**
162+
* Only available when "session_list_order" setting is on
163+
* @var integer
164+
*
165+
* @ORM\Column(name="position", type="integer", nullable=false)
166+
*/
167+
//private $position;
168+
161169
/**
162170
* @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CItemProperty", mappedBy="session")
163171
**/
@@ -1122,4 +1130,22 @@ public function getStudentPublications()
11221130
{
11231131
return $this->studentPublications;
11241132
}
1133+
1134+
/**
1135+
* @return int
1136+
*/
1137+
public function getPosition()
1138+
{
1139+
return $this->position;
1140+
}
1141+
1142+
/**
1143+
* @param int $position
1144+
* @return Session
1145+
*/
1146+
public function setPosition($position)
1147+
{
1148+
$this->position = $position;
1149+
return $this;
1150+
}
11251151
}

0 commit comments

Comments
 (0)