Add "session_list_order" setting see BT#13750

- Requires to uncomment the "position" variable in:
Session.php entity

- Requires DB change.
pull/2487/head
jmontoyaa 8 years ago
parent f9471264e5
commit 39bbae3c5d
  1. 19
      main/inc/ajax/session.ajax.php
  2. 13
      main/inc/lib/sessionmanager.lib.php
  3. 16
      main/inc/lib/usermanager.lib.php
  4. 4
      main/install/configuration.dist.php
  5. 26
      main/session/session_list.php
  6. 26
      src/Chamilo/CoreBundle/Entity/Session.php

@ -23,6 +23,25 @@ switch ($action) {
unset($list_sessions);
}
break;
case 'order':
api_protect_admin_script();
$allowOrder = api_get_configuration_value('session_list_order');
if ($allowOrder) {
$order = isset($_GET['order']) ? $_GET['order'] : [];
$order = json_decode($order);
if (!empty($order)) {
$table = Database::get_main_table(TABLE_MAIN_SESSION);
foreach ($order as $data) {
if (isset($data->order) && isset($data->id)) {
$orderId = (int)$data->order;
$sessionId = (int)$data->id;
$sql = "UPDATE $table SET position = $orderId WHERE id = $sessionId ";
Database::query($sql);
}
}
}
}
break;
case 'search_session':
if (api_is_platform_admin()) {
$sessions = SessionManager::get_sessions_list(

@ -541,6 +541,11 @@ class SessionManager
if ($showCountUsers) {
$query .= ' GROUP by s.id';
}
$allowOrder = api_get_configuration_value('session_list_order');
if ($allowOrder) {
$order = ' ORDER BY position ASC';
}
$query .= $order;
$query .= $limit;
$result = Database::query($query);
@ -7821,6 +7826,7 @@ class SessionManager
switch ($list_type) {
case 'simple':
$columns = array(
'#',
get_lang('Name'),
get_lang('Category'),
get_lang('SessionDisplayStartDate'),
@ -7832,6 +7838,13 @@ class SessionManager
);
$column_model = array(
array(
'name' => 'id',
'index' => 's.id',
'width' => '160',
'width' => '160',
'hidden' => 'true',
),
array(
'name' => 'name',
'index' => 's.name',

@ -2785,7 +2785,13 @@ class UserManager
$ignoreTimeLimit = false
) {
if ($user_id != strval(intval($user_id))) {
return array();
return [];
}
$allowOrder = api_get_configuration_value('session_list_order');
$position = '';
if ($allowOrder) {
$position = ', s.position AS position ';
}
// Get the list of sessions per user
@ -2806,6 +2812,7 @@ class UserManager
sc.dateEnd AS session_category_date_end,
s.coachAccessStartDate AS coach_access_start_date,
s.coachAccessEndDate AS coach_access_end_date
$position
FROM ChamiloCoreBundle:Session AS s
LEFT JOIN ChamiloCoreBundle:SessionRelCourseRelUser AS scu WITH scu.session = s
INNER JOIN ChamiloCoreBundle:AccessUrlRelSession AS url WITH url.sessionId = s.id
@ -2817,6 +2824,11 @@ class UserManager
if ($showAllSessions) {
$order = "ORDER BY s.accessStartDate";
}
if ($allowOrder) {
$order = "ORDER BY s.position";
}
$dql .= $order;
$dql = Database::getManager()
@ -2832,10 +2844,8 @@ class UserManager
foreach ($sessionData as $row) {
$session_id = $row['id'];
$coachList = SessionManager::getCoachesBySession($session_id);
$categoryStart = $row['session_category_date_start'] ? $row['session_category_date_start']->format('Y-m-d') : '';
$categoryEnd = $row['session_category_date_end'] ? $row['session_category_date_end']->format('Y-m-d') : '';
$courseList = self::get_courses_list_by_session(
$user_id,
$session_id

@ -717,6 +717,10 @@ $_configuration['gradebook_badge_sidebar'] = [
// Add user extra fields in report: main/mySpace/exercise_category_report.php
//$_configuration['exercise_category_report_user_extra_fields'] = ['fields' => ['skype', 'rssfeeds']];
// Order sessions
// Requires DB change: ALTER TABLE session ADD COLUMN position INT DEFAULT 0;
// Requires edit Entity Session: src/Chamilo/CoreBundle/Entity/Session.php uncomment "position" variable.
//$_configuration['session_list_order'] = false;
// ------ Custom DB changes
// Add user activation by confirmation email

@ -152,6 +152,8 @@ $action_links = 'function action_formatter(cellvalue, options, rowObject) {
}';
$urlAjaxExtraField = api_get_path(WEB_AJAX_PATH).'extra_field.ajax.php?1=1';
$allowOrder = api_get_configuration_value('session_list_order');
$orderUrl = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=order';
?>
<script>
@ -193,7 +195,6 @@ $urlAjaxExtraField = api_get_path(WEB_AJAX_PATH).'extra_field.ajax.php?1=1';
var second_filters = [];
$(function() {
date_pick_today = function(elem) {
$(elem).datetimepicker({dateFormat: "yy-mm-dd"});
$(elem).datetimepicker('setDate', (new Date()));
@ -286,6 +287,29 @@ $urlAjaxExtraField = api_get_path(WEB_AJAX_PATH).'extra_field.ajax.php?1=1';
original_cols = grid.jqGrid('getGridParam', 'colModel');
<?php if ($allowOrder) { ?>
options = {
update: function (e, ui) {
var rowNum = jQuery("#sessions").getGridParam('rowNum');
var page = jQuery("#sessions").getGridParam('page');
page = page - 1;
var start = rowNum * page;
var list = jQuery('#sessions').jqGrid('getRowData');
var orderList = [];
$(list).each(function(index, e) {
index = index + start;
orderList.push({'order':index, 'id': e.id});
});
orderList = JSON.stringify(orderList);
$.get("<?php echo $orderUrl ?>", "order="+orderList, function (result) {
console.log(result);
});
}
};
// Sortable rows
grid.jqGrid('sortableRows', options);
<?php } ?>
grid.jqGrid('navGrid','#sessions_pager',
{edit:false,add:false,del:false},
{height:280,reloadAfterSubmit:false}, // edit options

@ -158,6 +158,14 @@ class Session
*/
private $coachAccessEndDate;
/**
* Only available when "session_list_order" setting is on
* @var integer
*
* @ORM\Column(name="position", type="integer", nullable=false)
*/
//private $position;
/**
* @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CItemProperty", mappedBy="session")
**/
@ -1122,4 +1130,22 @@ class Session
{
return $this->studentPublications;
}
/**
* @return int
*/
public function getPosition()
{
return $this->position;
}
/**
* @param int $position
* @return Session
*/
public function setPosition($position)
{
$this->position = $position;
return $this;
}
}

Loading…
Cancel
Save