Created
July 11, 2022 19:38
-
-
Save vrhvid/6c33caf99cd590d5929ad055745d7784 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace local_vissync; //namespace->oznaka direktorija, v katerem se nahaja | |
defined('MOODLE_INTERNAL') || die(); //dostop do te .php datoteke dovolimo samo znotraj moodla, do nje ni mogoče dostopati direktno preko url-ja | |
class sync{ | |
public function do_sync(){ | |
global $CFG, $DB, $OUTPUT; //globalni objekti za delo z moodlom; $CFG->delo z vrednostmi v konfiguracijski datoteki; $DB->dostop do moodlove db; $OUTPUT->prikaz strani | |
require_once($CFG->dirroot. '/course/lib.php'); //naložimo moodlove knjižnice, ki se nahajajo na korenskem moodlovemu direktoriju + dodani poti;korenski direktorij definiran v konfiguracijski datoteki | |
require_once($CFG->dirroot. '/user/lib.php'); //$CFG->dirroot = /var/www/html/ | |
require_once($CFG->dirroot. '/enrol/locallib.php'); | |
require_once(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php'); //naložimo /var/www/html/config.php | |
$config = (array) get_config('local_vissync'); | |
if($config['sync_students']){ //če je v nastvitvah izbrana možnost sinhronizacije študentov( Synchronize students?, | |
$customfields = array(); | |
if(!($DB->record_exists('user_info_field', array('shortname' => "Program")))){ | |
$polje = new \stdClass(); | |
$polje->shortname = 'Program'; | |
$polje->name = 'Program'; | |
$polje->datatype = 'text'; | |
$polje->categoryid = 1; | |
$polje->locked = 1; | |
$polje->visible = 2; | |
$polje->description = ''; | |
$polje->defaultdata = ''; | |
$polje->descriptionformat = 1; | |
$polje->sortorder = 1; | |
$polje->defaultdata = ""; | |
$polje->param1 = 100; | |
$polje->param2 = ""; | |
$polje->param3 = ""; | |
$polje->param4 = ""; | |
$polje->param5 = ""; | |
try{ | |
$polje->id = $DB->insert_record('user_info_field', $polje); | |
} catch(\dml_exception $de) { | |
$result['err_messages'][] = "Could not create field: " . $polje->name . ". Message: " . $de->getMessage(); | |
sync::wf("Could not create field: " . $polje->name . ". Message: " . $de->getMessage(), 'create_field_error'); | |
} catch(\moodle_exception $me){ | |
$result['err_messages'][] = "Could not create field: " . $polje->name . ". Message: " . $me->getMessage(); | |
sync::wf("Could not create student user: " . $polje->name . ". Message: " . $me->getMessage(), 'me_create_student_error'); | |
} | |
} | |
if(!($DB->record_exists('user_info_field', array('shortname' => "Smer")))){ | |
$polje = new \stdClass(); | |
$polje->shortname = 'Smer'; | |
$polje->name = 'Smer'; | |
$polje->datatype = 'text'; | |
$polje->categoryid = 1; | |
$polje->locked = 1; | |
$polje->visible = 2; | |
$polje->description = ''; | |
$polje->defaultdata = ''; | |
$polje->descriptionformat = 1; | |
$polje->sortorder = 2; | |
$polje->defaultdata = ""; | |
$polje->param1 = 60; | |
$polje->param2 = ""; | |
$polje->param3 = ""; | |
$polje->param4 = ""; | |
$polje->param5 = ""; | |
try{ | |
$id = $DB->insert_record('user_info_field', $polje, true); | |
$polje->id = $id; | |
echo $OUTPUT->notification(print_object($id)); | |
echo $OUTPUT->notification($polje->id); | |
$customfields('Smer') = $polje->id; | |
} catch(\dml_exception $de) { | |
$result['err_messages'][] = "Could not create field: " . $polje->name . ". Message: " . $de->getMessage(); | |
sync::wf("Could not create field: " . $polje->name . ". Message: " . $de->getMessage(), 'create_field_error'); | |
} catch(\moodle_exception $me){ | |
$result['err_messages'][] = "Could not create field: " . $polje->name . ". Message: " . $me->getMessage(); | |
sync::wf("Could not create student user: " . $polje->name . ". Message: " . $me->getMessage(), 'me_create_student_error'); | |
} | |
} | |
if(!($DB->record_exists('user_info_field', array('shortname' => "Letnik")))){ | |
$polje = new \stdClass(); | |
$polje->shortname = 'Letnik'; | |
$polje->name = 'Letnik'; | |
$polje->datatype = 'text'; | |
$polje->categoryid = 1; | |
$polje->locked = 1; | |
$polje->visible = 2; | |
$polje->description = ''; | |
$polje->defaultdata = ''; | |
$polje->descriptionformat = 1; | |
$polje->sortorder = 3; | |
$polje->defaultdata = ""; | |
$polje->param1 = 10; | |
$polje->param2 = ""; | |
$polje->param3 = ""; | |
$polje->param4 = ""; | |
$polje->param5 = ""; | |
try{ | |
$polje->id = $DB->insert_record('user_info_field', $polje); | |
} catch(\dml_exception $de) { | |
$result['err_messages'][] = "Could not create field: " . $polje->name . ". Message: " . $de->getMessage(); | |
sync::wf("Could not create field: " . $polje->name . ". Message: " . $de->getMessage(), 'create_field_error'); | |
} catch(\moodle_exception $me){ | |
$result['err_messages'][] = "Could not create field: " . $polje->name . ". Message: " . $me->getMessage(); | |
sync::wf("Could not create student user: " . $polje->name . ". Message: " . $me->getMessage(), 'me_create_student_error'); | |
} | |
} | |
echo var_dump($customfields); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment