Пример #1
0
/**
 * moodle_profile_field_save_form_data - saves form specific sync settings for moodle profile fields
 *
 * @param object $form        the custom field form object submitted
 * @param object $field       the field object to save moodle_profile field_owner object for
 * @param object $data        the submitted form data to save
 * @uses  $DB
 */
function moodleprofile_field_save_form_data($form, $field, $data)
{
    global $DB;
    $level = required_param('level', PARAM_ACTION);
    if ($level != 'user' || !isset($data->moodle_profile_exclusive)) {
        return;
        // not user context or sync was disabled
    }
    if ($data->moodle_profile_exclusive == pm_moodle_profile::sync_to_moodle || $data->moodle_profile_exclusive == pm_moodle_profile::sync_from_moodle) {
        if (isset($field->owners['moodle_profile'])) {
            $owner = new field_owner($field->owners['moodle_profile']);
            $owner->exclude = $data->moodle_profile_exclusive;
        } else {
            $owner = new field_owner();
            $owner->fieldid = $field->id;
            $owner->plugin = 'moodle_profile';
            $owner->exclude = $data->moodle_profile_exclusive;
        }
        $owner->save();
        unset($field->owners);
        // force reload of owners field
        sync_profile_field_with_moodle($field);
    } else {
        $DB->delete_records(field_owner::TABLE, array('fieldid' => $field->id, 'plugin' => 'moodle_profile'));
    }
}
Пример #2
0
function moodle_profile_field_save_form_data($form, $field, $data)
{
    $level = $form->_customdata->required_param('level', PARAM_ACTION);
    if ($level != 'user') {
        return;
    }
    global $CURMAN;
    if ($data->moodle_profile_exclusive == cm_moodle_profile::sync_to_moodle || $data->moodle_profile_exclusive == cm_moodle_profile::sync_from_moodle) {
        if (isset($field->owners['moodle_profile'])) {
            $owner = new field_owner($field->owners['moodle_profile']);
            $owner->exclude = $data->moodle_profile_exclusive;
            $owner->update();
        } else {
            $owner = new field_owner();
            $owner->fieldid = $field->id;
            $owner->plugin = 'moodle_profile';
            $owner->exclude = $data->moodle_profile_exclusive;
            $owner->add();
        }
        unset($field->owners);
        // force reload of owners field
        sync_profile_field_with_moodle($field);
    } else {
        $CURMAN->db->delete_records(FIELDOWNERTABLE, 'fieldid', $field->id, 'plugin', 'moodle_profile');
    }
}
Пример #3
0
 function display_forceresync()
 {
     global $CFG, $OUTPUT;
     $confirm = $this->optional_param('confirm', 0, PARAM_INT);
     if (!$confirm) {
         $optionsyes = array('s' => 'field', 'action' => 'forceresync', 'confirm' => 1);
         $optionsno = array('s' => 'field', 'level' => 'user');
         $buttoncontinue = new single_button(new moodle_url('index.php', $optionsyes), get_string('yes'), 'POST');
         $buttoncancel = new single_button(new moodle_url('index.php', $optionsno), get_string('no'), 'GET');
         echo $OUTPUT->confirm(get_string('field_confirm_force_resync', 'local_elisprogram'), $buttoncontinue, $buttoncancel);
     } else {
         print_string('field_resyncing', 'local_elisprogram');
         $fields = field::get_for_context_level(CONTEXT_ELIS_USER);
         $fields = $fields ? $fields : array();
         require_once elis::plugin_file('elisfields_moodleprofile', 'custom_fields.php');
         foreach ($fields as $field) {
             $fieldobj = new field($field);
             sync_profile_field_with_moodle($fieldobj);
         }
         $tmppage = new customfieldpage(array('level' => 'user'));
         redirect($tmppage->url, get_string('continue'));
     }
 }
 function action_forceresync()
 {
     $confirm = $this->optional_param('confirm', 0, PARAM_INT);
     if (!$confirm) {
         notice_yesno(get_string('field_confirm_force_resync', 'block_curr_admin'), 'index.php', 'index.php', array('s' => 'field', 'action' => 'forceresync', 'confirm' => 1), array('s' => 'field', 'level' => 'user'), 'post', 'get');
     } else {
         print_string('field_resyncing', 'block_curr_admin');
         $ctxlvl = context_level_base::get_custom_context_level('user', 'block_curr_admin');
         if (!$ctxlvl) {
             print_error('invalid_context_level', 'block_curr_admin');
         }
         $fields = field::get_for_context_level($ctxlvl);
         $fields = $fields ? $fields : array();
         require_once CURMAN_DIRLOCATION . '/plugins/moodle_profile/custom_fields.php';
         foreach ($fields as $field) {
             $fieldobj = new field($field);
             sync_profile_field_with_moodle($fieldobj);
         }
         $tmppage = new customfieldpage(array('level' => 'user'));
         redirect($tmppage->get_url(), get_string('continue'));
     }
 }