⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 field.class.php

📁 很棒的在线教学系统
💻 PHP
字号:
<?php //$Id: field.class.php,v 1.10.2.3 2009/03/15 13:43:28 skodak Exp $class profile_field_menu extends profile_field_base {    var $options;    var $datakey;    /**     * Constructor method.     * Pulls out the options for the menu from the database and sets the     * the corresponding key for the data if it exists     */    function profile_field_menu($fieldid=0, $userid=0) {        //first call parent constructor        $this->profile_field_base($fieldid, $userid);        /// Param 1 for menu type is the options        $options = explode("\n", $this->field->param1);        $this->options = array();        if ($this->field->required){            $this->options[''] = get_string('choose').'...';        }        foreach($options as $key => $option) {            $this->options[$key] = format_string($option);//multilang formatting        }        /// Set the data key        if ($this->data !== NULL) {            $this->datakey = (int)array_search($this->data, $this->options);        }    }    /**     * Create the code snippet for this field instance     * Overwrites the base class method     * @param   object   moodleform instance     */    function edit_field_add(&$mform) {        $mform->addElement('select', $this->inputname, format_string($this->field->name), $this->options);    }    /**     * Set the default value for this field instance     * Overwrites the base class method     */    function edit_field_set_default(&$mform) {        if (FALSE !==array_search($this->field->defaultdata, $this->options)){            $defaultkey = (int)array_search($this->field->defaultdata, $this->options);        } else {            $defaultkey = '';        }        $mform->setDefault($this->inputname, $defaultkey);    }    /**     * The data from the form returns the key. This should be converted to the     * respective option string to be saved in database     * Overwrites base class accessor method     * @param   integer   the key returned from the select input in the form     */    function edit_save_data_preprocess($key) {        return isset($this->options[$key]) ? addslashes($this->options[$key]) : NULL;    }    /**     * When passing the user object to the form class for the edit profile page     * we should load the key for the saved data     * Overwrites the base class method     * @param   object   user object     */    function edit_load_user_data(&$user) {        $user->{$this->inputname} = $this->datakey;    }    /**     * HardFreeze the field if locked.     * @param   object   instance of the moodleform class     */    function edit_field_set_locked(&$mform) {        if (!$mform->elementExists($this->inputname)) {            return;        }        if ($this->is_locked() and !has_capability('moodle/user:update', get_context_instance(CONTEXT_SYSTEM))) {            $mform->hardFreeze($this->inputname);            $mform->setConstant($this->inputname, $this->datakey);        }    }}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -