Пример #1
0
/**
 * ELIS(TM): Enterprise Learning Intelligence Suite
 * Copyright (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net
 *
 * 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 3 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, see <http://www.gnu.org/licenses/>.
 *
 * @package    elis
 * @subpackage curriculummanagement
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net
 *
 */
function xmldb_crlm_cluster_groups_upgrade($oldversion = 0)
{
    global $CFG, $THEME, $db;
    $result = true;
    if ($result && $oldversion < 2010080602) {
        require_once $CFG->dirroot . '/curriculum/lib/customfield.class.php';
        require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/lib.php';
        require_once $CFG->dirroot . '/curriculum/plugins/cluster_classification/clusterclassification.class.php';
        $field = new field(field::get_for_context_level_with_name('cluster', 'cluster_group'));
        if (isset($field->owners['manual'])) {
            $owner = new field_owner($field->owners['manual']);
            $owner->param_help_file = 'crlm_cluster_groups/cluster_groups';
            $owner->update();
        }
    }
    if ($result && $oldversion < 2010080603) {
        //retrieve the cluster context
        $context = context_level_base::get_custom_context_level('cluster', 'block_curr_admin');
        //get the cluster classification category
        $category = new field_category();
        $category->name = get_string('cluster_group_category', 'crlm_cluster_groups');
        $field = new field();
        $field->shortname = 'cluster_groupings';
        $field->name = get_string('autoenrol_groupings', 'crlm_cluster_classification');
        $field->datatype = 'bool';
        $field = field::ensure_field_exists_for_context_level($field, $context, $category);
        $owner_options = array('required' => 0, 'edit_capability' => '', 'view_capability' => '', 'control' => 'checkbox', 'columns' => 30, 'rows' => 10, 'maxlength' => 2048, 'help_file' => 'crlm_cluster_groups/cluster_groupings');
        field_owner::ensure_field_owner_exists($field, 'manual', $owner_options);
    }
    if ($result && $oldversion < 2010080604) {
        if ($field = new field(field::get_for_context_level_with_name('cluster', 'cluster_site_course_group'))) {
            $field->shortname = 'cluster_groupings';
            $field->update();
        }
    }
    return $result;
}
 function action_editfield()
 {
     global $CURMAN;
     $level = $this->required_param('level', PARAM_ACTION);
     $ctxlvl = context_level_base::get_custom_context_level($level, 'block_curr_admin');
     if (!$ctxlvl) {
         print_error('invalid_context_level', 'block_curr_admin');
     }
     $id = $this->optional_param('id', NULL, PARAM_INT);
     require_once CURMAN_DIRLOCATION . '/form/customfieldform.class.php';
     $tmppage = new customfieldpage(array('level' => $level, 'action' => 'editfield'), $this);
     $form = new customfieldform($tmppage->get_moodle_url(), $this);
     if ($form->is_cancelled()) {
         $tmppage = new customfieldpage(array('level' => $level));
         redirect($tmppage->get_url(), get_string('edit_cancelled', 'block_curr_admin'));
     } else {
         if ($data = $form->get_data()) {
             $field = new field($data);
             if ($id) {
                 $field->id = $id;
                 $field->update();
             } else {
                 $field->add();
                 // assume each field only belongs to one context level (for now)
                 $fieldcontext = new field_contextlevel();
                 $fieldcontext->fieldid = $field->id;
                 $fieldcontext->contextlevel = $ctxlvl;
                 $fieldcontext->add();
             }
             //don't use !empty here because we might be storing a 0 or similar value
             if ($data->defaultdata != '') {
                 // save the default value
                 $defaultdata = $data->defaultdata;
                 if ($field->multivalued) {
                     // parse as a CSV string
                     // until we can use str_getcsv from PHP 5.3...
                     $temp = fopen("php://memory", "rw");
                     fwrite($temp, $defaultdata);
                     rewind($temp);
                     $defaultdata = fgetcsv($temp);
                     fclose($temp);
                 }
                 field_data::set_for_context_and_field(NULL, $field, $defaultdata);
             } else {
                 if ($field->multivalued) {
                     field_data::set_for_context_and_field(NULL, $field, array());
                 } else {
                     field_data::set_for_context_and_field(NULL, $field, NULL);
                 }
             }
             $plugins = get_list_of_plugins('curriculum/plugins');
             foreach ($plugins as $plugin) {
                 if (is_readable(CURMAN_DIRLOCATION . '/plugins/' . $plugin . '/custom_fields.php')) {
                     include_once CURMAN_DIRLOCATION . '/plugins/' . $plugin . '/custom_fields.php';
                     if (function_exists("{$plugin}_field_save_form_data")) {
                         call_user_func("{$plugin}_field_save_form_data", $form, $field, $data);
                     }
                 }
             }
             $tmppage = new customfieldpage(array('level' => $level));
             redirect($tmppage->get_url(), get_string('field_saved', 'block_curr_admin', $field));
         } else {
             if (!empty($id)) {
                 if ($this->optional_param('from', NULL, PARAM_CLEAN) == 'moodle' && $level == 'user') {
                     $moodlefield = $CURMAN->db->get_record('user_info_field', 'id', $id);
                     if (!$moodlefield) {
                         print_error('invalidfieldid', 'block_curr_admin');
                     }
                     unset($moodlefield->id);
                     $data_array = (array) $moodlefield;
                     $data_array['datatype'] = 'text';
                     $data_array['manual_field_control'] = $moodlefield->datatype;
                     switch ($moodlefield->datatype) {
                         case field::checkbox:
                             $data_array['datatype'] = 'bool';
                             break;
                         case field::menu:
                             $data_array['datatype'] = 'char';
                             $data_array['manual_field_options'] = $moodlefield->param1;
                             break;
                         case field::textarea:
                             $data_array['manual_field_columns'] = $moodlefield->param1;
                             $data_array['manual_field_rows'] = $moodlefield->param2;
                             break;
                         case field::text:
                             if ($moodlefield->param3) {
                                 $data_array['manual_field_control'] = 'password';
                             }
                             $data_array['manual_field_columns'] = $moodlefield->param1;
                             $data_array['manual_field_maxlength'] = $moodlefield->param2;
                             break;
                     }
                 } else {
                     $data = new field($id);
                     $data_array = $data->to_array();
                     $defaultdata = field_data::get_for_context_and_field(NULL, $data);
                     if (!empty($defaultdata)) {
                         if ($data->multivalued) {
                             $values = array();
                             // extract the data
                             foreach ($defaultdata as $data) {
                                 $values[] = $data->data;
                             }
                             // represent as a CSV string
                             $fh = fopen("php://memory", "rw");
                             fputcsv($fh, $values);
                             rewind($fh);
                             $defaultdata = fgets($fh);
                             fclose($fh);
                         } else {
                             $defaultdata = current($defaultdata);
                             $defaultdata = $defaultdata->data;
                         }
                     }
                     $data_array['defaultdata'] = $defaultdata;
                     $plugins = get_list_of_plugins('curriculum/plugins');
                     foreach ($plugins as $plugin) {
                         if (is_readable(CURMAN_DIRLOCATION . '/plugins/' . $plugin . '/custom_fields.php')) {
                             include_once CURMAN_DIRLOCATION . '/plugins/' . $plugin . '/custom_fields.php';
                             if (function_exists("{$plugin}_field_get_form_data")) {
                                 $data_array += call_user_func("{$plugin}_field_get_form_data", $form, $data);
                             }
                         }
                     }
                 }
                 $form->set_data($data_array);
             }
             $form->display();
         }
     }
 }