/** * Create a new customuserfieldtable object. * * @param mixed $items array (or other iterable) of items to be displayed * in the table. Each element in the array should be an object, with * fields matching the names in {@var $columns} containing the data. * @param array $columns mapping of column IDs to column configuration. * The column configuration is an array with the following entries: * - header (optional): the plain-text name, used for the table header. * Can either be a string or an array (for headers that allow sorting on * multiple values, e.g. first-name/last-name). If it is an array, then * the key is an ID used for sorting (if applicable), and the value is * an array of similar form to the $columns array, but only the 'header' * and 'sortable' keys are used. (Defaults to empty.) * - display_function (optional): the function used to display the column * entry. This can either be the name of a method, or a PHP callback. * Takes two arguments: the column ID, and the item (from the $items * array). Returns a string (or something that can be cast to a string). * (Defaults to the get_item_display_default method, which just returns * htmlspecialchars($item->$column), where $column is the column ID.) * - decorator (optional): a function used to decorate the column entry * (e.g. add links, change the text style, etc). This is a PHP callback * that takes three arguments: the column contents (the return value from * display_function), the column ID, and the item. (Defaults to doing * nothing.) * - sortable (optional): whether the column can be used for sorting. Can * be either true, false, display_table::ASC (which indicates that * the table is sorted by this column in the ascending direction), or * display_table::DESC. This has no effect if the header entry is an * array. (Defaults to the return value of is_sortable_default, which * defaults to true unless overridden by a subclass.) * - wrapped (optional): whether the column data should be wrapped if it is * too long. (Defaults to the return value of is_column_wrapped_default, * which defaults to true unless overridden by a subclass.) * - align (optional): how the column data should be aligned (left, right, * center). (Defaults to the return value of get_column_align_default(), * which defaults to left unless overridden by a subclass.) * @param moodle_url $base_url base url to the page, for changing sort * order. Only needed if the table can be sorted. * @param string $sort_param the name of the URL parameter to add to * $pageurl to specify the column to sort by. * @param string $sortdir_param the name of the URL parameter to add to * $pageurl to specify the direction of the sort. * @param array $attributes associative array of table attributes like: * 'id' => 'tableid', 'width' => '90%', 'cellpadding', 'cellspacing' ... */ public function __construct($items, $columns, moodle_url $base_url = null, $sort_param = 'sort', $sortdir_param = 'dir', array $attributes = array()) { parent::__construct($items, $columns, $base_url, $sort_param, $sortdir_param, $attributes); if (is_readable(elis::plugin_file("elisfields_moodleprofile", 'custom_fields.php'))) { include_once elis::plugin_file("elisfields_moodleprofile", 'custom_fields.php'); if (function_exists('moodle_profile_can_sync')) { $this->cansyncfcn = 'moodle_profile_can_sync'; } } }
function action_default() { global $CFG, $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'); } $tmppage = new customfieldpage(); $tabs = array(); require "{$CFG->dirroot}/blocks/curr_admin/db/access.php"; foreach ($block_curr_admin_contextlevels as $contextlevel => $val) { $tmppage->params['level'] = $contextlevel; $tabs[] = new tabobject($contextlevel, $tmppage->get_url(), get_string($contextlevel, 'block_curr_admin')); } print_tabs(array($tabs), $level); $fields = field::get_for_context_level($ctxlvl); $fields = $fields ? $fields : array(); $categories = field_category::get_for_context_level($ctxlvl); $categories = $categories ? $categories : array(); // divide the fields into categories $fieldsbycategory = array(); foreach ($categories as $category) { $fieldsbycategory[$category->id] = array(); } foreach ($fields as $field) { $fieldsbycategory[$field->categoryid][] = $field; } $deletetxt = get_string('delete'); $edittxt = get_string('edit'); $syncerr = false; if (empty($categories)) { print_heading(get_string('field_no_categories_defined', 'block_curr_admin')); } foreach ($fieldsbycategory as $categoryid => $fields) { $tmppage = new customfieldpage(); $tmppage->params = array('action' => 'deletecategory', 'id' => $categoryid, 'level' => $level); $deletelink = $tmppage->get_url(); $tmppage->params['action'] = 'editcategory'; $editlink = $tmppage->get_url(); echo "<h2>{$categories[$categoryid]->name} <a href=\"{$editlink}\">"; echo "<img src=\"{$CFG->wwwroot}/curriculum/pix/edit.gif\" alt=\"{$edittxt}\" title=\"{$edittxt}\" /></a>"; echo "<a href=\"{$deletelink}\"><img src=\"{$CFG->wwwroot}/curriculum/pix/delete.gif\" alt=\"{$deletetxt}\" title=\"{$deletetxt}\" /></a>"; echo "</h2>\n"; if (empty($fields)) { print_string('field_no_fields_defined', 'block_curr_admin'); } else { if ($level == 'user') { require_once CURMAN_DIRLOCATION . '/plugins/moodle_profile/custom_fields.php'; $table = new customuserfieldtable($fields, array('name' => get_string('name'), 'datatype' => get_string('field_datatype', 'block_curr_admin'), 'syncwithmoodle' => get_string('field_syncwithmoodle', 'block_curr_admin'), 'buttons' => ''), $this->get_moodle_url(array('level' => $level))); } else { $table = new customfieldtable($fields, array('name' => get_string('name'), 'datatype' => 'Data type', 'buttons' => ''), $this->get_moodle_url(array('level' => $level))); } $table->print_table(); $syncerr = $syncerr || !empty($table->syncerr); } } if ($syncerr) { print_string('moodle_field_sync_warning', 'block_curr_admin'); } // button for new category $options = array('s' => 'field', 'action' => 'editcategory', 'level' => $level); print_single_button('index.php', $options, get_string('field_create_category', 'block_curr_admin')); if (!empty($categories)) { if ($level == 'user') { // create new field from Moodle field $select = "shortname NOT IN (SELECT shortname FROM {$CURMAN->db->prefix_table(FIELDTABLE)})"; $moodlefields = $CURMAN->db->get_records_select('user_info_field', $select, 'sortorder', 'id,name'); $moodlefields = $moodlefields ? $moodlefields : array(); $tmppage->params['action'] = 'editfield'; $tmppage->params['from'] = 'moodle'; $tmppage->params['level'] = 'user'; echo '<div>'; popup_form("{$tmppage->get_url()}&id=", array_map(create_function('$x', 'return $x->name;'), $moodlefields), 'frommoodleform', '', 'choose', '', '', false, 'self', get_string('field_from_moodle', 'block_curr_admin')); echo '</div>'; $options = array('s' => 'field', 'action' => 'forceresync'); print_single_button('index.php', $options, get_string('field_force_resync', 'block_curr_admin')); } else { // create new field from scratch $options = array('s' => 'field', 'action' => 'editfield', 'level' => $level); print_single_button('index.php', $options, get_string('field_create_new', 'block_curr_admin')); } } }