本文整理汇总了PHP中field::get_for_context_level方法的典型用法代码示例。如果您正苦于以下问题:PHP field::get_for_context_level方法的具体用法?PHP field::get_for_context_level怎么用?PHP field::get_for_context_level使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类field
的用法示例。
在下文中一共展示了field::get_for_context_level方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set_from_data
public function set_from_data($data)
{
$fields = field::get_for_context_level(CONTEXT_ELIS_PROGRAM);
$fields = $fields ? $fields : array();
foreach ($fields as $field) {
$fieldname = "field_{$field->shortname}";
if (isset($data->{$fieldname})) {
$this->{$fieldname} = $data->{$fieldname};
}
}
$this->_load_data_from_record($data, true);
}
示例2: add_custom_fields
/**
* Adds custom field data to a CM entity based on the data defined for
* a particular class request (in-place)
*
* @param object $formdata the submitted form data
* @param string $contextlevel_name Name of the context level we are adding fields for,
* such as 'course' or 'class'
* @param object $entity The CM entity to update with custom field data
*/
function add_custom_fields($formdata, $contextlevel_name, &$entity)
{
global $CFG;
require_once $CFG->dirroot . '/local/elisprogram/lib/contexts.php';
$contextlevel = \local_eliscore\context\helper::get_level_from_name($contextlevel_name);
if ($fields = field::get_for_context_level($contextlevel)) {
foreach ($fields as $field) {
$key = "field_{$field->shortname}";
if (isset($formdata->{$key})) {
$entity->{$key} = $formdata->{$key};
}
}
}
}
示例3: generalized_filter_elisuserprofile
/**
* Constructor
*
* @param string $uniqueid Unique id for filter
* @param string $label Filter label
* @param array $options Filter options (see above)
* @return array of sub-filters
*/
function generalized_filter_elisuserprofile($uniqueid, $label, $options = array())
{
parent::multifilter($uniqueid, $label, $options);
foreach ($this->tables as $key => $val) {
foreach ($val as $table => $alias) {
if (empty($options['tables'][$key][$table])) {
//use defaults table aliases since not specified
$options['tables'][$key][$table] = $alias;
}
}
}
//default help setup
if (empty($options['help'])) {
$options['help'] = array();
}
// Get the custom fields that belong to the user context
$ctxlvl = context_level_base::get_custom_context_level('user', 'block_curr_admin');
$fields = field::get_for_context_level($ctxlvl);
$fields = $fields ? $fields : array();
$this->get_custom_fields('up', $fields);
//create field listing, including display names
$allfields = array();
foreach ($options['choices'] as $choice) {
$choicestring = $choice;
if (array_key_exists($choice, $this->labels['up'])) {
$choicestring = get_string($this->labels['up'][$choice], $this->languagefile);
}
if (0 == strcmp($choice, 'customfields')) {
foreach ($fields as $field) {
$allfields['customfield-' . $field->id] = $field->name;
}
} else {
$allfields[$choice] = $choicestring;
}
}
//add all fields
foreach ($allfields as $userfield => $fieldlabel) {
//calculate any necessary custom options
$myoptions = $this->make_filter_options('up', $userfield, $options['help'], $options['tables']);
//determine field type from mapping
$ftype = (string) $this->fieldtofiltermap['up'][$userfield];
$advanced = !empty($options['advanced']) && in_array($userfield, $options['advanced']) || !empty($options['notadvanced']) && !in_array($userfield, $options['notadvanced']);
//create the sub-filter object
$this->_filters['up'][$userfield] = new generalized_filter_entry($userfield, $myoptions['talias'], $myoptions['dbfield'], $fieldlabel, $advanced, $ftype, $myoptions);
}
}
示例4: definition
/**
* items in the form
*/
public function definition()
{
global $CURMAN, $CFG;
parent::definition();
$mform =& $this->_form;
$mform->addElement('hidden', 'id');
$mform->addElement('text', 'name', get_string('cluster_name', 'block_curr_admin') . ':');
$mform->addRule('name', get_string('required'), 'required', NULL, 'client');
$mform->setHelpButton('name', array('clusterform/name', get_string('cluster_name', 'block_curr_admin'), 'block_curr_admin'));
$mform->addElement('textarea', 'display', get_string('cluster_description', 'block_curr_admin') . ':', array('cols' => 40, 'rows' => 2));
$mform->setHelpButton('display', array('clusterform/display', get_string('cluster_description', 'block_curr_admin'), 'block_curr_admin'));
$current_cluster_id = isset($this->_customdata['obj']->id) ? $this->_customdata['obj']->id : '';
//obtain the non-child clusters that we could become the child of, with availability
//determined based on the edit capability
$contexts = clusterpage::get_contexts('block/curr_admin:cluster:edit');
$non_child_clusters = cluster_get_non_child_clusters($current_cluster_id, $contexts);
//parent dropdown
$mform->addElement('select', 'parent', get_string('cluster_parent', 'block_curr_admin') . ':', $non_child_clusters);
$mform->setHelpButton('parent', array('clusterform/parent', get_string('cluster_parent', 'block_curr_admin'), 'block_curr_admin'));
// allow plugins to add their own fields
$plugins = get_list_of_plugins('curriculum/cluster');
$mform->addElement('header', 'userassociationfieldset', get_string('userassociation', 'block_curr_admin'));
foreach ($plugins as $plugin) {
require_once CURMAN_DIRLOCATION . '/cluster/' . $plugin . '/lib.php';
call_user_func('cluster_' . $plugin . '_edit_form', $this);
}
// custom fields
$fields = field::get_for_context_level('cluster');
$fields = $fields ? $fields : array();
$lastcat = null;
$context = isset($this->_customdata['obj']) && isset($this->_customdata['obj']->id) ? get_context_instance(context_level_base::get_custom_context_level('cluster', 'block_curr_admin'), $this->_customdata['obj']->id) : get_context_instance(CONTEXT_SYSTEM);
require_once CURMAN_DIRLOCATION . '/plugins/manual/custom_fields.php';
foreach ($fields as $rec) {
$field = new field($rec);
if (!isset($field->owners['manual'])) {
continue;
}
if ($lastcat != $rec->categoryid) {
$lastcat = $rec->categoryid;
$mform->addElement('header', "category_{$lastcat}", htmlspecialchars($rec->categoryname));
}
manual_field_add_form_element($this, $context, $field);
}
$this->add_action_buttons();
}
示例5: test_syncpmuserfieldtodeletedmoodleprofilefield
/**
* Test sync-ing an ELIS User Profile field to a DELETED Moodle User Profile field
*/
public function test_syncpmuserfieldtodeletedmoodleprofilefield()
{
global $CFG, $DB;
require_once $CFG->dirroot . '/user/profile/definelib.php';
$this->load_csv_data();
// Set PM Custom User field(s) to Sync to Moodle.
$ctxlvl = CONTEXT_ELIS_USER;
$fields = field::get_for_context_level($ctxlvl);
foreach ($fields as $field) {
$fieldobj = new field($field);
if (!isset($fieldobj->owners['moodle_profile'])) {
$fieldobj->owners['moodle_profile'] = new stdClass();
}
$owner = new field_owner($fieldobj->owners['moodle_profile']);
$owner->exclude = pm_moodle_profile::sync_from_moodle;
$owner->save();
$fieldobj->save();
}
// Read a record.
$src = new user(103, null, array(), false, array());
$src->reset_custom_field_list();
// Modify the data.
$src->firstname = 'Testuser';
$src->lastname = 'One';
$src->field_sometext = 'boo';
$src->field_sometextfrompm = 'bla';
$src->save();
// Delete some custom Moodle Profile field(s) to cause old error (pre ELIS-4499).
$fields = field::get_for_context_level($ctxlvl);
foreach ($fields as $field) {
$fieldobj = new field($field);
if ($moodlefield = $DB->get_record('user_info_field', array('shortname' => $fieldobj->shortname))) {
profile_delete_field($moodlefield->id);
}
}
// Run the library sync - throws errors not exceptions :(.
$CFG->mnet_localhost_id = 1;
// ???
$mu = cm_get_moodleuser(103);
try {
$result = pm_moodle_user_to_pm($mu);
$this->assertTrue($result);
} catch (Exception $ex) {
$this->assertTrue(false, $ex->message);
}
}
示例6: set_from_data
public function set_from_data($data)
{
if (isset($data->curriculum)) {
$this->curriculum = $data->curriculum;
}
if (isset($data->location)) {
$this->location = $data->location;
$this->templateclass = $data->templateclass;
}
$fields = field::get_for_context_level('course', 'block_curr_admin');
$fields = $fields ? $fields : array();
foreach ($fields as $field) {
$fieldname = "field_{$field->shortname}";
if (isset($data->{$fieldname})) {
$this->{$fieldname} = $data->{$fieldname};
}
}
return parent::set_from_data($data);
}
示例7: definition
/**
* items in the form
*
* @uses $USER
*/
public function definition()
{
global $USER;
$this->set_data($this->_customdata['obj']);
$mform =& $this->_form;
$mform->addElement('hidden', 'id');
$curs = array();
if (!empty($USER->id)) {
// TBD: and/or capability 'block/curr_admin:curriculum:edit|view' ?
// WAS: 'block/curr_admin:track:create' ???
$contexts = get_contexts_by_capability_for_user('curriculum', 'block/curr_admin:curriculum:view', $USER->id);
$curs = curriculum_get_listing('name', 'ASC', 0, 0, '', '', $contexts);
}
if (empty($this->_customdata['obj']->id)) {
$curid_options = array();
if (!empty($curs)) {
foreach ($curs as $cur) {
$curid_options[$cur->id] = '(' . $cur->idnumber . ') ' . $cur->name;
}
}
$mform->addElement('select', 'curid', get_string('curriculum', 'block_curr_admin') . ':', $curid_options);
$mform->addRule('curid', get_string('required'), 'required', NULL, 'client');
$mform->setHelpButton('curid', array('trackform/curriculum', get_string('curriculum', 'block_curr_admin'), 'block_curr_admin'));
} else {
// Track editing, do not allow the user to change curriculum
$mform->addElement('static', 'curidstatic', get_string('curriculum', 'block_curr_admin') . ':', $curs[$this->_customdata['obj']->curid]->name);
$mform->setHelpButton('curidstatic', array('trackform/curriculum', get_string('curriculum', 'block_curr_admin'), 'block_curr_admin'));
$mform->addElement('hidden', 'curid');
}
$mform->addElement('text', 'idnumber', get_string('track_idnumber', 'block_curr_admin') . ':');
$mform->setType('idnumber', PARAM_TEXT);
$mform->addRule('idnumber', get_string('required'), 'required', NULL, 'client');
$mform->addRule('idnumber', null, 'maxlength', 100);
$mform->setHelpButton('idnumber', array('trackform/idnumber', get_string('track_idnumber', 'block_curr_admin'), 'block_curr_admin'));
$mform->addElement('text', 'name', get_string('track_name', 'block_curr_admin') . ':');
$mform->setType('name', PARAM_TEXT);
$mform->addRule('name', null, 'maxlength', 255);
$mform->addRule('name', get_string('required'), 'required', NULL, 'client');
$mform->setHelpButton('name', array('trackform/name', get_string('track_name', 'block_curr_admin'), 'block_curr_admin'));
$mform->addElement('textarea', 'description', get_string('track_description', 'block_curr_admin') . ':');
$mform->setType('description', PARAM_CLEAN);
$mform->setHelpButton('description', array('trackform/description', get_string('track_description', 'block_curr_admin'), 'block_curr_admin'));
$mform->addElement('date_selector', 'startdate', get_string('track_startdate', 'block_curr_admin') . ':', array('optional' => true));
$mform->addElement('date_selector', 'enddate', get_string('track_enddate', 'block_curr_admin') . ':', array('optional' => true));
$mform->setHelpButton('startdate', array('trackform/startdate', get_string('startdate', 'block_curr_admin'), 'block_curr_admin'));
if (!empty($this->_customdata['obj']->id)) {
$trackassignobj = new trackassignmentclass(array('trackid' => $this->_customdata['obj']->id));
}
// Only show auto-create checkbox if the track does not have any classes assigned
if (!isset($trackassignobj) or 0 == $trackassignobj->count_assigned_classes_from_track()) {
$mform->addElement('checkbox', 'autocreate', get_string('track_autocreate', 'block_curr_admin') . ':');
$mform->setHelpButton('autocreate', array('trackform/autocreate', get_string('track_autocreate', 'block_curr_admin'), 'block_curr_admin'));
}
// custom fields
$fields = field::get_for_context_level('track');
$fields = $fields ? $fields : array();
$lastcat = null;
$context = isset($this->_customdata['obj']) && isset($this->_customdata['obj']->id) ? get_context_instance(context_level_base::get_custom_context_level('track', 'block_curr_admin'), $this->_customdata['obj']->id) : get_context_instance(CONTEXT_SYSTEM);
require_once CURMAN_DIRLOCATION . '/plugins/manual/custom_fields.php';
foreach ($fields as $rec) {
$field = new field($rec);
if (!isset($field->owners['manual'])) {
continue;
}
if ($lastcat != $rec->categoryid) {
$lastcat = $rec->categoryid;
$mform->addElement('header', "category_{$lastcat}", htmlspecialchars($rec->categoryname));
}
manual_field_add_form_element($this, $context, $field);
}
$this->add_action_buttons();
}
示例8: get_columns
/**
* Method that specifies the report's columns
* (specifies various fields involving user info, clusters, class enrolment, and module information)
*
* @return table_report_column array The list of report columns
*/
function get_columns()
{
global $CURMAN, $SESSION, $CFG;
$columns = array();
$columns[] = new table_report_column('crs.name', get_string('column_course', $this->lang_file), 'csscourse', 'left', true);
$columns[] = new table_report_column('cls.idnumber', get_string('column_class_id', $this->lang_file), 'cssclass', 'left', true);
$filter_params = php_report_filtering_get_active_filter_values($this->get_report_shortname(), 'field' . $this->get_report_shortname());
// Unserialize value of filter params to get field ids array
$filter_params = @unserialize(base64_decode($filter_params[0]['value']));
// Loop through these additional parameters - new columns, will have to eventually pass the table etc...
if (isset($filter_params) && is_array($filter_params)) {
// Working with custom course fields - get all course fields
$context = context_level_base::get_custom_context_level('course', 'block_curr_admin');
$fields = field::get_for_context_level($context);
foreach ($filter_params as $custom_course_id) {
$custom_course_field = new field($custom_course_id);
// Obtain custom field default values IFF set
if (($default_value = $custom_course_field->get_default()) !== false) {
// save in array { record_field => default_value }
$this->field_default['custom_data_' . $custom_course_id] = $default_value;
}
//Find matching course field
$course_field_title = $fields[$custom_course_id]->name;
//Now, create a join statement for each custom course field and add it to the sql query
$data_table = $CURMAN->db->prefix_table($custom_course_field->data_table());
//field used to identify course id in custom field subquery
$course_id_field = "ctxt_instanceid_{$custom_course_id}";
//make sure the user can view fields for the current course
$view_field_capability = block_php_report_field_capability($custom_course_field->owners);
$view_field_contexts = get_contexts_by_capability_for_user('course', $view_field_capability, $this->userid);
$view_field_filter = $view_field_contexts->sql_filter_for_context_level('ctxt.instanceid', 'course');
// Create a custom join to be used later for the completed sql query
$this->custom_joins[] = " LEFT JOIN (SELECT d.data as custom_data_{$custom_course_id}, ctxt.instanceid as ctxt_instanceid_{$custom_course_id}\n FROM {$CURMAN->db->prefix_table('context')} ctxt\n JOIN {$data_table} d ON d.contextid = ctxt.id\n AND d.fieldid = {$custom_course_id}\n WHERE\n ctxt.contextlevel = {$context}\n AND {$view_field_filter}) custom_{$custom_course_id}\n ON cls.courseid = custom_{$custom_course_id}.{$course_id_field}";
$columns[] = new table_report_column('custom_' . $custom_course_id . '.custom_data_' . $custom_course_id, $fields[$custom_course_id]->name, 'csscustom_course_field', 'left', true);
}
}
// completion elements completed/total
$columns[] = new table_report_horizontal_bar_column("(SELECT COUNT(*)\n FROM {$CURMAN->db->prefix_table(CRSCOMPTABLE)} comp\n JOIN {$CURMAN->db->prefix_table(CLSTABLE)} cls2\n ON cls2.courseid = comp.courseid\n JOIN {$CURMAN->db->prefix_table(STUTABLE)} stu\n ON stu.classid = cls2.id\n JOIN {$CURMAN->db->prefix_table(GRDTABLE)} clsgr\n ON clsgr.classid = cls2.id\n AND clsgr.userid = stu.userid\n AND clsgr.locked = 1\n AND clsgr.grade >= comp.completion_grade\n AND clsgr.completionid = comp.id\n WHERE cls2.id = cls.id\n AND stu.userid = crlmuser.id\n ) AS stucompletedprogress", get_string('bar_column_progress', $this->lang_file), 'progress_bar', "(SELECT COUNT(*)\n FROM {$CURMAN->db->prefix_table(CRSCOMPTABLE)} comp\n JOIN {$CURMAN->db->prefix_table(CLSTABLE)} cls2\n ON cls2.courseid = comp.courseid\n WHERE cls2.id = cls.id\n ) AS numprogress", 'center', '$p');
$columns[] = new table_report_column('0 AS completedprogress', get_string('column_progress', $this->lang_file), 'cssprogress', 'center', true);
$columns[] = new table_report_column('cls.startdate', get_string('column_start_date', $this->lang_file), 'cssstart_date', 'center', true);
$columns[] = new table_report_column('cls.enddate', get_string('column_end_date', $this->lang_file), 'cssend_date', 'center', true);
$columns[] = new table_report_column('pretest.score AS pretestscore', get_string('column_pretest_score', $this->lang_file), 'csspretest_score', 'center', true);
$columns[] = new table_report_column('posttest.score AS posttestscore', get_string('column_posttest_score', $this->lang_file), 'cssposttest_score', 'center', true);
// discussion posts
$columns[] = new table_report_column("(SELECT COUNT(*)\n FROM {$CFG->prefix}forum_discussions disc\n JOIN {$CFG->prefix}forum_posts post\n ON post.discussion = disc.id\n WHERE disc.course = clsmdl.moodlecourseid\n AND post.userid = user.id\n ) AS numposts", get_string('column_discussion_posts', $this->lang_file), 'cssdiscussion_posts', 'center', true);
// resources accessed
$columns[] = new table_report_column("(SELECT COUNT(*)\n FROM {$CFG->prefix}log log\n JOIN {$CFG->prefix}resource rsc\n ON rsc.id = log.info\n WHERE log.module = 'resource'\n AND log.action = 'view'\n AND log.userid = user.id\n AND log.course = clsmdl.moodlecourseid\n ) AS numresources", get_string('column_resources_accessed', $this->lang_file), 'cssresources_accessed', 'center', true);
return $columns;
}
示例9: cm_user_filtering
/**
* Contructor
* @param array array of visible user fields
* @param string base url used for submission/return, null if the same of current page
* @param array extra page parameters
*/
function cm_user_filtering($fieldnames = null, $baseurl = null, $extraparams = null)
{
if (empty($fieldnames)) {
$fieldnames = array('realname' => 0, 'lastname' => 1, 'firstname' => 1, 'idnumber' => 1, 'email' => 0, 'city' => 1, 'country' => 1, 'username' => 0, 'language' => 1, 'clusterid' => 1, 'curriculumid' => 1, 'inactive' => 1);
$fields = field::get_for_context_level(context_level_base::get_custom_context_level('user', 'block_curr_admin'));
$fields = $fields ? $fields : array();
foreach ($fields as $field) {
$fieldnames["field_{$field->shortname}"] = 1;
}
}
/// Remove filters if missing capability...
$context = get_context_instance(CONTEXT_SYSTEM);
if (!has_capability('block/curr_admin:viewreports', $context)) {
if (has_capability('block/curr_admin:viewgroupreports', $context)) {
unset($fieldnames['clusterid']);
}
}
parent::user_filtering($fieldnames, $baseurl, $extraparams);
}
示例10: set_from_data
public function set_from_data($data)
{
$this->autocreate = !empty($data->autocreate) ? $data->autocreate : 0;
$fields = field::get_for_context_level('track', 'block_curr_admin');
$fields = $fields ? $fields : array();
foreach ($fields as $field) {
$fieldname = "field_{$field->shortname}";
if (isset($data->{$fieldname})) {
$this->{$fieldname} = $data->{$fieldname};
}
}
parent::set_from_data($data);
}
示例11: get_columns
/**
* Method that specifies the report's columns
* (specifies various fields involving user info, clusters, class enrolment, and module information)
*
* @uses $DB
* @return table_report_column array The list of report columns
*/
function get_columns()
{
global $DB;
$columns = array();
$columns[] = new table_report_column('crs.name', get_string('column_course', $this->lang_file), 'csscourse', 'left', true);
$columns[] = new table_report_column('cls.idnumber', get_string('column_class_id', $this->lang_file), 'cssclass', 'left', true);
$filter_params = php_report_filtering_get_active_filter_values($this->get_report_shortname(), 'field' . $this->get_report_shortname(), $this->filter);
$filter_params = $filter_params[0]['value'];
$filter_params = $filter_params ? explode(',', $filter_params) : array();
// Loop through these additional parameters - new columns, will have to eventually pass the table etc...
if (isset($filter_params) && is_array($filter_params)) {
// Working with custom course fields - get all course fields
$fields = field::get_for_context_level(CONTEXT_ELIS_COURSE)->to_array();
foreach ($filter_params as $custom_course_id) {
$custom_course_field = new field($custom_course_id);
// Obtain custom field default values IFF set
if (($default_value = $custom_course_field->get_default()) !== false) {
// save in array { record_field => default_value }
$this->field_default['custom_data_' . $custom_course_id] = $default_value;
}
//Find matching course field
$course_field_title = $fields[$custom_course_id]->name;
//Now, create a join statement for each custom course field and add it to the sql query
$data_table = $custom_course_field->data_table();
//field used to identify course id in custom field subquery
$course_id_field = "ctxt_instanceid_{$custom_course_id}";
//make sure the user can view fields for the current course
$view_field_capability = generalized_filter_custom_field_multiselect_values::field_capability($custom_course_field->owners);
$view_field_contexts = get_contexts_by_capability_for_user('course', $view_field_capability, $this->userid);
//$view_field_filter = $view_field_contexts->sql_filter_for_context_level('ctxt.instanceid', 'course');
$filter_obj = $view_field_contexts->get_filter('instanceid', 'course');
$filter_sql = $filter_obj->get_sql(false, 'ctxt', SQL_PARAMS_NAMED);
$view_field_filter = 'TRUE';
$params = array();
if (isset($filter_sql['where'])) {
$view_field_filter = $filter_sql['where'];
$params = $filter_sql['where_parameters'];
}
// Create a custom join to be used later for the completed sql query
$this->custom_joins[] = array("\n LEFT JOIN (SELECT d.data as custom_data_{$custom_course_id}, ctxt.instanceid as ctxt_instanceid_{$custom_course_id}\n FROM {context} ctxt\n JOIN {" . $data_table . "} d\n ON d.contextid = ctxt.id AND d.fieldid = {$custom_course_id}\n WHERE ctxt.contextlevel = " . CONTEXT_ELIS_COURSE . "\n AND {$view_field_filter}) custom_{$custom_course_id}\n ON cls.courseid = custom_{$custom_course_id}.{$course_id_field}", $params);
$columns[] = new table_report_column('custom_' . $custom_course_id . '.custom_data_' . $custom_course_id, $fields[$custom_course_id]->name, 'csscustom_course_field', 'left', true);
}
}
// completion elements completed/total
$columns[] = new table_report_horizontal_bar_column('(SELECT COUNT(*) FROM {' . coursecompletion::TABLE . '} comp
JOIN {' . pmclass::TABLE . '} cls2
ON cls2.courseid = comp.courseid
JOIN {' . student::TABLE . '} stu
ON stu.classid = cls2.id
JOIN {' . student_grade::TABLE . '} clsgr
ON clsgr.classid = cls2.id
AND clsgr.userid = stu.userid
AND clsgr.locked = 1
AND clsgr.grade >= comp.completion_grade
AND clsgr.completionid = comp.id
WHERE cls2.id = cls.id
AND stu.userid = crlmuser.id
) AS stucompletedprogress', get_string('bar_column_progress', $this->lang_file), 'progress_bar', '(SELECT COUNT(*) FROM {' . coursecompletion::TABLE . '} comp
JOIN {' . pmclass::TABLE . '} cls2
ON cls2.courseid = comp.courseid
WHERE cls2.id = cls.id
) AS numprogress', 'center', '$p');
$columns[] = new table_report_column('0 AS completedprogress', get_string('column_progress', $this->lang_file), 'cssprogress', 'center', true);
$columns[] = new table_report_column('cls.startdate', get_string('column_start_date', $this->lang_file), 'cssstart_date', 'center', true);
$columns[] = new table_report_column('cls.enddate', get_string('column_end_date', $this->lang_file), 'cssend_date', 'center', true);
$optional_columns_ppt = php_report_filtering_get_active_filter_values($this->get_report_shortname(), 'optional_columns_preposttest', $this->filter);
$optional_columns_los = php_report_filtering_get_active_filter_values($this->get_report_shortname(), 'optional_columns_los', $this->filter);
$optional_columns_totscore = php_report_filtering_get_active_filter_values($this->get_report_shortname(), 'optional_columns_totalscore', $this->filter);
$this->preposttest_columns = false;
$this->los_columns = false;
$this->totalscore_column = false;
if (!empty($optional_columns_ppt) && !empty($optional_columns_ppt['0']['value'])) {
$columns[] = new table_report_column('pretest.score AS pretestscore', get_string('column_pretest_score', $this->lang_file), 'csspretest_score', 'center', true);
$columns[] = new table_report_column('posttest.score AS posttestscore', get_string('column_posttest_score', $this->lang_file), 'cssposttest_score', 'center', true);
$this->preposttest_columns = true;
}
if (!empty($optional_columns_los) && !empty($optional_columns_los['0']['value'])) {
$max_los_sql = 'SELECT courseid, COUNT(\'x\') AS count FROM {' . coursecompletion::TABLE . '} GROUP BY courseid ORDER BY count DESC';
$max_los = $DB->get_records_sql($max_los_sql, null, 0, 1);
$max_los = empty($max_los) ? 0 : current($max_los)->count;
for ($i = 1; $i <= $max_los; ++$i) {
$columns[] = new table_report_column("'" . addslashes(get_string('na', $this->lang_file)) . "' AS lo{$i}", get_string('column_los_prefix', $this->lang_file) . "{$i}", 'csslos_columns', 'center', false);
}
$this->los_columns = true;
}
if (!empty($optional_columns_totscore) && !empty($optional_columns_totscore['0']['value'])) {
$columns[] = new table_report_column('enrol.grade AS elisgrade', get_string('column_totalscore', $this->lang_file), 'csstotal_score', 'center', true);
$this->totalscore_column = true;
}
// discussion posts
$columns[] = new table_report_column('(SELECT COUNT(*) FROM {forum_discussions} disc
JOIN {forum_posts} post
ON post.discussion = disc.id
//.........这里部分代码省略.........
示例12: get_columns
/**
* Method that specifies the report's columns
* (specifies various fields involving user info, clusters, class enrolment, and module information)
*
* @uses $DB
* @return table_report_column array The list of report columns
*/
function get_columns()
{
global $DB;
//add custom fields here, first the Course name, then custom fields, then progress and % students passing
$columns = array();
$columns[] = new table_report_column('crs.name', get_string('column_course', 'rlreport_course_progress_summary'), 'course', 'left', true);
$filter_params = php_report_filtering_get_active_filter_values($this->get_report_shortname(), 'field' . $this->get_report_shortname(), $this->filter);
$filter_params = $filter_params[0]['value'];
$filter_params = $filter_params ? explode(',', $filter_params) : array();
// Loop through these additional parameters - new columns, will have to eventually pass the table etc...
if (isset($filter_params) && is_array($filter_params)) {
// Working with custom course fields - get all course fields
$fields = field::get_for_context_level(CONTEXT_ELIS_COURSE)->to_array();
foreach ($filter_params as $custom_course_id) {
$custom_course_field = new field($custom_course_id);
// Obtain custom field default values IFF set
if (($default_value = $custom_course_field->get_default()) !== false) {
// save in array { record_field => default_value }
$this->field_default['custom_data_' . $custom_course_id] = $default_value;
}
//Find matching course field
$course_field_title = $fields[$custom_course_id]->name;
//Now, create a join statement for each custom course field and add it to the sql query
$data_table = $custom_course_field->data_table();
//field used to identify course id in custom field subquery
$course_id_field = "ctxt_instanceid_{$custom_course_id}";
//make sure the user can view fields for the current course
$view_field_capability = generalized_filter_custom_field_multiselect_values::field_capability($custom_course_field->owners);
$view_field_contexts = get_contexts_by_capability_for_user('course', $view_field_capability, $this->userid);
//$view_field_filter = $view_field_contexts->sql_filter_for_context_level('ctxt.instanceid', 'course');
$filter_obj = $view_field_contexts->get_filter('ctxt.instanceid', 'course');
$filter_sql = $filter_obj->get_sql(false, 'ctxt', SQL_PARAMS_NAMED);
$view_field_filter = 'TRUE';
$params = array();
if (isset($filter_sql['where'])) {
$view_field_filter = $filter_sql['where'];
$params = $filter_sql['where_parameters'];
}
// Create a custom join to be used later for the completed sql query
$this->custom_joins[] = array(" LEFT JOIN (SELECT d.data as custom_data_{$custom_course_id}, ctxt.instanceid as ctxt_instanceid_{$custom_course_id}\n FROM {context} ctxt\n JOIN {" . $data_table . "} d ON d.contextid = ctxt.id\n AND d.fieldid = {$custom_course_id}\n WHERE\n ctxt.contextlevel = " . CONTEXT_ELIS_COURSE . "\n AND {$view_field_filter}) custom_{$custom_course_id}\n ON cls.courseid = custom_{$custom_course_id}.{$course_id_field}", $params);
$columns[] = new table_report_column('custom_' . $custom_course_id . '.custom_data_' . $custom_course_id, $fields[$custom_course_id]->name, 'custom_course_field', 'left');
}
}
//add progress bar and students passing
$columns[] = new table_report_horizontal_bar_column('COUNT(DISTINCT clsgr.id) AS stucompletedprogress', get_string('bar_column_progress', 'rlreport_course_progress_summary'), 'progress_bar', 'COUNT(DISTINCT ' . $DB->sql_concat('comp.id', "'_'", 'enrol.id') . ') AS numprogress', 'center', '$e');
$columns[] = new table_report_column('SUM(CASE WHEN enrol.completestatusid = 2 THEN 1 ELSE 0 END) AS studentspassing', get_string('column_percent_passing', 'rlreport_course_progress_summary'), 'percent_passing', 'left');
return $columns;
}
示例13: set_for_context_from_datarecord
/**
* Convenience function for use by datarecord objects
*/
function set_for_context_from_datarecord($level, $record)
{
global $CURMAN;
$contextlevel = context_level_base::get_custom_context_level($level, 'block_curr_admin');
if (!$contextlevel) {
// context levels not set up -- we must be in initial installation,
// so no fields set up
return true;
}
$context = get_context_instance($contextlevel, $record->id);
$fields = field::get_for_context_level($contextlevel);
$fields = $fields ? $fields : array();
foreach ($fields as $field) {
$fieldname = "field_{$field->shortname}";
if (isset($record->{$fieldname})) {
field_data::set_for_context_and_field($context, new field($field), $record->{$fieldname});
}
}
return true;
}
示例14: definition
/**
* defines items in the form
*/
public function definition()
{
global $CURMAN;
$configData = array('title');
if ($this->_customdata['obj']) {
// FIXME: This is probably not be the right place for set_data. Move it.
$this->set_data($this->_customdata['obj']);
}
$mform =& $this->_form;
$mform->addElement('hidden', 'id');
$mform->addElement('hidden', 'courseid');
$mform->addElement('text', 'idnumber', get_string('curriculum_idnumber', 'block_curr_admin') . ':');
$mform->setType('idnumber', PARAM_TEXT);
$mform->addRule('idnumber', null, 'required', null, 'client');
$mform->addRule('idnumber', null, 'maxlength', 100);
$mform->setHelpButton('idnumber', array('curriculaform/idnumber', get_string('curriculum_idnumber', 'block_curr_admin'), 'block_curr_admin'));
$mform->addElement('text', 'name', get_string('curriculum_name', 'block_curr_admin') . ':');
$mform->setType('name', PARAM_TEXT);
$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', null, 'maxlength', 64);
$mform->setHelpButton('name', array('curriculaform/name', get_string('curriculum_name', 'block_curr_admin'), 'block_curr_admin'));
$attributes = array('rows' => '2', 'cols' => '40');
$mform->addElement('textarea', 'description', get_string('curriculum_description', 'block_curr_admin') . ':', $attributes);
$mform->setType('description', PARAM_CLEAN);
$mform->setHelpButton('description', array('curriculaform/description', get_string('curriculum_description', 'block_curr_admin'), 'block_curr_admin'));
$mform->addElement('text', 'reqcredits', get_string('required_credits', 'block_curr_admin') . ':');
$mform->setType('reqcredits', PARAM_NUMBER);
$mform->addRule('reqcredits', null, 'maxlength', 10);
$mform->setHelpButton('reqcredits', array('curriculaform/reqcredits', get_string('required_credits', 'block_curr_admin'), 'block_curr_admin'));
$choices = range(0, 10);
$mform->addElement('select', 'priority', get_string('priority', 'block_curr_admin') . ':', $choices);
$mform->setHelpButton('priority', array('curriculaform/priority', get_string('priority', 'block_curr_admin'), 'block_curr_admin'));
//because moodle forms will not allow headers within headers
$mform->addElement('header', 'editform', get_string('time_settings', 'block_curr_admin'));
// Time to complete
$mform->addElement('text', 'timetocomplete', get_string('time_to_complete', 'block_curr_admin') . ':');
$mform->setType('timetocomplete', PARAM_TEXT);
$mform->addRule('timetocomplete', null, 'maxlength', 64);
$mform->setHelpButton('timetocomplete', array('curriculaform/timetocomplete', get_string('time_to_complete', 'block_curr_admin'), 'block_curr_admin'));
//$mform->addElement('html', '<small>' . get_string('tips_time_to_complete', 'block_curr_admin') . '</small><br /><br />');
// Frequency (only display if curriculum expiration is currently enabled).
if (!empty($CURMAN->config->enable_curriculum_expiration)) {
$mform->addElement('text', 'frequency', get_string('expiration', 'block_curr_admin') . ':');
$mform->setType('frequency', PARAM_TEXT);
$mform->addRule('frequency', null, 'maxlength', 64);
$mform->setHelpButton('frequency', array('curriculaform/frequency', get_string('expiration', 'block_curr_admin'), 'block_curr_admin'));
} else {
$mform->addElement('hidden', 'frequency');
}
//$mform->addElement('html', '<small>' . get_string('tips_time_to_redo', 'block_curr_admin') . '</small><br /><br />');
$mform->addElement('static', '', '', '<small>' . get_string('tips_time_format', 'block_curr_admin') . '</small>');
// custom fields
$fields = field::get_for_context_level('curriculum');
$fields = $fields ? $fields : array();
$lastcat = null;
$context = isset($this->_customdata['obj']) && isset($this->_customdata['obj']->id) ? get_context_instance(context_level_base::get_custom_context_level('curriculum', 'block_curr_admin'), $this->_customdata['obj']->id) : get_context_instance(CONTEXT_SYSTEM);
require_once CURMAN_DIRLOCATION . '/plugins/manual/custom_fields.php';
foreach ($fields as $rec) {
$field = new field($rec);
if (!isset($field->owners['manual'])) {
continue;
}
if ($lastcat != $rec->categoryid) {
$lastcat = $rec->categoryid;
$mform->addElement('header', "category_{$lastcat}", htmlspecialchars($rec->categoryname));
}
manual_field_add_form_element($this, $context, $field);
}
$this->add_action_buttons();
}
示例15: set_for_context_from_datarecord
/**
* Convenience function for use by data_object objects
*
* @param mixed $contextlevel the context level. Either a numeric value,
* or the name of the context level from the ELIS Program Manager
* @param object $record the data_object to fetch the field values from
* @return bool true
*/
public static function set_for_context_from_datarecord($contextlevel, $record)
{
if (!is_numeric($contextlevel)) {
$contextlevel = \local_eliscore\context\helper::get_level_from_name($contextlevel);
if (!$contextlevel) {
// context levels not set up -- we must be in initial installation,
// so no fields set up
return true;
}
}
$ctxclass = \local_eliscore\context\helper::get_class_for_level($contextlevel);
$context = $ctxclass::instance($record->id);
$fields = field::get_for_context_level($contextlevel);
$fields = $fields ? $fields : array();
foreach ($fields as $field) {
$fieldname = "field_{$field->shortname}";
if (isset($record->{$fieldname})) {
self::set_for_context_and_field($context, $field, $record->{$fieldname});
}
}
return true;
}