Commit c5a5d222 authored by Lea's avatar Lea
Browse files

enrol corrections

parent 4536b0b1
......@@ -66,16 +66,29 @@ class block_career extends block_base
$list=array();
$request = $DB->get_records_sql('SELECT * FROM {block_career} WHERE course = ?', array($course_id));
foreach($request as $value){
$sql="SELECT * FROM {block_career_groups} JOIN {groups_members} JOIN {block_career} WHERE userid= ? AND groupid=group_id AND mdl_block_career.id= ?";
$requete=$DB->get_records_sql($sql,array($user_id,$value->id));
if (!empty($requete)) {
array_push($list, $value);
}else if($value->enrollment=='student'){
if(($value->enrollment=='student')){
array_push($list, $value);
}
else if($this->is_enrol($user_id,$value->id)){
array_push($list, $value);
}
}
return $list;
}
function is_enrol($user_id,$path_id){
global $DB;
$isenrol=false;
$sql="SELECT group_id FROM {block_career_groups} JOIN {block_career} WHERE career=? AND enrollment = ? AND career=mdl_block_career.id";
$request=$DB->get_records_sql($sql,array($path_id, "teacher"));
foreach($request as $value){
$requete=$DB->get_records('groups_members',array('groupid'=>$value->group_id,'userid'=>$user_id));
if(!empty($requete)){
$isenrol=true;
}
}
return $isenrol;
}
/**
* @return stdClass
......@@ -139,8 +152,6 @@ class block_career extends block_base
$this->content->text .= "<p class='alert alert-secondary m-t-1'>" . get_string('any_carrer', 'block_career') . "</p>";
}
// $this->content->text .= "<p></p>";
return $this->content;
}
}
......
......@@ -22,7 +22,7 @@ echo $OUTPUT->header();
if (isset($_GET["delete"]) && $_GET["delete"] == 1) {
$DB->execute("DELETE FROM {block_career} WHERE id = ?", array($_GET["id"]));
$DB->execute("DELETE FROM {groups} WHERE idnumber = ?", array('GR'.$idCareer));
$DB->execute("DELETE FROM {groups} WHERE idnumber = ?", array('GR_PATH'.$idCareer));
header("Location: $CFG->wwwroot/blocks/career/career_list.php?courseid=" . $id_course);
}
if (isset($_POST['action'])) {
......@@ -50,11 +50,11 @@ if (isset($_POST['action'])) {
$record->image='';
$idCareer = $DB->insert_record('block_career', $record);
}
$request=$DB->get_record('groups',array('idnumber'=>'GR'.$_POST['careerName']));
$request=$DB->get_record('groups',array('idnumber'=>'GR_PATH'.$_POST['careerId']));
if(empty($request)&&$_POST['enrollment']=='student'){
$record2 = new stdClass();
$record2->courseid = $id_course;
$record2->idnumber='GR'.$idCareer;
$record2->idnumber='GR_PATH'.$idCareer;
$record2->name='Groupe '.$_POST["careerName"];
$record2->description=get_string('career_description','block_career',$_POST['careerName']);
$record2->descriptionformat=1;
......@@ -73,7 +73,7 @@ if (isset($_POST['action'])) {
}
if($_POST['enrollment']=='teacher'){
$DB->execute("DELETE FROM {groups} WHERE idnumber = ?", array('GR'.$idCareer));
$DB->execute("DELETE FROM {groups} WHERE idnumber = ?", array('GR_PATH'.$idCareer));
}
if ($_POST['action'] == 'Enregistrer'){
......
......@@ -53,7 +53,7 @@ else {
$sql='SELECT mdl_groups.id
FROM {groups} JOIN {groups_members}
WHERE mdl_groups.id=groupid AND userid=? AND idnumber=?';
$request=$DB->get_record_sql($sql,array($USER->id,'GR'.$careerId));
$request=$DB->get_record_sql($sql,array($USER->id,'GR_PATH'.$careerId));
if(!empty($request)){
$follow=get_string('unfollow','block_career');
}
......@@ -65,9 +65,10 @@ else {
if($_POST['action']==get_string('unfollow','block_career')&&!empty($request)){
$follow=get_string('follow','block_career');
$requete=$DB->execute("DELETE FROM {groups_members} WHERE userid = ? AND groupid", array($USER->id,$request->id));
}else{
}
else{
$follow=get_string('unfollow','block_career');
$requete=$DB->get_record('groups',array('idnumber'=>'GR'.$careerId));
$requete=$DB->get_record('groups',array('idnumber'=>'GR_PATH'.$careerId));
$groupid=$requete->id;
$record = new stdClass();
$record->groupid=$groupid;
......
......@@ -18,12 +18,14 @@ class view_career_setting extends moodleform{
$name = "";
$description = "";
$ressourcesId = "";
$enrol="student";
$contentButton = "Ajouter un parcours";
if (isset($careerId) && !empty($careerId)){
$requete = $DB->get_record_sql('SELECT * FROM {block_career} WHERE id = ?', array($careerId));
$name = $requete->name;
$description = $requete->description;
$ressourcesId = explode(",", $requete->ressources);
$enrol=$requete->enrollment;
$contentButton = "Modifier le parcours";
}
$mform->addElement('text','careerName',get_string('titleaddname_plugin', 'block_career'));
......@@ -34,6 +36,8 @@ class view_career_setting extends moodleform{
$mform->addRule('descriptionName', get_string('error'), 'required', null, null, false, false);
$mform->setDefault('descriptionName',array('text'=>$description));
$mform->addElement('select', 'enrollment', get_string('enroll','block_career'), array('student'=>get_string('student','block_career'), 'teacher'=>get_string('teacher','block_career')));
$mform->getElement('enrollment')->setSelected($enrol);
$content = "";
$content .= "<h2>Édition du parcours</h2>";
$content .= "<div class='alert alert-info'>" . get_string('heading_plugin', 'block_career') . "</div>";
......
......@@ -4,6 +4,7 @@
$string['career:addinstance'] = 'Ajouter un block Parcours';
$string['career:myaddinstance'] = 'Ajouter un block Parcours sur ma page';
$string['pluginname'] = 'Bloc Parcours';
$string['release'] = 'Release : ';
$string['title_plugin'] = 'Parcours';
$string['titleadd_plugin'] = 'Ajouter un parcours';
$string['titleaddname_plugin'] = 'Nom';
......@@ -17,7 +18,6 @@
$string['list_title'] = 'Liste des parcours';
$string['about_this_career']='À propos de ce parcours';
$string['edit_path']='Editer';
$string['editing_path']='Editing path';
$string['cancel']='Annuler';
$string['delete']='Supprimer';
......@@ -31,4 +31,6 @@
$string['career_description']='Groupe pour le parcours : {$a}';
$string['follow']='Suivre ce parcours';
$string['unfollow']='Ne plus suivre ce parcours';
$string['track']='Suivre le parcours : {$a}';
$string['no_group']="Il n'y a pas de groupe inscrit à ce parcours";
?>
\ No newline at end of file
......@@ -59,7 +59,8 @@ class block_career_renderer extends plugin_renderer_base {
else {
$class="btn-danger";
}
$student=false;
$student=true;
$button=false;
$context = context_course::instance($COURSE->id);
$aboutcareer=get_string('about_this_career','block_career');
$request = $DB->get_record('block_career',array('id' => $pathid));
......@@ -67,11 +68,13 @@ class block_career_renderer extends plugin_renderer_base {
$trackerpath=$CFG->wwwroot.'/blocks/career/career_tracker.php?courseid='.$request->course.'&pathid='.$request->id.'&display=solo';
if (!has_capability('moodle/course:update', $context)&&$request->enrollment=='student') {
$student=true;
if (has_capability('moodle/course:update', $context)) {
$student=false;
}
$list=array('about_this_career'=>$aboutcareer,'description'=>$description,'student'=>$student,'follow'=>$follow,'class'=>$class,'track_path'=>$trackerpath);
if($request->enrollment=='student'){
$button=true;
}
$list=array('about_this_career'=>$aboutcareer,'description'=>$description,'student'=>$student,'follow'=>$follow,'class'=>$class,'track_path'=>$trackerpath,'button'=>$button);
echo $this->render_from_template('block_career/career_header', $list);
}
......
<div class="path-header">
{{#student}}
{{#student}}{{#button}}
<form action="{{link}}" method="POST">
<input type="submit" class="btn {{class}} right-content" name="action" value="{{follow}}" >
</form> {{/student}}
</form>
{{/button}}{{/student}}
{{^student}}
<a class="btn btn-primary right-content" href="{{track_path}}">Suivi étudiant</a>
{{/student}}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment