mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 20:29:29 +00:00
Erstversion Moodle2.4 Syncronisation
This commit is contained in:
@@ -0,0 +1,383 @@
|
||||
<?php
|
||||
/* Copyright (C) 2013 FH Technikum-Wien
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors: Andreas Oesterreicher <andreas.oesterreicher@technikum-wien.at>
|
||||
*/
|
||||
/*
|
||||
* Verwaltung der Moodlekurse zu einer LV
|
||||
* Moodle 2.4
|
||||
*/
|
||||
require_once('../../../config/cis.config.inc.php');
|
||||
require_once('../../../include/basis_db.class.php');
|
||||
require_once('../../../include/functions.inc.php');
|
||||
require_once('../../../include/benutzerberechtigung.class.php');
|
||||
require_once('../../../include/moodle2_4_course.class.php');
|
||||
require_once('../../../include/moodle2_4_user.class.php');
|
||||
require_once('../../../include/lehrveranstaltung.class.php');
|
||||
require_once('../../../include/lehreinheit.class.php');
|
||||
require_once('../../../include/lehreinheitgruppe.class.php');
|
||||
require_once('../../../include/lehreinheitmitarbeiter.class.php');
|
||||
require_once('../../../include/studiengang.class.php');
|
||||
require_once('../../../include/phrasen.class.php');
|
||||
|
||||
$sprache = getSprache();
|
||||
$p = new phrasen($sprache);
|
||||
|
||||
if (!$db = new basis_db())
|
||||
die($p->t('global/fehlerBeimOeffnenDerDatenbankverbindung'));
|
||||
|
||||
if (!$user=get_uid())
|
||||
die($p->t('moodle/sieSindNichtAngemeldet').' !');
|
||||
|
||||
if(isset($_GET['lvid']) && is_numeric($_GET['lvid']))
|
||||
$lvid=$_GET['lvid'];
|
||||
else
|
||||
die($p->t('moodle/lvidMussUebergebenWerden'));
|
||||
|
||||
if(isset($_GET['stsem']) && check_stsem($_GET['stsem']))
|
||||
$stsem = $_GET['stsem'];
|
||||
else
|
||||
die($p->t('moodle/esWurdeKeinStudiensemesterUebergeben'));
|
||||
|
||||
$art = (isset($_POST['art'])?$_POST['art']:'lv');
|
||||
|
||||
$berechtigt = false;
|
||||
|
||||
//Pruefen ob Rechte fuer diese LV vorhanden sind
|
||||
$lem = new lehreinheitmitarbeiter();
|
||||
if($lem->existsLV($lvid, $stsem, $user))
|
||||
$berechtigt=true;
|
||||
|
||||
$rechte = new benutzerberechtigung();
|
||||
$rechte->getBerechtigungen($user);
|
||||
|
||||
if($rechte->isBerechtigt('admin'))
|
||||
$berechtigt=true;
|
||||
|
||||
$lv = new lehrveranstaltung();
|
||||
$lv->load($lvid);
|
||||
|
||||
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<link href="../../../skin/style.css.php" rel="stylesheet" type="text/css">
|
||||
<script language="Javascript">
|
||||
<!--
|
||||
function togglediv()
|
||||
{
|
||||
var block = "table-row";
|
||||
if (navigator.appName.indexOf("Microsoft") > -1)
|
||||
block = "block";
|
||||
|
||||
if(document.getElementById("radiole").checked)
|
||||
document.getElementById("lehreinheitencheckboxen").style.display = block;
|
||||
else
|
||||
document.getElementById("lehreinheitencheckboxen").style.display = "none";
|
||||
}
|
||||
-->
|
||||
</script>
|
||||
</head>
|
||||
<body onload="togglediv()">
|
||||
<h1>'.$db->convert_html_chars($lv->bezeichnung).' ('.$db->convert_html_chars($stsem).')</h1>
|
||||
<br />
|
||||
<table>
|
||||
<tr>
|
||||
<td>';
|
||||
|
||||
if(isset($_POST['neu']))
|
||||
{
|
||||
if($_POST['bezeichnung']=='')
|
||||
{
|
||||
echo '<span class="error">'.$p->t('benotungstool/bezeichnungMussEingegebenWerden').'</span><br>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$lehrveranstaltung = new lehrveranstaltung();
|
||||
$lehrveranstaltung->load($lvid);
|
||||
$studiengang = new studiengang();
|
||||
$studiengang->load($lehrveranstaltung->studiengang_kz);
|
||||
|
||||
$orgform = ($lehrveranstaltung->orgform_kurzbz!=''?$lehrveranstaltung->orgform_kurzbz:$studiengang->orgform_kurzbz);
|
||||
|
||||
//Kurzbezeichnung generieren Format: STSEM-STG-SEM-LV/LEID/LEID/LEID...
|
||||
//$shortname = $stsem.'-'.$studiengang->kuerzel.'-'.$lehrveranstaltung->semester.'-'.$lehrveranstaltung->kurzbz;
|
||||
$shortname = $studiengang->kuerzel.'-'.$orgform.'-'.$lehrveranstaltung->semester.'-'.$stsem.'-'.$lehrveranstaltung->kurzbz;
|
||||
|
||||
//Gesamte LV zu einem Moodle Kurs zusammenlegen
|
||||
if($art=='lv')
|
||||
{
|
||||
$mdl_course = new moodle_course();
|
||||
|
||||
$mdl_course->lehrveranstaltung_id = $lvid;
|
||||
$mdl_course->studiensemester_kurzbz = $stsem;
|
||||
$mdl_course->mdl_fullname = $_POST['bezeichnung'];
|
||||
$mdl_course->mdl_shortname = $shortname;
|
||||
$mdl_course->insertamum = date('Y-m-d H:i:s');
|
||||
$mdl_course->insertvon = $user;
|
||||
$mdl_course->gruppen = isset($_POST['gruppen']);
|
||||
|
||||
//Moodlekurs anlegen
|
||||
if($mdl_course->create_moodle())
|
||||
{
|
||||
//Eintrag in der Vilesci DB
|
||||
$mdl_course->create_vilesci();
|
||||
|
||||
$mdl_user = new moodle_user();
|
||||
//Lektoren Synchronisieren
|
||||
if(!$mdl_user->sync_lektoren($mdl_course->mdl_course_id))
|
||||
echo $mdl_user->errormsg;
|
||||
|
||||
$mdl_user = new moodle_user();
|
||||
//Studenten Synchronisieren
|
||||
if(!$mdl_user->sync_studenten($mdl_course->mdl_course_id))
|
||||
echo $mdl_user->errormsg;
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $mdl_course->errormsg;
|
||||
}
|
||||
}
|
||||
elseif($art=='le') //Getrennte Kurse fuer die Lehreinheiten
|
||||
{
|
||||
$lehreinheiten=array();
|
||||
|
||||
foreach ($_POST as $key=>$value)
|
||||
{
|
||||
if(mb_strstr($key, 'lehreinheit_'))
|
||||
{
|
||||
$shortname.='/'.$value;
|
||||
$lehreinheiten[]=$value;
|
||||
}
|
||||
}
|
||||
|
||||
if(count($lehreinheiten)>0)
|
||||
{
|
||||
$mdl_course = new moodle_course();
|
||||
|
||||
$mdl_course->mdl_fullname = $_POST['bezeichnung'];
|
||||
$mdl_course->mdl_shortname = $shortname;
|
||||
$mdl_course->studiensemester_kurzbz = $stsem;
|
||||
$mdl_course->insertamum = date('Y-m-d H:i:s');
|
||||
$mdl_course->insertvon = $user;
|
||||
$mdl_course->lehreinheit_id=$lehreinheiten[0];
|
||||
$mdl_course->gruppen = isset($_POST['gruppen']);
|
||||
|
||||
//Kurs im Moodle anlegen
|
||||
if($mdl_course->create_moodle())
|
||||
{
|
||||
//fuer jede Lehreinheit einen Eintrag in VilesciDB anlegen
|
||||
foreach ($lehreinheiten as $value)
|
||||
{
|
||||
$mdl_course->lehreinheit_id = $value;
|
||||
if(!$mdl_course->create_vilesci())
|
||||
echo '<br>'.$p->t('moodle/fehlerBeimAnlegenAufgetreten').':'.$mdl_course->errormsg;
|
||||
}
|
||||
|
||||
$mdl_user = new moodle_user();
|
||||
//Lektoren Synchronisieren
|
||||
if(!$mdl_user->sync_lektoren($mdl_course->mdl_course_id))
|
||||
echo $mdl_user->errormsg;
|
||||
|
||||
$mdl_user = new moodle_user();
|
||||
//Studenten Synchronisieren
|
||||
if(!$mdl_user->sync_studenten($mdl_course->mdl_course_id))
|
||||
echo $mdl_user->errormsg;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo '<span class="error">'.$p->t('moodle/esMussMindestensEineLehreinheitMarkiertSein').'</span><br>';
|
||||
}
|
||||
}
|
||||
else
|
||||
die($p->t('moodle/artIstUnbekannt'));
|
||||
}
|
||||
}
|
||||
//Gruppen Syncro ein/aus schalten
|
||||
if(isset($_POST['changegruppe']))
|
||||
{
|
||||
if(isset($_POST['moodle_id']) && is_numeric($_POST['moodle_id']))
|
||||
{
|
||||
$mcourse = new moodle_course();
|
||||
if($mcourse->updateGruppenSync($_POST['moodle_id'], isset($_POST['gruppen'])))
|
||||
echo '<b>'.$p->t('moodle/datenWurdenAktualisiert').'</b><br>';
|
||||
else
|
||||
echo '<span class="error">'.$p->t('global/fehlerBeimAktualisierenDerDaten').'</span>';
|
||||
}
|
||||
else
|
||||
{
|
||||
echo '<span class="error">'.$p->t('moodle/esWurdeKeineGueltigeIdUebergeben').'</span>';
|
||||
}
|
||||
}
|
||||
|
||||
//Anlegen eines Testkurses
|
||||
if(isset($_GET['action']) && $_GET['action']=='createtestkurs')
|
||||
{
|
||||
$mdl_course = new moodle_course();
|
||||
if(!$mdl_course->loadTestkurs($lvid, $stsem))
|
||||
{
|
||||
$lehrveranstaltung = new lehrveranstaltung();
|
||||
$lehrveranstaltung->load($lvid);
|
||||
$studiengang = new studiengang();
|
||||
$studiengang->load($lehrveranstaltung->studiengang_kz);
|
||||
|
||||
//$orgform = ($lehrveranstaltung->orgform_kurzbz!=''?$lehrveranstaltung->orgform_kurzbz:$studiengang->orgform_kurzbz);
|
||||
|
||||
//Kurzbezeichnung generieren Format: STSEM-STG-SEM-LV/LEID/LEID/LEID...
|
||||
$shortname = 'TK-'.$stsem.'-'.$studiengang->kuerzel.'-'.$lehrveranstaltung->semester.'-'.$lehrveranstaltung->kurzbz;
|
||||
|
||||
$mdl_course->lehrveranstaltung_id = $lvid;
|
||||
$mdl_course->studiensemester_kurzbz = $stsem;
|
||||
$mdl_course->mdl_fullname = 'Testkurs - '.$lehrveranstaltung->bezeichnung;
|
||||
$mdl_course->mdl_shortname = $shortname;
|
||||
|
||||
//TestKurs erstellen
|
||||
if($mdl_course->createTestkurs($lvid, $stsem))
|
||||
{
|
||||
$id=$mdl_course->mdl_course_id;
|
||||
$errormsg='';
|
||||
|
||||
$mdl_user = new moodle_user();
|
||||
//Lektoren zuweisen
|
||||
if(!$mdl_user->sync_lektoren($id, $lvid, $stsem))
|
||||
$errormsg.=$p->t('moodle/fehlerBeiDerLektorenZuordnung').':'.$mdl_user->errormsg.'<br>';
|
||||
//Teststudenten zuweisen
|
||||
if(!$mdl_user->createTestStudentenZuordnung($id))
|
||||
$errormsg.=$p->t('moodle/fehlerBeiDerStudentenZuordnung').':'.$mdl_user->errormsg.'<br>';
|
||||
|
||||
if($errormsg!='')
|
||||
echo $errormsg;
|
||||
else
|
||||
echo '<b>'.$p->t('moodle/testkursWurdeErfolgreichAngelegt').'</b><br>';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
echo '<span class="error">'.$p->t('moodle/esExistiertBereitsEinTestkurs').'</span><br>';
|
||||
}
|
||||
}
|
||||
|
||||
$mdl_course = new moodle_course();
|
||||
if($mdl_course->course_exists_for_lv($lvid, $stsem) || $mdl_course->course_exists_for_allLE($lvid, $stsem))
|
||||
{
|
||||
echo $p->t('moodle/esIstBereitsEinMoodleKursVorhanden');
|
||||
}
|
||||
else
|
||||
{
|
||||
//wenn bereits ein Moodle Kurs fuer eine Lehreinheit angelegt wurde, dann dass
|
||||
//anlegen fuer die Lehrveranstaltung verhindern
|
||||
$qry = "SELECT 1 FROM lehre.tbl_moodle
|
||||
WHERE lehreinheit_id in(SELECT lehreinheit_id FROM lehre.tbl_lehreinheit
|
||||
WHERE lehrveranstaltung_id=".$db->db_add_param($lvid, FHC_INTEGER)."
|
||||
AND studiensemester_kurzbz=".$db->db_add_param($stsem).")";
|
||||
$disable_lv='';
|
||||
if($result = $db->db_query($qry))
|
||||
if($db->db_num_rows($result)>0)
|
||||
{
|
||||
$disable_lv='disabled="true"';
|
||||
//wenn schon ein Moodle Kurs zu einer Lehreinheit angelegt wurde,
|
||||
//dann ist standardmaessig die Lehreinheit markiert
|
||||
if($art=='lv')
|
||||
$art='le';
|
||||
}
|
||||
|
||||
echo '<b>'.$p->t('moodle/moodleKursAnlegen').': </b><br><br>
|
||||
<form action="'.$_SERVER['PHP_SELF'].'?lvid='.$lvid.'&stsem='.$stsem.'" method="POST">
|
||||
<input type="radio" '.$disable_lv.' name="art" value="lv" onclick="togglediv()" '.($art=='lv'?'checked':'').'>einen Moodle Kurs für die gesamte LV anlegen<br>
|
||||
<input type="radio" id="radiole" name="art" value="le" onclick="togglediv()" '.($art=='le'?'checked':'').'>einen Moodle Kurs für einzelne Lehreinheiten anlegen
|
||||
';
|
||||
|
||||
$le = new lehreinheit();
|
||||
$le->load_lehreinheiten($lv->lehrveranstaltung_id, $stsem);
|
||||
echo '<div id="lehreinheitencheckboxen" style="display:none">';
|
||||
foreach ($le->lehreinheiten as $row)
|
||||
{
|
||||
//Gruppen laden
|
||||
$gruppen = '';
|
||||
|
||||
$lehreinheitgruppe = new lehreinheitgruppe();
|
||||
$lehreinheitgruppe->getLehreinheitgruppe($row->lehreinheit_id);
|
||||
foreach ($lehreinheitgruppe->lehreinheitgruppe as $grp)
|
||||
{
|
||||
if($grp->gruppe_kurzbz=='')
|
||||
$gruppen.=' '.$grp->semester.$grp->verband.$grp->gruppe;
|
||||
else
|
||||
$gruppen.=' '.$grp->gruppe_kurzbz;
|
||||
}
|
||||
|
||||
//Lektoren laden
|
||||
$lektoren = '';
|
||||
$lehreinheitmitarbeiter = new lehreinheitmitarbeiter();
|
||||
$lehreinheitmitarbeiter->getLehreinheitmitarbeiter($row->lehreinheit_id);
|
||||
|
||||
foreach ($lehreinheitmitarbeiter->lehreinheitmitarbeiter as $ma)
|
||||
{
|
||||
$lektoren.= ' '.$ma->mitarbeiter_uid;
|
||||
}
|
||||
|
||||
if($mdl_course->course_exists_for_le($row->lehreinheit_id))
|
||||
$disabled='disabled';
|
||||
else
|
||||
$disabled='';
|
||||
echo '
|
||||
<input type="checkbox" name="lehreinheit_'.$row->lehreinheit_id.'" value="'.$row->lehreinheit_id.'" '.$disabled.'>'.$row->lehrform_kurzbz.' '.$gruppen.' '.$lektoren;
|
||||
echo '<br>';
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
$studiengang = new studiengang();
|
||||
$studiengang->load($lv->studiengang_kz);
|
||||
$orgform = ($lv->orgform_kurzbz!=''?$lv->orgform_kurzbz:$studiengang->orgform_kurzbz);
|
||||
$longbezeichnung = $studiengang->kuerzel.'-'.$orgform.'-'.$lv->semester.'-'.$stsem.' - '.$lv->bezeichnung;
|
||||
|
||||
echo '<br>'.$p->t('moodle/kursbezeichnung').': <input type="text" name="bezeichnung" maxlength="254" size="40" value="'.$db->convert_html_chars($longbezeichnung).'">';
|
||||
echo '<br>'.$p->t('moodle/gruppenUebernehmen').': <input type="checkbox" name="gruppen" checked>';
|
||||
echo '<br><br><input type="submit" name="neu" value="'.$p->t('moodle/kursAnlegen').'">
|
||||
</form>';
|
||||
}
|
||||
echo '</td>';
|
||||
|
||||
echo '<td valign="top">';
|
||||
echo '<b>'.$p->t('moodle/vorhandeneMoodleKurse').'</b>';
|
||||
if(!$mdl_course->getAll($lvid, $stsem))
|
||||
echo $mdl_course->errormsg;
|
||||
echo '<table>';
|
||||
foreach ($mdl_course->result as $course)
|
||||
{
|
||||
echo '<tr>';
|
||||
echo '<td><a href="'.MOODLE_PATH24.'course/view.php?id='.$course->mdl_course_id.'" class="Item" target="_blank">'.$course->mdl_fullname.'</a></td>';
|
||||
echo "<td nowrap><form action='".$_SERVER['PHP_SELF']."?lvid=$lvid&stsem=$stsem' method='POST' style='margin:0px'><input type='hidden' name='moodle_id' value='$course->moodle_id'><input type='checkbox' name='gruppen' ".($course->gruppen?'checked':'').">Gruppen übernehmen <input type='submit' value='".$p->t('global/ok')."' name='changegruppe'></form></td>";
|
||||
}
|
||||
echo '</table>';
|
||||
echo '</td></tr></table>';
|
||||
|
||||
echo '<br><br><br>';
|
||||
echo '<b>'.$p->t('moodle/testkurse').'</b><br><br>';
|
||||
$mdlcourse = new moodle_course();
|
||||
if($mdlcourse->loadTestkurs($lvid, $stsem))
|
||||
{
|
||||
echo '<a href="'.MOODLE_PATH24.'course/view.php?id='.$mdlcourse->mdl_course_id.'" class="Item" target="_blank">'.$db->convert_html_chars($mdlcourse->mdl_fullname).'</a>';
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<a href='".$_SERVER['PHP_SELF']."?lvid=$lvid&stsem=$stsem&action=createtestkurs' class='Item'>".$p->t('moodle/klickenSieHierUmTestkursErstellen')."</a>";
|
||||
}
|
||||
echo '
|
||||
</body>
|
||||
</html>';
|
||||
?>
|
||||
@@ -314,6 +314,45 @@ class lehreinheitmitarbeiter extends basis_db
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prueft ob ein Mitarbeiter einer LV zugeordnet ist
|
||||
* @param $lehrveranstaltung_id
|
||||
* @param $studiensemester_kurzbz
|
||||
* @param $uid
|
||||
* @return true wenn die Zuteilung existiert sonst false
|
||||
*/
|
||||
public function existsLV($lehrveranstaltung_id, $studiensemester_kurzbz, $uid)
|
||||
{
|
||||
if(!is_numeric($lehrveranstaltung_id))
|
||||
{
|
||||
$this->errormsg = 'lehrveranstaltung_id muss eine gueltige Zahl sein';
|
||||
return false;
|
||||
}
|
||||
|
||||
$qry = "SELECT
|
||||
1
|
||||
FROM
|
||||
lehre.tbl_lehreinheitmitarbeiter
|
||||
JOIN lehre.tbl_lehreinheit USING(lehreinheit_id)
|
||||
WHERE
|
||||
lehrveranstaltung_id=".$this->db_add_param($lehrveranstaltung_id, FHC_INTEGER)."
|
||||
AND studiensemester_kurzbz=".$this->db_add_param($studiensemester_kurzbz)."
|
||||
AND mitarbeiter_uid=".$this->db_add_param($uid).';';
|
||||
|
||||
if($this->db_query($qry))
|
||||
{
|
||||
if($this->db_num_rows()>0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errormsg = 'Fehler beim Lesen der Lehreinheitmitarbeiterzuteilung';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loescht die Zuteilung eines Mitarbeiters
|
||||
* zu einer Lehreinheit
|
||||
@@ -391,4 +430,4 @@ class lehreinheitmitarbeiter extends basis_db
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,563 @@
|
||||
<?php
|
||||
/* Copyright (C) 2013 FH Technikum-Wien
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors: Andreas Oesterreicher <andreas.oesterreicher@technikum-wien.at> and
|
||||
*/
|
||||
/*
|
||||
* Connector fuer Moodle 2.4 User
|
||||
*
|
||||
* FHComplete Moodle Plugin muss installiert sein fuer
|
||||
* Webservice Funktion 'fhcomplete_user_get_users'
|
||||
*/
|
||||
require_once(dirname(__FILE__).'/basis_db.class.php');
|
||||
|
||||
class moodle_user extends basis_db
|
||||
{
|
||||
public $log=''; //log message fuer Syncro
|
||||
public $log_public=''; //log message fuer Syncro
|
||||
public $sync_create=0; //anzahl der durchgefuehrten zuteilungen beim syncro
|
||||
public $group_update=0; //anzahl der updates an gruppen
|
||||
private $serverurl;
|
||||
|
||||
public $mdl_user_id;
|
||||
public $mdl_user_username;
|
||||
public $mdl_user_firstname;
|
||||
public $mdl_user_lastname;
|
||||
|
||||
/**
|
||||
* Konstruktor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->serverurl=MOODLE_PATH24.'/webservice/soap/server.php?wsdl=1&wstoken='.MOODLE_TOKEN24.'&'.microtime(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Laedt einen Moodle User
|
||||
*
|
||||
* @param $uid
|
||||
* @return boolean
|
||||
*/
|
||||
public function loaduser($uid)
|
||||
{
|
||||
$client = new SoapClient($this->serverurl);
|
||||
$response = $client->fhcomplete_user_get_users(array(array('key'=>'username', 'value'=>$uid)));
|
||||
|
||||
if(isset($response['users'][0]))
|
||||
{
|
||||
$this->mdl_user_id = $response['users'][0]['id'];
|
||||
$this->mdl_user_username = $response['users'][0]['username'];
|
||||
$this->mdl_user_firstname = $response['users'][0]['firstname'];
|
||||
$this->mdl_user_lastname = $response['users'][0]['lastname'];
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errormsg = 'Fehler beim Laden des Users';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert ein Array mit allen Lektoren die
|
||||
* zu dem Moodle Kurs zugeteilt sind
|
||||
*/
|
||||
public function getMitarbeiter($mdl_course_id)
|
||||
{
|
||||
//Mitarbeiter laden die zu diesem Kurs zugeteilt sind
|
||||
$qry = "SELECT
|
||||
mitarbeiter_uid
|
||||
FROM
|
||||
lehre.tbl_lehreinheitmitarbeiter JOIN lehre.tbl_moodle USING(lehreinheit_id)
|
||||
WHERE
|
||||
mdl_course_id=".$this->db_add_param($mdl_course_id, FHC_INTEGER)."
|
||||
UNION
|
||||
SELECT
|
||||
mitarbeiter_uid
|
||||
FROM
|
||||
lehre.tbl_lehreinheitmitarbeiter JOIN lehre.tbl_lehreinheit USING(lehreinheit_id)
|
||||
JOIN lehre.tbl_moodle USING(lehrveranstaltung_id)
|
||||
WHERE
|
||||
tbl_lehreinheit.studiensemester_kurzbz=tbl_moodle.studiensemester_kurzbz
|
||||
AND mdl_course_id=".$this->db_add_param($mdl_course_id, FHC_INTEGER);
|
||||
$mitarbeiter=array();
|
||||
if($this->db_query($qry))
|
||||
{
|
||||
while($row_ma = $this->db_fetch_object())
|
||||
{
|
||||
$mitarbeiter[] = $row_ma->mitarbeiter_uid;
|
||||
}
|
||||
return $mitarbeiter;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errormsg='Fehler beim Laden der Mitarbeiter';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronisiert die Lektoren der Lehreinheiten
|
||||
* mit denen des Moodle Kurses
|
||||
* @param $mdl_course_id ID des MoodleKurses
|
||||
* lehrveranstaltung_id wird nur angegeben beim Syncro von Testkursen
|
||||
* studiensemester_kurzbz wird nur angegeben beim Syncro von Testkursen
|
||||
* @return true wenn ok, false wenn Fehler
|
||||
*/
|
||||
public function sync_lektoren($mdl_course_id, $lehrveranstaltung_id=null, $studiensemester_kurzbz=null)
|
||||
{
|
||||
//Mitarbeiter laden die zu diesem Kurs zugeteilt sind
|
||||
if(!is_null($lehrveranstaltung_id) && !is_null($studiensemester_kurzbz))
|
||||
{
|
||||
//Bei Testkursen werden alle Lektoren einer Lehrveranstaltung zugeteilt
|
||||
//da hier kein Eintrag in der tbl_moodle vorhanden ist, werden die Lektoren direkt aus
|
||||
//der tbl_lehreinheitmitarbeiter geholt.
|
||||
$qry = "SELECT
|
||||
mitarbeiter_uid
|
||||
FROM
|
||||
lehre.tbl_lehreinheitmitarbeiter
|
||||
JOIN lehre.tbl_lehreinheit USING(lehreinheit_id)
|
||||
WHERE
|
||||
lehrveranstaltung_id=".$this->db_add_param($lehrveranstaltung_id, FHC_INTEGER)."
|
||||
AND studiensemester_kurzbz=".$this->db_add_param($studiensemester_kurzbz);
|
||||
}
|
||||
else
|
||||
{
|
||||
$qry = "SELECT
|
||||
mitarbeiter_uid
|
||||
FROM
|
||||
lehre.tbl_lehreinheitmitarbeiter JOIN lehre.tbl_moodle USING(lehreinheit_id)
|
||||
WHERE
|
||||
mdl_course_id=".$this->db_add_param($mdl_course_id, FHC_INTEGER)."
|
||||
UNION
|
||||
SELECT
|
||||
mitarbeiter_uid
|
||||
FROM
|
||||
lehre.tbl_lehreinheitmitarbeiter JOIN lehre.tbl_lehreinheit USING(lehreinheit_id)
|
||||
JOIN lehre.tbl_moodle USING(lehrveranstaltung_id)
|
||||
WHERE
|
||||
tbl_lehreinheit.studiensemester_kurzbz=tbl_moodle.studiensemester_kurzbz
|
||||
AND mdl_course_id=".$this->db_add_param($mdl_course_id, FHC_INTEGER);
|
||||
}
|
||||
$mitarbeiter='';
|
||||
|
||||
$client = new SoapClient($this->serverurl);
|
||||
$enrolled_users = $client->core_enrol_get_enrolled_users($mdl_course_id,array());
|
||||
|
||||
if($result_ma = $this->db_query($qry))
|
||||
{
|
||||
while($row_ma = $this->db_fetch_object($result_ma))
|
||||
{
|
||||
//MoodleID des Users holen bzw ggf neu anlegen
|
||||
if(!$this->loaduser($row_ma->mitarbeiter_uid))
|
||||
{
|
||||
//User anlegen
|
||||
if(!$this->createUser($row_ma->mitarbeiter_uid))
|
||||
{
|
||||
$this->errormsg = "Fehler beim Anlegen des Users $row_ma->mitarbeiter_uid: $this->errormsg";
|
||||
return false;
|
||||
}
|
||||
else
|
||||
$this->errormsg = '';
|
||||
}
|
||||
|
||||
if($mitarbeiter!='')
|
||||
$mitarbeiter.=',';
|
||||
$mitarbeiter.=$this->mdl_user_id;
|
||||
|
||||
$user_zugeteilt=false;
|
||||
foreach($enrolled_users as $user)
|
||||
{
|
||||
if($user->id==$this->mdl_user_id)
|
||||
{
|
||||
$user_zugeteilt=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$user_zugeteilt)
|
||||
{
|
||||
//Mitarbeiter ist noch nicht zugeteilt.
|
||||
$data = new stdClass();
|
||||
$data->roleid=3; // 3=Lektor
|
||||
$data->userid=$this->mdl_user_id;
|
||||
$data->courseid=$mdl_course_id;
|
||||
|
||||
if($client->enrol_manual_enrol_users(array($data)))
|
||||
{
|
||||
$this->log.="\nder Lektor $this->mdl_user_firstname $this->mdl_user_lastname wurde zum Kurs hinzugefügt";
|
||||
$this->log_public.="\nder Lektor $this->mdl_user_firstname $this->mdl_user_lastname wurde zum Kurs hinzugefügt";
|
||||
$this->sync_create++;
|
||||
}
|
||||
else
|
||||
$this->log.="\nFehler beim Anlegen der Lektoren-Zuteilung: $this->errormsg";
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errormsg = 'Fehler beim Ermitteln der Zugeteilten Lektoren';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronisiert die Studenten der Lehreinheiten
|
||||
* mit denen des Moodle Kurses
|
||||
* @param $mdl_course_id ID des MoodleKurses
|
||||
* @return true wenn ok, false wenn Fehler
|
||||
*/
|
||||
public function sync_studenten($mdl_course_id)
|
||||
{
|
||||
//Studentengruppen laden die zu diesem Kurs zugeteilt sind
|
||||
$qry = "SELECT
|
||||
studiengang_kz, semester, verband, gruppe, gruppe_kurzbz, tbl_moodle.studiensemester_kurzbz, tbl_moodle.gruppen
|
||||
FROM
|
||||
lehre.tbl_lehreinheitgruppe JOIN lehre.tbl_moodle USING(lehreinheit_id)
|
||||
WHERE
|
||||
mdl_course_id=".$this->db_add_param($mdl_course_id)."
|
||||
UNION
|
||||
SELECT
|
||||
studiengang_kz, semester, verband, gruppe, gruppe_kurzbz, tbl_moodle.studiensemester_kurzbz, tbl_moodle.gruppen
|
||||
FROM
|
||||
lehre.tbl_lehreinheitgruppe JOIN lehre.tbl_lehreinheit USING(lehreinheit_id)
|
||||
JOIN lehre.tbl_moodle USING(lehrveranstaltung_id)
|
||||
WHERE
|
||||
tbl_lehreinheit.studiensemester_kurzbz=tbl_moodle.studiensemester_kurzbz
|
||||
AND mdl_course_id=".$this->db_add_param($mdl_course_id);
|
||||
$studenten='';
|
||||
|
||||
$client = new SoapClient($this->serverurl);
|
||||
$enrolled_users = $client->core_enrol_get_enrolled_users($mdl_course_id, array());
|
||||
|
||||
if($result_std = $this->db_query($qry))
|
||||
{
|
||||
while($row_std = $this->db_fetch_object($result_std))
|
||||
{
|
||||
//Schauen ob fuer diesen Kurs die Gruppen mitgesynct werden sollen
|
||||
$gruppensync = $this->db_parse_bool($row_std->gruppen);
|
||||
|
||||
//Studenten dieser Gruppe holen
|
||||
|
||||
if($row_std->gruppe_kurzbz=='') //LVB Gruppe
|
||||
{
|
||||
$qry = "SELECT
|
||||
distinct student_uid
|
||||
FROM
|
||||
public.tbl_studentlehrverband
|
||||
WHERE
|
||||
studiensemester_kurzbz=".$this->db_add_param($row_std->studiensemester_kurzbz)." AND
|
||||
studiengang_kz = ".$this->db_add_param($row_std->studiengang_kz)." AND
|
||||
semester = ".$this->db_add_param($row_std->semester);
|
||||
|
||||
if(trim($row_std->verband)!='')
|
||||
{
|
||||
$qry.=" AND verband = ".$this->db_add_param($row_std->verband);
|
||||
if(trim($row_std->gruppe)!='')
|
||||
{
|
||||
$qry.=" AND gruppe = ".$this->db_add_param($row_std->gruppe);
|
||||
}
|
||||
}
|
||||
$studiengang_obj = new studiengang();
|
||||
$studiengang_obj->load($row_std->studiengang_kz);
|
||||
$gruppenbezeichnung = $studiengang_obj->kuerzel.'-'.trim($row_std->semester).trim($row_std->verband).trim($row_std->gruppe);
|
||||
}
|
||||
else //Spezialgruppe
|
||||
{
|
||||
$qry = "SELECT
|
||||
distinct uid as student_uid
|
||||
FROM
|
||||
public.tbl_benutzergruppe
|
||||
WHERE
|
||||
gruppe_kurzbz=".$this->db_add_param($row_std->gruppe_kurzbz)." AND
|
||||
studiensemester_kurzbz=".$this->db_add_param($row_std->studiensemester_kurzbz);
|
||||
$gruppenbezeichnung = $row_std->gruppe_kurzbz;
|
||||
}
|
||||
|
||||
if($result_user = $this->db_query($qry))
|
||||
{
|
||||
while($row_user = $this->db_fetch_object($result_user))
|
||||
{
|
||||
//MoodleID des Users holen bzw ggf neu anlegen
|
||||
if(!$this->loaduser($row_user->student_uid))
|
||||
{
|
||||
//User anlegen
|
||||
if(!$this->createUser($row_user->student_uid))
|
||||
{
|
||||
$this->errormsg = "Fehler beim Anlegen des Users $row_user->student_uid: $this->errormsg";
|
||||
return false;
|
||||
}
|
||||
else
|
||||
$this->errormsg = '';
|
||||
}
|
||||
|
||||
if($studenten!='')
|
||||
$studenten.=',';
|
||||
$studenten.=$this->mdl_user_id;
|
||||
|
||||
//Nachschauen ob dieser Student bereits zugeteilt ist
|
||||
|
||||
$user_zugeteilt=false;
|
||||
foreach($enrolled_users as $user)
|
||||
{
|
||||
if(isset($user->id) && $user->id==$this->mdl_user_id)
|
||||
{
|
||||
$user_zugeteilt=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$user_zugeteilt)
|
||||
{
|
||||
//Student ist noch nicht zugeteilt.
|
||||
|
||||
$data = new stdClass();
|
||||
$data->roleid=5; // 5=Teilnehmer/Student
|
||||
$data->userid=$this->mdl_user_id;
|
||||
$data->courseid=$mdl_course_id;
|
||||
|
||||
if($client->enrol_manual_enrol_users(array($data)))
|
||||
{
|
||||
$this->log.="\nder Student $this->mdl_user_firstname $this->mdl_user_lastname wurde zum Kurs hinzugefügt";
|
||||
$this->log_public.="\nder Student $this->mdl_user_firstname $this->mdl_user_lastname wurde zum Kurs hinzugefügt";
|
||||
$this->sync_create++;
|
||||
}
|
||||
else
|
||||
$this->log.="\nFehler beim Anlegen der Studenten-Zuteilung: $this->errormsg";
|
||||
}
|
||||
//Gruppenzuteilung
|
||||
if($gruppensync)
|
||||
{
|
||||
//Schauen ob die Gruppe vorhanden ist
|
||||
if(!$groupid = $this->getGroup($mdl_course_id, $gruppenbezeichnung))
|
||||
{
|
||||
//wenn nicht dann anlegen
|
||||
if(!$groupid = $this->createGroup($mdl_course_id, $gruppenbezeichnung))
|
||||
continue;
|
||||
$this->group_update++;
|
||||
$this->log.="\nes wurde eine neue Gruppe angelgt: $gruppenbezeichnung";
|
||||
$this->log_public.="\nes wurde eine neue Gruppe angelgt: $gruppenbezeichnung";
|
||||
}
|
||||
|
||||
//Schauen ob eine Zuteilung zu dieser Gruppe vorhanden ist
|
||||
if(!$this->getGroupMember($groupid, $this->mdl_user_id))
|
||||
{
|
||||
//wenn nicht dann zuteilen
|
||||
$this->createGroupMember($groupid, $this->mdl_user_id);
|
||||
$this->group_update++;
|
||||
$this->log.="\nder Student $this->mdl_user_firstname $this->mdl_user_lastname wurde der Gruppe $gruppenbezeichnung zugeordnet";
|
||||
$this->log_public.="\nder Student $this->mdl_user_firstname $this->mdl_user_lastname wurde der Gruppe $gruppenbezeichnung zugeordnet";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errormsg = 'Fehler beim Ermitteln der Zugeteilten Studenten';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Schaut ob eine Zuteilung von Person zu Gruppe
|
||||
* existiert
|
||||
* @param grouid ID der Gruppe
|
||||
* userid ID des Users
|
||||
* @return true wenn zugeteilt sonst false
|
||||
*/
|
||||
public function getGroupMember($groupid, $userid)
|
||||
{
|
||||
$client = new SoapClient($this->serverurl);
|
||||
$response = $client->core_group_get_group_members(array($groupid));
|
||||
|
||||
foreach($response as $row)
|
||||
{
|
||||
if(isset($row->id) && $row->id==$userid)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Legt eine Zuteilung eines Users zu
|
||||
* einer Gruppe an
|
||||
* @param groupid ID der Gruppe
|
||||
* userid ID des Users
|
||||
* @return boolean
|
||||
*/
|
||||
public function createGroupMember($groupid, $userid)
|
||||
{
|
||||
$client = new SoapClient($this->serverurl);
|
||||
$response = $client->core_group_add_group_members(array(array('groupid'=>$groupid, 'userid'=>$userid)));
|
||||
if(isset($response[0]))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt die ID einer MoodleGruppe
|
||||
* @param $mdl_course_id ID des Kurses
|
||||
* $gruppenbezeichnung Name der Gruppe
|
||||
* @return GruppenID wenn ok, false im Fehlerfall
|
||||
*/
|
||||
public function getGroup($mdl_course_id, $gruppenbezeichnung)
|
||||
{
|
||||
$client = new SoapClient($this->serverurl);
|
||||
$response = $client->core_group_get_course_groups($mdl_course_id);
|
||||
|
||||
foreach($response as $row)
|
||||
{
|
||||
if($row['name']==$gruppenbezeichnung)
|
||||
return $row['id'];
|
||||
}
|
||||
|
||||
$this->errormsg = "Gruppe wurde nicht gefunden $gruppenbezeichnung";
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Legt eine MoodleGruppe zu einem Kurs an
|
||||
* @param mdl_course_id ID des MoodleKuses
|
||||
* gruppenbezeichnung Bezeichnung der Gruppe
|
||||
* @return ID der Gruppe wenn ok, false im Fehlerfall
|
||||
*/
|
||||
public function createGroup($mdl_course_id, $gruppenbezeichnung)
|
||||
{
|
||||
$client = new SoapClient($this->serverurl);
|
||||
$data = new stdClass();
|
||||
$data->courseid=$mdl_course_id;
|
||||
$data->name = $gruppenbezeichnung;
|
||||
$data->description = $gruppenbezeichnung;
|
||||
|
||||
$response = $client->core_group_create_groups(array($data));
|
||||
|
||||
if(isset($response[0]))
|
||||
{
|
||||
return $response[0]['id'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errormsg = 'Fehler beim Anlegen der Gruppe';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Legt einen User im Moodle an
|
||||
* @param $uid UID der Person die angelegt werden soll
|
||||
* @return true wenn ok, false wenn Fehler
|
||||
*/
|
||||
public function createUser($uid)
|
||||
{
|
||||
$qry = "SELECT uid, vorname, nachname FROM campus.vw_benutzer WHERE uid=".$this->db_add_param($uid);
|
||||
if($this->db_query($qry))
|
||||
{
|
||||
if($row = $this->db_fetch_object())
|
||||
{
|
||||
$username = $row->uid;
|
||||
$vorname = $row->vorname;
|
||||
$nachname = $row->nachname;
|
||||
|
||||
$user = new stdClass();
|
||||
$user->username = $username;
|
||||
/*
|
||||
Passwort muss gesetzt werden damit das Anlegen funktioniert.
|
||||
Es wird ein random Passwort gesetzt
|
||||
Dieses wird beim Login nicht verwendet da ueber ldap authentifiziert wird.
|
||||
Prefix ist noetig damit es nicht zu Problemen kommt wenn
|
||||
im Moodle die Passwort Policy aktiviert ist
|
||||
*/
|
||||
$user->password = "FHCv!A2".hash('sha512', rand());
|
||||
$user->firstname = $vorname;
|
||||
$user->lastname = $nachname;
|
||||
$user->email = $username.'@'.DOMAIN;
|
||||
$user->auth = 'ldap';
|
||||
$user->idnumber = $username;
|
||||
$user->lang = 'de';
|
||||
|
||||
$client = new SoapClient($this->serverurl);
|
||||
$response = $client->core_user_create_users(array($user));
|
||||
|
||||
if(isset($response[0]))
|
||||
{
|
||||
$this->mdl_user_id = $response[0]['id'];
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errormsg = 'Fehler beim Laden des Users';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errormsg = 'Fehler beim Laden des Users';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->errormsg='Fehler beim Laden des Users';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Teilt die TestStudenten zu einem Testkurs zu
|
||||
* @param mdl_course_id ID des Moodle Kurses
|
||||
*/
|
||||
public function createTestStudentenZuordnung($mdl_course_id)
|
||||
{
|
||||
//Context des Kurses holen
|
||||
$mdlcourse = new moodle_course();
|
||||
|
||||
$users = array('student1', 'student2', 'student3');
|
||||
|
||||
foreach ($users as $row_user)
|
||||
{
|
||||
//MoodleID des Users holen
|
||||
if(!$this->loaduser($row_user))
|
||||
{
|
||||
$this->errormsg = "Fehler beim Laden des Users $row_user: $this->errormsg";
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = new stdClass();
|
||||
$data->roleid=5;
|
||||
$data->userid=$this->mdl_user_id;
|
||||
$data->courseid=$mdl_course_id;
|
||||
|
||||
$client = new SoapClient($this->serverurl);
|
||||
$client->enrol_manual_enrol_users(array($data));
|
||||
// WS-Funktion enrol_manual_enrol_users liefert immer null zurück
|
||||
// Fehler bei der Zuordnung koennen daher nicht abgefangen werden.
|
||||
// Eventuell sollten hier nochmals die Teilnehmer des Kurses geladen werden
|
||||
// um zu pruefen ob die Zuordnung erfolgreich war.
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ class variable extends basis_db
|
||||
public function __construct($uid=null, $name=null)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->variable= new stdClass();
|
||||
if($uid!=null && $name!=null)
|
||||
$this->load($uid, $name);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
FHComplete Moodle 2.4 Webservice Plugin
|
||||
=======================================
|
||||
|
||||
Mit diesem Plugin wird Moodle 2.4 um zusätzliche Webservices erweitert
|
||||
die für die Syncronisation mit FHComplete benötigt werden.
|
||||
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
- ) Zur Installation des Plugins muss der gesamte Ordner fhcompletews in den
|
||||
Ordner local der Moodleinstallation kopiert werden.
|
||||
|
||||
zB: cp /var/www/fhcomplete/system/moodlePlugin/fhcompletews /var/www/moodle/local/
|
||||
|
||||
- ) Danach muss die Moodle Startseite aufgerufen werden.
|
||||
Das neue Plugin wird automatisch erkannt uns installiert.
|
||||
|
||||
Sonstiges
|
||||
=========
|
||||
|
||||
Falls Änderungen am Plugin durchgeführt werden, muss in version.php die Versionsnummer erhöht werden
|
||||
damit Moodle die Änderung an dem Plugin erkennt und ein Update durchführt.
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Web service local plugin template external functions and service definitions.
|
||||
*
|
||||
* @package localwstemplate
|
||||
* @copyright 2011 Jerome Mouneyrac
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
// We defined the web service functions to install.
|
||||
$functions = array(
|
||||
'fhcomplete_courses_by_shortname' => array(
|
||||
'classname' => 'local_fhcompletews_external',
|
||||
'methodname' => 'get_courses_by_shortname',
|
||||
'classpath' => 'local/fhcompletews/externallib.php',
|
||||
'description' => 'Get course contents by Shortname',
|
||||
'type' => 'read',
|
||||
'capabilities'=> 'moodle/course:update,moodle/course:viewhiddencourses',
|
||||
),
|
||||
|
||||
'fhcomplete_user_get_users' => array(
|
||||
'classname' => 'local_fhcompletews_external',
|
||||
'methodname' => 'get_users',
|
||||
'classpath' => 'local/fhcompletews/externallib.php',
|
||||
'description' => 'get Users by Criteria',
|
||||
'type' => 'read',
|
||||
'capabilities'=> 'moodle/user:viewdetails, moodle/user:viewhiddendetails, moodle/course:useremail, moodle/user:update',
|
||||
),
|
||||
|
||||
);
|
||||
@@ -0,0 +1,484 @@
|
||||
<?php
|
||||
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* External Web Service Template
|
||||
*
|
||||
* @package localwstemplate
|
||||
* @copyright 2011 Moodle Pty Ltd (http://moodle.com)
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
require_once($CFG->libdir . "/externallib.php");
|
||||
|
||||
class local_fhcompletews_external extends external_api {
|
||||
|
||||
|
||||
|
||||
|
||||
public static function get_courses_by_shortname_parameters() {
|
||||
return new external_function_parameters(
|
||||
array('options' => new external_single_structure(
|
||||
array('shortnames' => new external_multiple_structure(
|
||||
new external_value(PARAM_RAW, 'Short Name')
|
||||
, 'List of short names. If empty return all courses
|
||||
except front page course.',
|
||||
VALUE_OPTIONAL)
|
||||
), 'options - operator OR is used', VALUE_DEFAULT, array())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get courses
|
||||
* @param array $options
|
||||
* @return array
|
||||
*/
|
||||
public static function get_courses_by_shortname($options) {
|
||||
global $CFG, $DB;
|
||||
require_once($CFG->dirroot . "/course/lib.php");
|
||||
|
||||
//validate parameter
|
||||
$params = self::validate_parameters(self::get_courses_by_shortname_parameters(),
|
||||
array('options' => $options));
|
||||
|
||||
//retrieve courses
|
||||
if (!key_exists('shortnames', $params['options'])
|
||||
or empty($params['options']['shortnames'])) {
|
||||
$courses = $DB->get_records('course');
|
||||
} else {
|
||||
$courses = $DB->get_records_list('course', 'shortname', $params['options']['shortnames']);
|
||||
}
|
||||
|
||||
//create return value
|
||||
$coursesinfo = array();
|
||||
foreach ($courses as $course) {
|
||||
|
||||
// now security checks
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
try {
|
||||
self::validate_context($context);
|
||||
} catch (Exception $e) {
|
||||
$exceptionparam = new stdClass();
|
||||
$exceptionparam->message = $e->getMessage();
|
||||
$exceptionparam->shortname = $course->shortname;
|
||||
throw new moodle_exception(
|
||||
get_string('errorcoursecontextnotvalid', 'webservice', $exceptionparam));
|
||||
}
|
||||
require_capability('moodle/course:view', $context);
|
||||
|
||||
$courseinfo = array();
|
||||
$courseinfo['id'] = $course->id;
|
||||
$courseinfo['fullname'] = $course->fullname;
|
||||
$courseinfo['shortname'] = $course->shortname;
|
||||
$courseinfo['categoryid'] = $course->category;
|
||||
$courseinfo['summary'] = $course->summary;
|
||||
$courseinfo['summaryformat'] = $course->summaryformat;
|
||||
$courseinfo['format'] = $course->format;
|
||||
$courseinfo['startdate'] = $course->startdate;
|
||||
$courseinfo['numsections'] = $course->numsections;
|
||||
|
||||
//some field should be returned only if the user has update permission
|
||||
$courseadmin = has_capability('moodle/course:update', $context);
|
||||
if ($courseadmin) {
|
||||
$courseinfo['categorysortorder'] = $course->sortorder;
|
||||
$courseinfo['idnumber'] = $course->idnumber;
|
||||
$courseinfo['showgrades'] = $course->showgrades;
|
||||
$courseinfo['showreports'] = $course->showreports;
|
||||
$courseinfo['newsitems'] = $course->newsitems;
|
||||
$courseinfo['visible'] = $course->visible;
|
||||
$courseinfo['maxbytes'] = $course->maxbytes;
|
||||
$courseinfo['hiddensections'] = $course->hiddensections;
|
||||
$courseinfo['groupmode'] = $course->groupmode;
|
||||
$courseinfo['groupmodeforce'] = $course->groupmodeforce;
|
||||
$courseinfo['defaultgroupingid'] = $course->defaultgroupingid;
|
||||
$courseinfo['lang'] = $course->lang;
|
||||
$courseinfo['timecreated'] = $course->timecreated;
|
||||
$courseinfo['timemodified'] = $course->timemodified;
|
||||
$courseinfo['forcetheme'] = $course->theme;
|
||||
$courseinfo['enablecompletion'] = $course->enablecompletion;
|
||||
$courseinfo['completionstartonenrol'] = $course->completionstartonenrol;
|
||||
$courseinfo['completionnotify'] = $course->completionnotify;
|
||||
}
|
||||
|
||||
if ($courseadmin or $course->visible
|
||||
or has_capability('moodle/course:viewhiddencourses', $context)) {
|
||||
$coursesinfo[] = $courseinfo;
|
||||
}
|
||||
}
|
||||
|
||||
return $coursesinfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* @return external_description
|
||||
*/
|
||||
public static function get_courses_by_shortname_returns() {
|
||||
return new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'id' => new external_value(PARAM_INT, 'course id'),
|
||||
'shortname' => new external_value(PARAM_TEXT, 'course short name'),
|
||||
'categoryid' => new external_value(PARAM_INT, 'category id'),
|
||||
'categorysortorder' => new external_value(PARAM_INT,
|
||||
'sort order into the category', VALUE_OPTIONAL),
|
||||
'fullname' => new external_value(PARAM_TEXT, 'full name'),
|
||||
'idnumber' => new external_value(PARAM_RAW, 'id number', VALUE_OPTIONAL),
|
||||
'summary' => new external_value(PARAM_RAW, 'summary'),
|
||||
'summaryformat' => new external_value(PARAM_INT,
|
||||
'the summary text Moodle format'),
|
||||
'format' => new external_value(PARAM_ALPHANUMEXT,
|
||||
'course format: weeks, topics, social, site,..'),
|
||||
'showgrades' => new external_value(PARAM_INT,
|
||||
'1 if grades are shown, otherwise 0', VALUE_OPTIONAL),
|
||||
'newsitems' => new external_value(PARAM_INT,
|
||||
'number of recent items appearing on the course page', VALUE_OPTIONAL),
|
||||
'startdate' => new external_value(PARAM_INT,
|
||||
'timestamp when the course start'),
|
||||
'numsections' => new external_value(PARAM_INT, 'number of weeks/topics'),
|
||||
'maxbytes' => new external_value(PARAM_INT,
|
||||
'largest size of file that can be uploaded into the course',
|
||||
VALUE_OPTIONAL),
|
||||
'showreports' => new external_value(PARAM_INT,
|
||||
'are activity report shown (yes = 1, no =0)', VALUE_OPTIONAL),
|
||||
'visible' => new external_value(PARAM_INT,
|
||||
'1: available to student, 0:not available', VALUE_OPTIONAL),
|
||||
'hiddensections' => new external_value(PARAM_INT,
|
||||
'How the hidden sections in the course are displayed to students',
|
||||
VALUE_OPTIONAL),
|
||||
'groupmode' => new external_value(PARAM_INT, 'no group, separate, visible',
|
||||
VALUE_OPTIONAL),
|
||||
'groupmodeforce' => new external_value(PARAM_INT, '1: yes, 0: no',
|
||||
VALUE_OPTIONAL),
|
||||
'defaultgroupingid' => new external_value(PARAM_INT, 'default grouping id',
|
||||
VALUE_OPTIONAL),
|
||||
'timecreated' => new external_value(PARAM_INT,
|
||||
'timestamp when the course have been created', VALUE_OPTIONAL),
|
||||
'timemodified' => new external_value(PARAM_INT,
|
||||
'timestamp when the course have been modified', VALUE_OPTIONAL),
|
||||
'enablecompletion' => new external_value(PARAM_INT,
|
||||
'Enabled, control via completion and activity settings. Disbaled,
|
||||
not shown in activity settings.',
|
||||
VALUE_OPTIONAL),
|
||||
'completionstartonenrol' => new external_value(PARAM_INT,
|
||||
'1: begin tracking a student\'s progress in course completion
|
||||
after course enrolment. 0: does not',
|
||||
VALUE_OPTIONAL),
|
||||
'completionnotify' => new external_value(PARAM_INT,
|
||||
'1: yes 0: no', VALUE_OPTIONAL),
|
||||
'lang' => new external_value(PARAM_ALPHANUMEXT,
|
||||
'forced course language', VALUE_OPTIONAL),
|
||||
'forcetheme' => new external_value(PARAM_ALPHANUMEXT,
|
||||
'name of the force theme', VALUE_OPTIONAL),
|
||||
), 'course'
|
||||
)
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Returns description of get_users() parameters.
|
||||
*
|
||||
* @return external_function_parameters
|
||||
* @since Moodle 2.5
|
||||
*/
|
||||
public static function get_users_parameters() {
|
||||
return new external_function_parameters(
|
||||
array(
|
||||
'criteria' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'key' => new external_value(PARAM_ALPHA, 'the user column to search, expected keys (value format) are:
|
||||
"id" (int) matching user id,
|
||||
"lastname" (string) user last name (Note: you can use % for searching but it may be considerably slower!),
|
||||
"firstname" (string) user first name (Note: you can use % for searching but it may be considerably slower!),
|
||||
"idnumber" (string) matching user idnumber,
|
||||
"username" (string) matching user username,
|
||||
"email" (string) user email (Note: you can use % for searching but it may be considerably slower!),
|
||||
"auth" (string) matching user auth plugin'),
|
||||
'value' => new external_value(PARAM_RAW, 'the value to search')
|
||||
)
|
||||
), 'the key/value pairs to be considered in user search. Values can not be empty.
|
||||
Specify different keys only once (fullname => \'user1\', auth => \'manual\', ...) -
|
||||
key occurences are forbidden.
|
||||
The search is executed with AND operator on the criterias. Invalid criterias (keys) are ignored,
|
||||
the search is still executed on the valid criterias.
|
||||
You can search without criteria, but the function is not designed for it.
|
||||
It could very slow or timeout. The function is designed to search some specific users.'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve matching user.
|
||||
*
|
||||
* @param array $criteria the allowed array keys are id/lastname/firstname/idnumber/username/email/auth.
|
||||
* @return array An array of arrays containing user profiles.
|
||||
* @since Moodle 2.5
|
||||
*/
|
||||
public static function get_users($criteria = array()) {
|
||||
global $CFG, $USER, $DB;
|
||||
|
||||
require_once($CFG->dirroot . "/user/lib.php");
|
||||
|
||||
$params = self::validate_parameters(self::get_users_parameters(),
|
||||
array('criteria' => $criteria));
|
||||
|
||||
// Validate the criteria and retrieve the users.
|
||||
$users = array();
|
||||
$warnings = array();
|
||||
$sqlparams = array();
|
||||
$usedkeys = array();
|
||||
|
||||
// Do not retrieve deleted users.
|
||||
$sql = ' deleted = 0';
|
||||
|
||||
foreach ($params['criteria'] as $criteriaindex => $criteria) {
|
||||
|
||||
// Check that the criteria has never been used.
|
||||
if (array_key_exists($criteria['key'], $usedkeys)) {
|
||||
throw new moodle_exception('keyalreadyset', '', '', null, 'The key ' . $criteria['key'] . ' can only be sent once');
|
||||
} else {
|
||||
$usedkeys[$criteria['key']] = true;
|
||||
}
|
||||
|
||||
$invalidcriteria = false;
|
||||
// Clean the parameters.
|
||||
$paramtype = PARAM_RAW;
|
||||
switch ($criteria['key']) {
|
||||
case 'id':
|
||||
$paramtype = PARAM_INT;
|
||||
break;
|
||||
case 'idnumber':
|
||||
$paramtype = PARAM_RAW;
|
||||
break;
|
||||
case 'username':
|
||||
$paramtype = PARAM_RAW;
|
||||
break;
|
||||
case 'email':
|
||||
// We use PARAM_RAW to allow searches with %.
|
||||
$paramtype = PARAM_RAW;
|
||||
break;
|
||||
case 'auth':
|
||||
$paramtype = PARAM_AUTH;
|
||||
break;
|
||||
case 'lastname':
|
||||
case 'firstname':
|
||||
$paramtype = PARAM_TEXT;
|
||||
break;
|
||||
default:
|
||||
// Send back a warning that this search key is not supported in this version.
|
||||
// This warning will make the function extandable without breaking clients.
|
||||
$warnings[] = array(
|
||||
'item' => $criteria['key'],
|
||||
'warningcode' => 'invalidfieldparameter',
|
||||
'message' => 'The search key \'' . $criteria['key'] . '\' is not supported, look at the web service documentation'
|
||||
);
|
||||
// Do not add this invalid criteria to the created SQL request.
|
||||
$invalidcriteria = true;
|
||||
unset($params['criteria'][$criteriaindex]);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!$invalidcriteria) {
|
||||
$cleanedvalue = clean_param($criteria['value'], $paramtype);
|
||||
|
||||
$sql .= ' AND ';
|
||||
|
||||
// Create the SQL.
|
||||
switch ($criteria['key']) {
|
||||
case 'id':
|
||||
case 'idnumber':
|
||||
case 'username':
|
||||
case 'auth':
|
||||
$sql .= $criteria['key'] . ' = :' . $criteria['key'];
|
||||
$sqlparams[$criteria['key']] = $cleanedvalue;
|
||||
break;
|
||||
case 'email':
|
||||
case 'lastname':
|
||||
case 'firstname':
|
||||
$sql .= $DB->sql_like($criteria['key'], ':' . $criteria['key'], false);
|
||||
$sqlparams[$criteria['key']] = $cleanedvalue;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$users = $DB->get_records_select('user', $sql, $sqlparams, 'id ASC');
|
||||
|
||||
// Finally retrieve each users information.
|
||||
$returnedusers = array();
|
||||
foreach ($users as $user) {
|
||||
$userdetails = user_get_user_details_courses($user);
|
||||
|
||||
// Return the user only if all the searched fields are returned.
|
||||
// Otherwise it means that the $USER was not allowed to search the returned user.
|
||||
if (!empty($userdetails)) {
|
||||
$validuser = true;
|
||||
|
||||
foreach($params['criteria'] as $criteria) {
|
||||
if (empty($userdetails[$criteria['key']])) {
|
||||
$validuser = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($validuser) {
|
||||
$returnedusers[] = $userdetails;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array('users' => $returnedusers, 'warnings' => $warnings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of get_users result value.
|
||||
*
|
||||
* @return external_description
|
||||
* @since Moodle 2.5
|
||||
*/
|
||||
public static function get_users_returns() {
|
||||
return new external_single_structure(
|
||||
array('users' => new external_multiple_structure(
|
||||
self::user_description()
|
||||
),
|
||||
'warnings' => new external_warnings('always set to \'key\'', 'faulty key name')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create user return value description.
|
||||
*
|
||||
* @param array $additionalfields some additional field
|
||||
* @return single_structure_description
|
||||
*/
|
||||
public static function user_description($additionalfields = array()) {
|
||||
$userfields = array(
|
||||
'id' => new external_value(PARAM_INT, 'ID of the user'),
|
||||
'username' => new external_value(PARAM_RAW, 'The username', VALUE_OPTIONAL),
|
||||
'firstname' => new external_value(PARAM_NOTAGS, 'The first name(s) of the user', VALUE_OPTIONAL),
|
||||
'lastname' => new external_value(PARAM_NOTAGS, 'The family name of the user', VALUE_OPTIONAL),
|
||||
'fullname' => new external_value(PARAM_NOTAGS, 'The fullname of the user'),
|
||||
'email' => new external_value(PARAM_TEXT, 'An email address - allow email as root@localhost', VALUE_OPTIONAL),
|
||||
'address' => new external_value(PARAM_TEXT, 'Postal address', VALUE_OPTIONAL),
|
||||
'phone1' => new external_value(PARAM_NOTAGS, 'Phone 1', VALUE_OPTIONAL),
|
||||
'phone2' => new external_value(PARAM_NOTAGS, 'Phone 2', VALUE_OPTIONAL),
|
||||
'icq' => new external_value(PARAM_NOTAGS, 'icq number', VALUE_OPTIONAL),
|
||||
'skype' => new external_value(PARAM_NOTAGS, 'skype id', VALUE_OPTIONAL),
|
||||
'yahoo' => new external_value(PARAM_NOTAGS, 'yahoo id', VALUE_OPTIONAL),
|
||||
'aim' => new external_value(PARAM_NOTAGS, 'aim id', VALUE_OPTIONAL),
|
||||
'msn' => new external_value(PARAM_NOTAGS, 'msn number', VALUE_OPTIONAL),
|
||||
'department' => new external_value(PARAM_TEXT, 'department', VALUE_OPTIONAL),
|
||||
'institution' => new external_value(PARAM_TEXT, 'institution', VALUE_OPTIONAL),
|
||||
'idnumber' => new external_value(PARAM_RAW, 'An arbitrary ID code number perhaps from the institution', VALUE_OPTIONAL),
|
||||
'interests' => new external_value(PARAM_TEXT, 'user interests (separated by commas)', VALUE_OPTIONAL),
|
||||
'firstaccess' => new external_value(PARAM_INT, 'first access to the site (0 if never)', VALUE_OPTIONAL),
|
||||
'lastaccess' => new external_value(PARAM_INT, 'last access to the site (0 if never)', VALUE_OPTIONAL),
|
||||
'auth' => new external_value(PARAM_PLUGIN, 'Auth plugins include manual, ldap, imap, etc', VALUE_OPTIONAL),
|
||||
'confirmed' => new external_value(PARAM_INT, 'Active user: 1 if confirmed, 0 otherwise', VALUE_OPTIONAL),
|
||||
'lang' => new external_value(PARAM_SAFEDIR, 'Language code such as "en", must exist on server', VALUE_OPTIONAL),
|
||||
'theme' => new external_value(PARAM_PLUGIN, 'Theme name such as "standard", must exist on server', VALUE_OPTIONAL),
|
||||
'timezone' => new external_value(PARAM_TIMEZONE, 'Timezone code such as Australia/Perth, or 99 for default', VALUE_OPTIONAL),
|
||||
'mailformat' => new external_value(PARAM_INT, 'Mail format code is 0 for plain text, 1 for HTML etc', VALUE_OPTIONAL),
|
||||
'description' => new external_value(PARAM_RAW, 'User profile description', VALUE_OPTIONAL),
|
||||
'descriptionformat' => new external_format_value('description', VALUE_OPTIONAL),
|
||||
'city' => new external_value(PARAM_NOTAGS, 'Home city of the user', VALUE_OPTIONAL),
|
||||
'url' => new external_value(PARAM_URL, 'URL of the user', VALUE_OPTIONAL),
|
||||
'country' => new external_value(PARAM_ALPHA, 'Home country code of the user, such as AU or CZ', VALUE_OPTIONAL),
|
||||
'profileimageurlsmall' => new external_value(PARAM_URL, 'User image profile URL - small version'),
|
||||
'profileimageurl' => new external_value(PARAM_URL, 'User image profile URL - big version'),
|
||||
'customfields' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'type' => new external_value(PARAM_ALPHANUMEXT, 'The type of the custom field - text field, checkbox...'),
|
||||
'value' => new external_value(PARAM_RAW, 'The value of the custom field'),
|
||||
'name' => new external_value(PARAM_RAW, 'The name of the custom field'),
|
||||
'shortname' => new external_value(PARAM_RAW, 'The shortname of the custom field - to be able to build the field class in the code'),
|
||||
)
|
||||
), 'User custom fields (also known as user profile fields)', VALUE_OPTIONAL),
|
||||
'preferences' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'name' => new external_value(PARAM_ALPHANUMEXT, 'The name of the preferences'),
|
||||
'value' => new external_value(PARAM_RAW, 'The value of the custom field'),
|
||||
)
|
||||
), 'Users preferences', VALUE_OPTIONAL)
|
||||
);
|
||||
if (!empty($additionalfields)) {
|
||||
$userfields = array_merge($userfields, $additionalfields);
|
||||
}
|
||||
return new external_single_structure($userfields);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to obtain user details, either recurring directly to the user's system profile
|
||||
* or through one of the user's course enrollments (course profile).
|
||||
*
|
||||
* @param object $user The user.
|
||||
* @return array if unsuccessful or the allowed user details.
|
||||
*/
|
||||
function user_get_user_details_courses($user) {
|
||||
global $USER;
|
||||
$userdetails = null;
|
||||
|
||||
// Get the courses that the user is enrolled in (only active).
|
||||
$courses = enrol_get_users_courses($user->id, true);
|
||||
|
||||
$systemprofile = false;
|
||||
if (can_view_user_details_cap($user) || ($user->id == $USER->id) || has_coursecontact_role($user->id)) {
|
||||
$systemprofile = true;
|
||||
}
|
||||
|
||||
// Try using system profile.
|
||||
if ($systemprofile) {
|
||||
$userdetails = user_get_user_details($user, null);
|
||||
} else {
|
||||
// Try through course profile.
|
||||
foreach ($courses as $course) {
|
||||
if ($can_view_user_details_cap($user, $course) || ($user->id == $USER->id) || has_coursecontact_role($user->id)) {
|
||||
$userdetails = user_get_user_details($user, $course);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $userdetails;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if $USER have the necessary capabilities to obtain user details.
|
||||
*
|
||||
* @param object $user
|
||||
* @param object $course if null then only consider system profile otherwise also consider the course's profile.
|
||||
* @return bool true if $USER can view user details.
|
||||
*/
|
||||
function can_view_user_details_cap($user, $course = null) {
|
||||
// Check $USER has the capability to view the user details at user context.
|
||||
$usercontext = get_context_instance(CONTEXT_USER, $user->id);
|
||||
$result = has_capability('moodle/user:viewdetails', $usercontext);
|
||||
// Otherwise can $USER see them at course context.
|
||||
if (!$result && !empty($course)) {
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
$result = has_capability('moodle/user:viewdetails', $context);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Web service template plugin related strings
|
||||
* @package localwstemplate
|
||||
* @copyright 2011 Moodle Pty Ltd (http://moodle.com)
|
||||
* @author Jerome Mouneyrac
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['pluginname'] = 'FH Complete Web service Plugin';
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
$plugin->version = 2013022105; // The (date) version of this module + 2 extra digital for daily versions
|
||||
// This version number is displayed into /admin/forms.php
|
||||
// TODO: if ever this plugin get branched, the old branch number
|
||||
// will not be updated to the current date but just incremented. We will
|
||||
// need then a $plugin->release human friendly date. For the moment, we use
|
||||
// display this version number with userdate (dev friendly)
|
||||
$plugin->requires = 2010112400; // Requires this Moodle version - at least 2.0
|
||||
$plugin->cron = 0;
|
||||
$plugin->release = '1.0 (Build: 2013022105)';
|
||||
$plugin->maturity = MATURITY_STABLE;
|
||||
Reference in New Issue
Block a user