Adding Subscribe user to LP option see BT#5765

skala
Julio Montoya 13 years ago
parent 020277ddc4
commit b52154a9e3
  1. 43
      main/newscorm/learnpath.class.php
  2. 4
      main/newscorm/learnpathList.class.php
  3. 2
      main/newscorm/lp_controller.php
  4. 5
      main/newscorm/lp_edit.php
  5. 28
      main/newscorm/lp_list.php
  6. 92
      main/newscorm/lp_subscribe_users.php
  7. 2
      main/pages/index.php
  8. 44
      main/template/default/learnpath/subscribe_users.tpl

@ -69,6 +69,7 @@ class learnpath
public $lp_view_session_id = 0; // The specific view might be bound to a session.
public $prerequisite = 0;
public $use_max_score = 1; // 1 or 0
public $subscribe_users = 0;
public $created_on = '';
public $modified_on = '';
public $publicated_on = '';
@ -157,6 +158,7 @@ class learnpath
$this->hide_toc_frame = $row['hide_toc_frame'];
$this->lp_session_id = $row['session_id'];
$this->use_max_score = $row['use_max_score'];
$this->subscribe_users = $row['subscribe_users'];
$this->created_on = $row['created_on'];
$this->modified_on = $row['modified_on'];
$this->ref = $row['ref'];
@ -2332,13 +2334,13 @@ class learnpath
* @param string Course code (optional)
* @return bool True if
*/
public static function is_lp_visible_for_student($lp_id, $student_id, $course = null)
public static function is_lp_visible_for_student($lp_id, $student_id, $course_code = null)
{
$lp_id = (int)$lp_id;
$course = api_get_course_info($course);
$course_info = api_get_course_info($course_code);
$tbl_learnpath = Database :: get_course_table(TABLE_LP_MAIN);
// Get current prerequisite
$sql = "SELECT id, prerequisite, publicated_on, expired_on FROM $tbl_learnpath WHERE c_id = ".$course['real_id']." AND id = $lp_id";
$sql = "SELECT id, prerequisite, publicated_on, expired_on FROM $tbl_learnpath WHERE c_id = ".$course_info['real_id']." AND id = $lp_id";
$rs = Database::query($sql);
$now = time();
if (Database::num_rows($rs) > 0) {
@ -2347,6 +2349,7 @@ class learnpath
$is_visible = true;
$progress = 0;
//Checking LP prerequisites
if (!empty($prerequisite)) {
$progress = self::get_db_progress($prerequisite, $student_id, '%', '', false, api_get_session_id());
$progress = intval($progress);
@ -2358,7 +2361,7 @@ class learnpath
// Also check the time availability of the LP
if ($is_visible) {
//Adding visibility reestrinctions
//Adding visibility restrictions
if (!empty($row['publicated_on']) && $row['publicated_on'] != '0000-00-00 00:00:00') {
if ($now < api_strtotime($row['publicated_on'], 'UTC')) {
//api_not_allowed();
@ -4751,6 +4754,12 @@ class learnpath
return $this->max_attempts;
}
public function get_subscribe_users()
{
return $this->subscribe_users;
}
public function check_attempts()
{
$max_attempts = $this->get_max_attempts();
@ -4803,6 +4812,28 @@ class learnpath
$this->set_attempt_mode($mode);
}
/**
* Sets subscribe_users
* @param string $value Optional string giving the new location of this learnpath
* @return bool True on success / False on error
*/
public function set_subscribe_users($value = 0)
{
if ($this->debug > 0) {
error_log('New LP - In learnpath::set_subscribe_users()', 0);
}
$this->subscribe_users = intval($value);;
$lp_table = Database :: get_course_table(TABLE_LP_MAIN);
$lp_id = $this->get_id();
$sql = "UPDATE $lp_table SET subscribe_users = '".$this->subscribe_users."' WHERE c_id = ".$this->course_int_id." AND id = '$lp_id'";
if ($this->debug > 2) {
error_log('New LP - lp updated with new set_subscribe_users : '.$this->subscribe_users, 0);
}
Database::query($sql);
return true;
}
/**
* Sets use_max_score
* @param string Optional string giving the new location of this learnpath
@ -4813,8 +4844,7 @@ class learnpath
if ($this->debug > 0) {
error_log('New LP - In learnpath::set_use_max_score()', 0);
}
$use_max_score = intval($use_max_score);
$this->use_max_score = $use_max_score;
$this->use_max_score = intval($use_max_score);
$lp_table = Database :: get_course_table(TABLE_LP_MAIN);
$lp_id = $this->get_id();
$sql = "UPDATE $lp_table SET use_max_score = '".$this->use_max_score."' WHERE c_id = ".$this->course_int_id." AND id = '$lp_id'";
@ -4823,7 +4853,6 @@ class learnpath
error_log('New LP - lp updated with new use_max_score : '.$this->use_max_score, 0);
}
Database::query($sql);
return true;
}

@ -119,6 +119,7 @@ class learnpathList {
} else {
$row['expired_on'] = '';
}
//@todo user LP object
$this->list[$row['id']] = array(
'lp_type' => $row['lp_type'],
'lp_session' => $row['session_id'],
@ -144,7 +145,8 @@ class learnpathList {
'modified_on' => $row['modified_on'],
'publicated_on' => $row['publicated_on'],
'expired_on' => $row['expired_on'],
'category_id' => $row['category_id']
'category_id' => $row['category_id'],
'subscribe_users' => $row['subscribe_users']
);
$names[$row['name']] = $row['id'];
}

@ -688,7 +688,7 @@ switch ($action) {
$_SESSION['oLP']->set_prerequisite($_REQUEST['prerequisites']);
$_SESSION['oLP']->set_use_max_score($_REQUEST['use_max_score']);
$_SESSION['oLP']->set_subscribe_users($_REQUEST['subscribe_users']);
$_SESSION['oLP']->set_max_attempts($_REQUEST['max_attempts']);
if (isset($_REQUEST['activate_start_date_check']) && $_REQUEST['activate_start_date_check'] == 1) {

@ -172,6 +172,8 @@ if (api_is_platform_admin()) {
$defaults['use_max_score'] = $_SESSION['oLP']->use_max_score;
}
$form->addElement('checkbox', 'subscribe_users', null, get_lang('SubscribeUsersToLP'));
//Submit button
$form->addElement('style_submit_button', 'Submit', get_lang('SaveLPSettings'),'class="save"');
@ -180,8 +182,9 @@ $form->addElement('hidden', 'action', 'update_lp');
$form->addElement('hidden', 'lp_id', $_SESSION['oLP']->get_id());
$defaults['publicated_on'] = ($publicated_on!='0000-00-00 00:00:00' && !empty($publicated_on))? api_get_local_time($publicated_on) : date('Y-m-d 12:00:00');
$defaults['expired_on'] = ($expired_on !='0000-00-00 00:00:00' && !empty($expired_on) )? api_get_local_time($expired_on): date('Y-m-d 12:00:00',time()+84600);
$defaults['expired_on'] = ($expired_on !='0000-00-00 00:00:00' && !empty($expired_on) ) ? api_get_local_time($expired_on): date('Y-m-d 12:00:00', time()+84600);
$defaults['max_attempts'] = $_SESSION['oLP']->get_max_attempts();
$defaults['subscribe_users'] = $_SESSION['oLP']->get_subscribe_users();
$form->setDefaults($defaults);
echo '<div class="row">';

@ -103,7 +103,6 @@ if ($is_allowed_to_edit) {
/* DISPLAY SCORM LIST */
$categories_temp = learnpath::get_categories(api_get_course_int_id());
$category_test = new Entity\EntityCLpCategory;
@ -155,10 +154,10 @@ foreach ($categories as $item) {
$max = count($flat_list);
$counter = 0;
$current = 0;
$autolunch_exists = false;
$autolaunch_exists = false;
foreach ($flat_list as $id => $details) {
// Validacion when belongs to a session
// Validation when belongs to a session
$session_img = api_get_session_image($details['lp_session'], $_user['status']);
if (!$is_allowed_to_edit && $details['lp_visibility'] == 0) {
@ -353,7 +352,7 @@ foreach ($categories as $item) {
}
}
/* DEBUG */
/* Debug */
if ($test_mode == 'test' or api_is_platform_admin()) {
if ($details['lp_scorm_debug'] == 1) {
@ -379,11 +378,17 @@ foreach ($categories as $item) {
//Copy
$copy = Display::url(Display::return_icon('cd_copy.png', get_lang('Copy'), array(), ICON_SIZE_SMALL), api_get_self()."?".api_get_cidreq()."&action=copy&lp_id=$id");
//Subscribe users
$subscribe_users = null;
if ($details['subscribe_users'] == 1) {
$subscribe_users = Display::url(Display::return_icon('add.png', get_lang('AddUsers')), "lp_subscribe_users.php?lp_id=$id");
}
/* Auto Lunch LP code */
$lp_auto_lunch_icon = '';
if (api_get_course_setting('enable_lp_auto_launch') == 1) {
if ($details['autolaunch'] == 1 && $autolunch_exists == false) {
$autolunch_exists = true;
if ($details['autolaunch'] == 1 && $autolaunch_exists == false) {
$autolaunch_exists = true;
$lp_auto_lunch_icon = '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=auto_launch&status=0&lp_id='.$id.'">
<img src="../img/launch.png" border="0" title="'.get_lang('DisableLPAutoLaunch').'" /></a>';
} else {
@ -407,7 +412,6 @@ foreach ($categories as $item) {
$dsp_delete = Display::return_icon('delete_na.png', get_lang('LearnpathDeleteLearnpath'), '', ICON_SIZE_SMALL);
}
/* COLUMN ORDER */
// Only active while session mode is not active
@ -440,14 +444,14 @@ foreach ($categories as $item) {
$export_icon = ' <a href="'.api_get_self().'?'.api_get_cidreq().'&action=export_to_pdf&lp_id='.$id.'">'.Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_SMALL).'</a>';
}
echo $dsp_line.$start_time.$end_time.$dsp_progress.$dsp_desc.$dsp_export.$dsp_edit.$dsp_build.$dsp_edit_lp.$dsp_visible.$dsp_publish.$dsp_reinit.
echo $dsp_line.$start_time.$end_time.$dsp_progress.$dsp_desc.$dsp_export.$dsp_edit.$dsp_build.$dsp_edit_lp.$dsp_visible.$dsp_publish.$subscribe_users.$dsp_reinit.
$dsp_default_view.$dsp_debug.$dsp_disk.$copy.$lp_auto_lunch_icon.$export_icon.$dsp_delete.$dsp_order.$dsp_edit_close;
$lp_showed = true;
echo "</tr>";
$current++; //counter for number of elements treated
} // end foreach ($flat_list)
// TODO: Erint some user-friendly message if counter is still = 0 to tell nothing can be display yet.
// TODO: Some user-friendly message if counter is still = 0 to tell nothing can be display yet.
echo "</table>";
}
}
@ -465,6 +469,6 @@ $course_info = api_get_course_info();
learnpath::generate_learning_path_folder($course_info);
//Deleting the objects
Session::erase('oLP');
Session::erase('lpobject');
Display::display_footer();
Session::erase('oLP');
Session::erase('lpobject');
Display::display_footer();

@ -0,0 +1,92 @@
<?php
use Silex\Application;
use Symfony\Component\HttpFoundation\Response;
require_once '../inc/global.inc.php';
class SubscribeUserToLP {
function indexAction(Application $app) {
$request = $app['request'];
$sessionId = api_get_session_id();
$lpId = $request->get('lp_id');
if (empty($lpId)) {
var_dump($lpId);
//return $app->redirect('lp_controller.php');
}
$course = $app['orm.em']->getRepository('Entity\EntityCourse')->find(api_get_course_int_id());
$subscribedUsers = $app['orm.em']->getRepository('Entity\EntityCourse')->getSubscribedStudents($course);
$subscribedUsers = $subscribedUsers->getQuery();
$subscribedUsers = $subscribedUsers->execute();
$choices = array();
foreach ($subscribedUsers as $user) {
$choices[$user->getUserId()] = $user->getCompleteName();
}
$subscribedUsersInLp = $app['orm.em']->getRepository('Entity\EntityCItemProperty')->getUsersSubscribedToItem('learnpath', $lpId, $course);
$selectedChoices = array();
foreach ($subscribedUsersInLp as $itemProperty) {
$userId = $itemProperty->getToUserId();
$user = $app['orm.em']->getRepository('Entity\EntityUser')->find($userId);
$selectedChoices[$user->getUserId()] = $user->getCompleteName();
if (isset($choices[$user->getUserId()])) {
unset($choices[$user->getUserId()]);
}
}
$form = $app['form.factory']->createBuilder('form')
->add('origin', 'choice', array(
'label' => get_lang('Origin'),
'multiple' => true,
'required' => false,
'expanded' => false,
/*'class' => 'Entity\EntityCourse',
'property' => 'complete_name',
'query_builder' => function(\Entity\Repository\CourseRepository $repo) use ($course) {
$repo = $repo->getSubscribedStudents($course);
return $repo;
},*/
'choices' => $choices
))
->add('destination', 'choice', array(
'label' => get_lang('Destination'),
'multiple' => true,
'expanded' => false,
'required' => false,
/*'class' => 'Entity\EntityCourse',
'property' => 'complete_name',
'query_builder' => function(\Entity\Repository\CourseRepository $repo) use ($course) {
return $repo->getSubscribedStudents($course);
},*/
'choices' => $selectedChoices
))
->getForm();
if ($request->getMethod() == 'POST') {
$form->bind($request);
//$data = $form->getData();
$data = $request->get('form');
$destination = isset($data['destination']) ? $data['destination'] : array();
$app['orm.em']->getRepository('Entity\EntityCItemProperty')->SubscribedUsersToItem('learnpath', $course, $sessionId, $lpId, $destination);
return $app->redirect($app['url_generator']->generate('subscribe_users', array('lp_id' => $lpId)));
} else {
$app['template']->assign('form', $form->createView());
}
$response = $app['template']->render_template('learnpath/subscribe_users.tpl');
//return new Response($response, 200, array('Cache-Control' => 's-maxage=3600, private'));
return new Response($response, 200, array());
}
}
$app->match('/', 'SubscribeUserToLP::indexAction', 'POST|GET')->bind('subscribe_users');
$app->run();

@ -94,8 +94,6 @@ class PagesController {
//return $grid->getGridResponse('MyProjectMyBundle::myGrid.html.twig');
*/
$em = $app['orm.em'];
$dql = 'SELECT a FROM Entity\EntityPages a';
$query = $em->createQuery($dql)->setFirstResult(0)->setMaxResults(100);

@ -0,0 +1,44 @@
{% extends "default/layout/layout_1_col.tpl" %}
{% block content %}
<script>
$().ready(function() {
$('#add').click(function() {
return !$('#{{ form.origin.vars.id }} option:selected').remove().appendTo('#{{ form.destination.vars.id }}');
});
$('#remove').click(function() {
return !$('#{{ form.destination.vars.id }} option:selected').remove().appendTo('#{{ form.origin.vars.id }}');
});
$('#send').click(function() {
$("#{{ form.destination.vars.id }}").each(function(){
$("#{{ form.destination.vars.id }} option").attr("selected","selected");
});
});
});
</script>
<form method="POST" {{ form_enctype(form) }}>
{{ form_errors(form) }}
<div class="row">
<div class="span4">
{{ form_label(form.origin) }}
{{ form_widget(form.origin) }}
</div>
<div class="span1">
<br />
<button id="add" class="btn btn-block"><i class="icon-arrow-right icon-large"></i></button>
<button id="remove" class="btn btn-block"><i class="icon-arrow-left icon-large"></i></button>
</div>
<div class="span4">
{{ form_label(form.destination) }}
{{ form_widget(form.destination) }}
</div>
</div>
<div class="row">
<div class="span12">
<button id="send" type="submit" class="btn btn-primary"><i class="icon-arrow-lef icon-large"></i>{{ 'Save' | get_lang }}</button>
</div>
</div>
{{ form_rest(form) }}
</form>
{% endblock %}
Loading…
Cancel
Save