[moodle] / moodle / lib / adminlib.php Repository:

Diff of /moodle/lib/adminlib.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.153.2.57, Fri Dec 12 19:45:48 2008 WST revision 1.153.2.58, Thu Jan 8 16:05:31 2009 WST

By tjhunt:

course requests: MDL-6160 clean up admin option for choosing who is notified.

# Line 2417  Line 2417 
2417          }          }
2418    
2419          $defaults = array();          $defaults = array();
2420            $size = min(10, count($this->choices));
2421          $return = '<div class="form-select"><input type="hidden" name="'.$this->get_full_name().'[xxxxx]" value="1" />'; // something must be submitted even if nothing selected          $return = '<div class="form-select"><input type="hidden" name="'.$this->get_full_name().'[xxxxx]" value="1" />'; // something must be submitted even if nothing selected
2422          $return .= '<select id="'.$this->get_id().'" name="'.$this->get_full_name().'[]" size="10" multiple="multiple">';          $return .= '<select id="'.$this->get_id().'" name="'.$this->get_full_name().'[]" size="'.$size.'" multiple="multiple">';
2423          foreach ($this->choices as $key => $description) {          foreach ($this->choices as $key => $description) {
2424              if (in_array($key, $data)) {              if (in_array($key, $data)) {
2425                  $selected = 'selected="selected"';                  $selected = 'selected="selected"';
# Line 2510  Line 2511 
2511  }  }
2512    
2513  /**  /**
2514     * An admin setting for selecting one or more users, who have a particular capability
2515     * in the system context. Warning, make sure the list will never be too long. There is
2516     * no paging or searching of this list.
2517     *
2518     * To correctly get a list of users from this config setting, you need to call the
2519     * get_users_from_config($CFG->mysetting, $capability); function in moodlelib.php.
2520     */
2521    class admin_setting_users_with_capability extends admin_setting_configmultiselect {
2522        protected $capability;
2523    
2524        /**
2525         * Constructor.
2526         *
2527         * @param string $name unique ascii name, either 'mysetting' for settings that in config, or 'myplugin/mysetting' for ones in config_plugins.
2528         * @param string $visiblename localised name
2529         * @param string $description localised long description
2530         * @param array $defaultsetting array of usernames
2531         * @param string $capability string capability name.
2532         */
2533        function __construct($name, $visiblename, $description, $defaultsetting, $capability) {
2534            $users = get_users_by_capability(get_context_instance(CONTEXT_SYSTEM),
2535                    $capability, 'username,firstname,lastname', 'lastname,firstname');
2536            $choices = array(
2537                '$@NONE@$' => get_string('nobody'),
2538                '$@ALL@$' => get_string('everyonewhocan', 'admin', get_capability_string($capability)),
2539            );
2540            foreach ($users as $user) {
2541                $choices[$user->username] = fullname($user);
2542            }
2543            parent::admin_setting_configmultiselect($name, $visiblename, $description, $defaultsetting, $choices);
2544        }
2545    
2546        function get_defaultsetting() {
2547            $this->load_choices();
2548            if (empty($this->defaultsetting)) {
2549                return array('$@NONE@$');
2550            } else if (array_key_exists($this->defaultsetting, $this->choices)) {
2551                return $this->defaultsetting;
2552            } else {
2553                return '';
2554            }
2555        }
2556    
2557        function get_setting() {
2558            $result = parent::get_setting();
2559            if (empty($result)) {
2560                $result = array('$@NONE@$');
2561            }
2562            return $result;
2563        }
2564    
2565        function write_setting($data) {
2566            // If all is selected, remove any explicit options.
2567            if (in_array('$@ALL@$', $data)) {
2568                $data = array('$@ALL@$');
2569            }
2570            // None never needs to be writted to the DB.
2571            if (in_array('$@NONE@$', $data)) {
2572                unset($data[array_search('$@NONE@$', $data)]);
2573            }
2574            return parent::write_setting($data);
2575        }
2576    }
2577    
2578    /**
2579   * Special checkbox for calendar - resets SESSION vars.   * Special checkbox for calendar - resets SESSION vars.
2580   */   */
2581  class admin_setting_special_adminseesall extends admin_setting_configcheckbox {  class admin_setting_special_adminseesall extends admin_setting_configcheckbox {

Legend:
Removed from v.1.153.2.57  
changed lines
  Added in v.1.153.2.58

Moodle CVS Admin
ViewVC Help
Powered by ViewVC 1.0.7