本文整理汇总了PHP中enrol_plugin::add_instance方法的典型用法代码示例。如果您正苦于以下问题:PHP enrol_plugin::add_instance方法的具体用法?PHP enrol_plugin::add_instance怎么用?PHP enrol_plugin::add_instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类enrol_plugin
的用法示例。
在下文中一共展示了enrol_plugin::add_instance方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_instance
/**
* Add new instance of enrol plugin.
* @param stdClass $course
* @param array instance fields
* @return int id of new instance, null if can not be created
*/
public function add_instance($course, array $fields = NULL)
{
global $DB;
if ($DB->record_exists('enrol', array('courseid' => $course->id, 'enrol' => 'manual'))) {
// only one instance allowed, sorry
return NULL;
}
return parent::add_instance($course, $fields);
}
示例2: add_instance
/**
* Add new instance of enrol plugin.
* @param object $course
* @param array $fields instance fields
* @return int id of new instance, null if can not be created
*/
public function add_instance($course, array $fields = null)
{
// In the form we are representing 2 db columns with one field.
if (!empty($fields) && !empty($fields['expirynotify'])) {
if ($fields['expirynotify'] == 2) {
$fields['expirynotify'] = 1;
$fields['notifyall'] = 1;
} else {
$fields['notifyall'] = 0;
}
}
return parent::add_instance($course, $fields);
}
示例3: add_instance
/**
* Add new instance of enrol plugin.
* @param object $course
* @param array $fields instance fields
* @return int id of new instance, null if can not be created
*/
public function add_instance($course, array $fields = null)
{
global $CFG;
require_once "{$CFG->dirroot}/enrol/meta/locallib.php";
if (!empty($fields['customint2']) && $fields['customint2'] == ENROL_META_CREATE_GROUP) {
$context = context_course::instance($course->id);
require_capability('moodle/course:managegroups', $context);
$groupid = enrol_meta_create_new_group($course->id, $fields['customint1']);
$fields['customint2'] = $groupid;
}
$result = parent::add_instance($course, $fields);
enrol_meta_sync($course->id);
return $result;
}
示例4: restore_instance
/**
* Restore instance and map settings.
*
* @param restore_enrolments_structure_step $step
* @param stdClass $data
* @param stdClass $course
* @param int $oldid
*/
public function restore_instance(restore_enrolments_structure_step $step, stdClass $data, $course, $oldid)
{
// We want to call the parent because we do not want to add an enrol_lti_tools row
// as that is done as part of the restore process.
$instanceid = parent::add_instance($course, (array) $data);
$step->set_mapping('enrol', $oldid, $instanceid);
}
示例5: add_instance
/**
* Add new instance of enrol plugin.
* @param object $course
* @param array $fields instance fields
* @return int id of last instance, null if can not be created
*/
public function add_instance($course, array $fields = null)
{
global $CFG;
require_once "{$CFG->dirroot}/enrol/meta/locallib.php";
// Support creating multiple at once.
if (is_array($fields['customint1'])) {
$courses = array_unique($fields['customint1']);
} else {
$courses = array($fields['customint1']);
}
foreach ($courses as $courseid) {
if (!empty($fields['customint2']) && $fields['customint2'] == ENROL_META_CREATE_GROUP) {
$context = context_course::instance($course->id);
require_capability('moodle/course:managegroups', $context);
$groupid = enrol_meta_create_new_group($course->id, $courseid);
$fields['customint2'] = $groupid;
}
$fields['customint1'] = $courseid;
$result = parent::add_instance($course, $fields);
}
enrol_meta_sync($course->id);
return $result;
}
示例6: add_instance
/**
* Ensures existence instance of enrol plugin.
*
* @param object $course
* @param array $fields
* @return int Id of instance, null if can not be created.
*/
public function add_instance($course, array $fields = null)
{
global $DB;
if ($result = $DB->get_record('enrol', array('courseid' => $course->id, 'enrol' => 'invitation'))) {
// Instance already exists, so just give id.
return $result->id;
}
return parent::add_instance($course, $fields);
}
示例7: add_instance
public function add_instance($course, array $fields = NULL)
{
global $USER, $DB;
if ($fields['customchar3']) {
$boletooptions = json_decode($fields['customchar3']);
if (!($instanceid = parent::add_instance($course, $fields))) {
return false;
}
$boleto = new stdclass();
$boleto->enrolid = $instanceid;
$boleto->sacado = fullname($USER);
$boleto->timecreated = time();
$numerodocumento = $this->get_numero_documento_sem_parcela($instanceid, $course->id);
if (count($boletooptions->parcelas) > 1) {
$boleto->name = get_string('paymenparcelado', 'enrol_boleto') . ' - ' . $numerodocumento;
} else {
$boleto->name = get_string('paymentavista', 'enrol_boleto') . ' - ' . $numerodocumento;
}
foreach ($boletooptions->parcelas as $parcela => $valor) {
$boleto->totalprice = $valor;
$boleto->parcela = $parcela;
$boleto->numerodocumento = $numerodocumento . $parcela;
$DB->insert_record('enrol_boleto', $boleto);
}
return $instanceid;
} else {
return false;
}
}
示例8: add_instance
/**
* Add new instance of enrol plugin.
* @param object $course
* @param array instance fields
* @return int id of new instance, null if can not be created
*/
public function add_instance($course, array $fields = null)
{
global $DB;
if ($DB->record_exists('enrol', array('courseid' => $course->id, 'enrol' => 'restxml'))) {
return null;
}
return parent::add_instance($course, $fields);
}