[svn r13110] Added ordering in the learnpath tool homepage

skala
Yannick Warnier 18 years ago
parent 142f776f6a
commit 39d111f8ba
  1. 93
      main/newscorm/learnpath.class.php
  2. 3
      main/newscorm/learnpathList.class.php
  3. 34
      main/newscorm/lp_controller.php
  4. 39
      main/newscorm/lp_list.php

@ -2742,7 +2742,98 @@ class learnpath {
}
return $display;
}
/**
* Move a learnpath up (display_order)
* @param integer Learnpath ID
*/
function move_up($lp_id)
{
$lp_table = Database::get_course_table(TABLE_LP_MAIN);
$sql = "SELECT * FROM $lp_table ORDER BY display_order";
$res = api_sql_query($sql);
if($res === false) return false;
$lps = array();
$lp_order = array();
$num = Database::num_rows($res);
//first check the order is correct, globally (might be wrong because
//of versions < 1.8.4)
if($num>0)
{
$i = 1;
$need_fix = false;
while($row = Database::fetch_array($res))
{
if($row['display_order'] != $i)
{ //if we find a gap in the order, we need to fix it
$need_fix = true;
$sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
$res_u = api_sql_query($sql_u);
}
$row['display_order'] = $i;
$lps[$row['id']] = $row;
$lp_order[$i] = $row['id'];
$i++;
}
}
if($num>1) //if there's only one element, no need to sort
{
$order = $lps[$lp_id]['display_order'];
if($order>1) //if it's the first element, no need to move up
{
$sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = ".$lp_order[$order-1];
$res_u1 = api_sql_query($sql_u1);
$sql_u2 = "UPDATE $lp_table SET display_order = ".($order-1)." WHERE id = ".$lp_id;
$res_u2 = api_sql_query($sql_u2);
}
}
}
/**
* Move a learnpath down (display_order)
* @param integer Learnpath ID
*/
function move_down($lp_id)
{
$lp_table = Database::get_course_table(TABLE_LP_MAIN);
$sql = "SELECT * FROM $lp_table ORDER BY display_order";
$res = api_sql_query($sql);
if($res === false) return false;
$lps = array();
$lp_order = array();
$num = Database::num_rows($res);
$max = 0;
//first check the order is correct, globally (might be wrong because
//of versions < 1.8.4)
if($num>0)
{
$i = 1;
$need_fix = false;
while($row = Database::fetch_array($res))
{
$max = $i;
if($row['display_order'] != $i)
{ //if we find a gap in the order, we need to fix it
$need_fix = true;
$sql_u = "UPDATE $lp_table SET display_order = $i WHERE id = ".$row['id'];
$res_u = api_sql_query($sql_u);
}
$row['display_order'] = $i;
$lps[$row['id']] = $row;
$lp_order[$i] = $row['id'];
$i++;
}
}
if($num>1) //if there's only one element, no need to sort
{
$order = $lps[$lp_id]['display_order'];
if($order<$max) //if it's the first element, no need to move up
{
$sql_u1 = "UPDATE $lp_table SET display_order = $order WHERE id = ".$lp_order[$order+1];
$res_u1 = api_sql_query($sql_u1);
$sql_u2 = "UPDATE $lp_table SET display_order = ".($order+1)." WHERE id = ".$lp_id;
$res_u2 = api_sql_query($sql_u2);
}
}
}
/**
* Updates learnpath attributes to point to the next element
* The last part is similar to set_current_item but processing the other way around

@ -35,7 +35,7 @@ class learnpathList {
}
$this->course_code = $course_code;
$this->user_id = $user_id;
$sql = "SELECT * FROM $lp_table ORDER BY name ASC";
$sql = "SELECT * FROM $lp_table ORDER BY display_order ASC, name ASC";
$res = api_sql_query($sql);
$names = array();
while ($row = Database::fetch_array($res))
@ -75,6 +75,7 @@ class learnpathList {
'lp_published' => $pub,
'lp_prevent_reinit' => $row['prevent_reinit'],
'lp_scorm_debug' => $row['debug'],
'lp_display_order' => $row['display_order'],
);
$names[$row['name']]=$row['id'];
}

@ -493,10 +493,42 @@ switch($_REQUEST['action'])
require('lp_list.php');
}
break;
case 'edit':
case 'move_lp_up': //change lp published status (visibility on homepage)
if(!api_is_allowed_to_edit()){
api_not_allowed(true);
}
if($debug>0) error_log('New LP - publish action triggered',0);
if(!$lp_found)
{
error_log('New LP - No learnpath given for publish',0);
require('lp_list.php');
}
else
{
learnpath::move_up($_REQUEST['lp_id']);
require('lp_list.php');
}
break;
case 'move_lp_down': //change lp published status (visibility on homepage)
if(!api_is_allowed_to_edit()){
api_not_allowed(true);
}
if($debug>0) error_log('New LP - publish action triggered',0);
if(!$lp_found){
error_log('New LP - No learnpath given for publish',0);
require('lp_list.php');
}
else
{
learnpath::move_down($_REQUEST['lp_id']);
require('lp_list.php');
}
break;
case 'edit':
if(!api_is_allowed_to_edit())
{
api_not_allowed(true);
}
if($debug>0) error_log('New LP - edit action triggered',0);
if(!$lp_found){ error_log('New LP - No learnpath given for edit',0); require('lp_list.php'); }
else{

@ -153,9 +153,10 @@ echo '<th>'.get_lang("Name").'</th>'."\n" .
'<th>'.get_lang("Progress")."</th>\n";
if (api_is_allowed_to_edit())
{
echo "<th>",get_lang("Description"),"</th>\n" .
"<th>",get_lang("ExportShort"),"</th>\n",
'<th>',get_lang("Modify"),"</th>\n";
echo '<th>'.get_lang("Description")."</th>\n" .
'<th>'.get_lang("ExportShort")."</th>\n" .
'<th>'.get_lang("Modify")."</th>\n" .
'<th>'.get_lang('Move')."</th>\n";
}
echo "</tr>\n";
@ -167,10 +168,12 @@ $list = new LearnpathList(api_get_user_id());
$flat_list = $list->get_flat_list();
$is_allowed_to_edit = api_is_allowed_to_edit();
$test_mode = api_get_setting('server_type');
$max = count($flat_list);
//var_dump($flat_list);
if (is_array($flat_list))
{
$counter = 0;
$current = 0;
foreach ($flat_list as $id => $details)
{
if(!$is_allowed_to_edit && $details['lp_visibility'] == 0)
@ -194,10 +197,12 @@ if (is_array($flat_list))
$dsp_export = '';
$dsp_edit = '';
$dsp_edit_close = '';
$dsp_delete = '';
$dsp_visible = '';
$dsp_default_view = '';
$dsp_debug = '';
$dsp_order = '';
if($display_progress_bar)
{
$dsp_progress = '<td>'.learnpath::get_progress_bar('%',learnpath::get_db_progress($id,api_get_user_id()),'').'</td>';
@ -236,7 +241,8 @@ if (is_array($flat_list))
/* edit title and description */
$dsp_edit = '<td align="center">';
$dsp_edit_close = '</td>';
/* DELETE COMMAND */
$dsp_delete = "<a href=\"lp_controller.php?".api_get_cidreq()."&action=delete&lp_id=$id\" " .
"onClick=\"return confirmation('".addslashes($dspFileName)."');\">" .
@ -323,12 +329,33 @@ if (is_array($flat_list))
'</a>&nbsp;';
}
}
if($details['lp_display_order'] == 1)
{
$dsp_order .= '<td><a href="lp_controller.php?'.api_get_cidreq().'&action=move_lp_down&lp_id='.$id.'">' .
'<img src="../img/arrow_down_0.gif" border="0" alt="'.get_lang("MoveDown").'" title="'.get_lang("MoveDown").'"/>' .
'</a><img src="../img/blanco.png" border="0" alt="" title="" /></td>';
}
elseif($current == $max-1) //last element
{
$dsp_order .= '<td><img src="../img/blanco.png" border="0" alt="" title="" /><a href="lp_controller.php?'.api_get_cidreq().'&action=move_lp_up&lp_id='.$id.'">' .
'<img src="../img/arrow_up_0.gif" border="0" alt="'.get_lang("MoveDown").'" title="'.get_lang("MoveDown").'"/>' .
'</a></td>';
}
else
{
$dsp_order .= '<td><a href="lp_controller.php?'.api_get_cidreq().'&action=move_lp_down&lp_id='.$id.'">' .
'<img src="../img/arrow_down_0.gif" border="0" alt="'.get_lang("MoveDown").'" title="'.get_lang("MoveDown").'"/>' .
'</a>&nbsp;';
$dsp_order .= '<a href="lp_controller.php?'.api_get_cidreq().'&action=move_lp_up&lp_id='.$id.'">' .
'<img src="../img/arrow_up_0.gif" border="0" alt="'.get_lang("MoveDown").'" title="'.get_lang("MoveDown").'"/>' .
'</a></td>';
}
} // end if($is_allowedToEdit)
//echo $dsp_line.$dsp_desc.$dsp_export.$dsp_edit.$dsp_delete.$dsp_visible;
echo $dsp_line.$dsp_progress.$dsp_desc.$dsp_export.$dsp_edit.$dsp_build.$dsp_visible.$dsp_publish.$dsp_reinit.$dsp_default_view.$dsp_force_commit.$dsp_debug.$dsp_delete;
echo $dsp_line.$dsp_progress.$dsp_desc.$dsp_export.$dsp_edit.$dsp_build.$dsp_visible.$dsp_publish.$dsp_reinit.$dsp_default_view.$dsp_force_commit.$dsp_debug.$dsp_delete.$dsp_close.$dsp_order;
//echo $dsp_line.$dsp_progress.$dsp_desc.$dsp_export.$dsp_edit.$dsp_build.$dsp_visible.$dsp_reinit.$dsp_force_commit.$dsp_delete;
echo "</tr>\n";
$current ++; //counter for number of elements treated
} // end foreach ($flat_list)
//TODO print some user-friendly message if counter is still = 0 to tell nothing can be displayd yet
}// end if ( is_array($flat_list)

Loading…
Cancel
Save