示例#1
0
 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
0
 /**
  * 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
0
 /**
  * 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);
     }
 }
 /**
  * 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
0
 /**
  * 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
0
 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
0
 /**
  * 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();
 }
 /**
  * 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
0
 /**
  * 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
0
 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);
 }
 /**
  * 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
                             WHERE disc.course = clsmdl.moodlecourseid
                               AND post.userid = user.id
                           ) AS numposts', get_string('column_discussion_posts', $this->lang_file), 'cssdiscussion_posts', 'center', true);
     //create an IN clause identifying modules that are considered resources
     //todo: use get_in_or_equal
     $modules = $this->get_resource_modules();
     $in = "IN ('" . implode("', '", $modules) . "')";
     // resources accessed
     $columns[] = new table_report_column("(SELECT COUNT(*) FROM {log} log\n                                WHERE log.module {$in}\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;
 }
 /**
  * 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
0
 /**
  * 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;
 }
 /**
  * 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
0
 /**
  * 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;
 }
示例#16
0
 /**
  * Create the elements of the group
  */
 public function _createElements()
 {
     global $PAGE, $OUTPUT;
     $attributes = $this->getAttributes();
     if (!$attributes) {
         $attributes = array();
     }
     $this->_generateId();
     $id = $this->getAttribute('id');
     $this->_elements = array();
     $form = new MoodleQuickForm('test', 'POST', 'http://localhost');
     // A hidden element to contain the actual values to be submitted.
     $this->_elements[] = $form->createElement('hidden', 'value', '', array('id' => $id . '_value'));
     // A container that will be populated by JavaScript.
     $this->_elements[] = $form->createElement('static', '', '', "<div id=\"{$id}_container\"></div>");
     $options = array('id' => $id, 'up' => $OUTPUT->pix_url('t/up')->out(false), 'down' => $OUTPUT->pix_url('t/down')->out(false), 'del' => $OUTPUT->pix_url('t/delete')->out(false));
     $fields = field::get_for_context_level($this->_options['contextlevel']);
     $fieldsbycategory = array();
     $filter = $this->_options['fieldfilter'];
     foreach ($fields as $field) {
         if ($filter && !call_user_func($filter, $field)) {
             continue;
         }
         if (!isset($fieldsbycategory[$field->categoryname])) {
             $fieldsbycategory[$field->categoryname] = array();
         }
         $fieldsbycategory[$field->categoryname][$field->id] = $field->name;
     }
     $options['fields'] = $fieldsbycategory;
     $PAGE->requires->string_for_js('add', 'moodle');
     $PAGE->requires->strings_for_js(array('allitemsselected', 'field_category', 'field_name', 'nofieldsselected'), 'local_eliscore');
     $PAGE->requires->yui_module('moodle-local_eliscore-custom_field_multiselect', 'M.local_eliscore.init_custom_field_multiselect', array($options));
     foreach ($this->_elements as $element) {
         if (method_exists($element, 'setHiddenLabel')) {
             $element->setHiddenLabel(true);
         }
     }
 }
示例#17
0
 /**
  * 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 pm_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_ELIS_USER);
         $fields = $fields ? $fields : array();
         foreach ($fields as $field) {
             $fieldnames["field_{$field->shortname}"] = 1;
         }
     }
     parent::user_filtering($fieldnames, $baseurl, $extraparams);
 }
示例#18
0
 /**
  * items in the form
  *
  * @uses $USER
  */
 public function definition()
 {
     global $USER;
     $fields = field::get_for_context_level('track');
     foreach ($fields as $rec) {
         $field = new field($rec);
         if (strcmp($field->datatype, "num") == 0) {
             $fieldname = "field_{$field->shortname}";
             if (isset($this->_customdata['obj']->{$fieldname})) {
                 $formatnum = $field->format_number($this->_customdata['obj']->{$fieldname});
                 $this->_customdata['obj']->{$fieldname} = $formatnum;
             }
         }
     }
     $this->set_data($this->_customdata['obj']);
     $mform =& $this->_form;
     $mform->addElement('hidden', 'id');
     $mform->setType('id', PARAM_INT);
     $curs = array();
     if (!empty($USER->id)) {
         // TBD: and/or capability 'local/elisprogram:track_edit|view' ?
         // This is necessary for creating a new track but will prevent a parent programs from appearing
         // when the user has track edit permissions but not track creation permission -- ELIS-5954
         $contexts = get_contexts_by_capability_for_user('curriculum', 'local/elisprogram:track_create', $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', 'local_elisprogram') . ':', $curid_options);
         $mform->addRule('curid', get_string('required'), 'required', NULL, 'client');
         $mform->addHelpButton('curid', 'trackform:curriculum_curid', 'local_elisprogram');
     } else {
         // Track editing, do not allow the user to change curriculum
         // Make sure that the parent program for this track is always included otherwise the display is messed up
         // and hitting the form Cancel button causes a DB error -- ELIS-5954
         $track = new track($this->_customdata['obj']->id);
         $curs = curriculum_get_listing('name', 'ASC', 0, 0, $track->curriculum->name);
         $mform->addElement('static', 'curidstatic', get_string('curriculum', 'local_elisprogram') . ':', $curs[$this->_customdata['obj']->curid]->name);
         $mform->addHelpButton('curidstatic', 'trackform:curriculum_curidstatic', 'local_elisprogram');
         $mform->addElement('hidden', 'curid');
         $mform->setType('curid', PARAM_INT);
     }
     $mform->addElement('text', 'idnumber', get_string('track_idnumber', 'local_elisprogram') . ':');
     $mform->setType('idnumber', PARAM_TEXT);
     $mform->addRule('idnumber', get_string('required'), 'required', NULL, 'client');
     $mform->addRule('idnumber', null, 'maxlength', 100);
     $mform->addHelpButton('idnumber', 'trackform:track_idnumber', 'local_elisprogram');
     $mform->addElement('text', 'name', get_string('track_name', 'local_elisprogram') . ':');
     $mform->setType('name', PARAM_TEXT);
     $mform->addRule('name', null, 'maxlength', 255);
     $mform->addRule('name', get_string('required'), 'required', NULL, 'client');
     $mform->addHelpButton('name', 'trackform:track_name', 'local_elisprogram');
     $mform->addElement('textarea', 'description', get_string('track_description', 'local_elisprogram') . ':');
     $mform->setType('description', PARAM_CLEAN);
     $mform->addHelpButton('description', 'trackform:track_description', 'local_elisprogram');
     $mform->addElement('date_selector', 'startdate', get_string('track_startdate', 'local_elisprogram') . ':', array('optional' => true));
     $mform->addElement('date_selector', 'enddate', get_string('track_enddate', 'local_elisprogram') . ':', array('optional' => true));
     $mform->addHelpButton('startdate', 'trackform:track_startdate', 'local_elisprogram');
     if (!empty($this->_customdata['obj']->id)) {
         $trackassignobj = new trackassignment(array('trackid' => $this->_customdata['obj']->id));
     }
     // Only show auto-create checkbox if the track does not have any classes assigned
     if (!isset($trackassignobj) || 0 == $trackassignobj->count_assigned_classes_from_track()) {
         $mform->addElement('checkbox', 'autocreate', get_string('track_autocreate', 'local_elisprogram') . ':');
         $mform->addHelpButton('autocreate', 'trackform:track_autocreate', 'local_elisprogram');
     }
     // custom fields
     $this->add_custom_fields('track', 'local/elisprogram:track_edit', 'local/elisprogram:track_view', 'curriculum');
     $this->add_action_buttons();
 }
示例#19
0
 function definition()
 {
     global $USER, $CFG, $COURSE, $CURMAN;
     parent::definition();
     if (!empty($this->_customdata['obj'])) {
         $obj = $this->_customdata['obj'];
         if (empty($obj->startdate) || $obj->startdate == 0) {
             $this->set_data(array('disablestart' => '1'));
         }
         if (empty($obj->enddate) || $obj->enddate == 0) {
             $this->set_data(array('disableend' => '1'));
         }
         if (isset($obj->starttimeminute) && isset($obj->starttimehour)) {
             $this->set_data(array('starttime' => array('minute' => $obj->starttimeminute, 'hour' => $obj->starttimehour)));
         }
         if (isset($obj->endtimeminute) && isset($obj->endtimehour)) {
             $this->set_data(array('endtime' => array('minute' => $obj->endtimeminute, 'hour' => $obj->endtimehour)));
         }
     }
     $mform =& $this->_form;
     $mform->addElement('hidden', 'id');
     // If there is no custom data for the course, create some
     if (empty($this->_customdata['obj']->course->name) || empty($this->_customdata['obj']->id)) {
         $courses = array();
         if (!empty($USER->id)) {
             $contexts = get_contexts_by_capability_for_user('course', 'block/curr_admin:class:create', $USER->id);
             // get listing of available ELIS courses
             $courses = course_get_listing('name', 'ASC', 0, 0, '', '', $contexts);
         }
         // Add course select
         $attributes = array('onchange' => 'update_trk_multiselect(); ');
         $selections = array();
         if (!empty($courses)) {
             foreach ($courses as $course) {
                 $selections[$course->id] = '(' . $course->idnumber . ')' . $course->name;
             }
         }
         $mform->addElement('select', 'courseid', get_string('course', 'block_curr_admin') . ':', $selections, $attributes);
         $mform->setHelpButton('courseid', array('cmclassform/course', get_string('course', 'block_curr_admin'), 'block_curr_admin'));
         $firstcourse = reset($courses);
         $this->firstcourse = $firstcourse;
         if (false !== $firstcourse && empty($this->_customdata['obj']->id)) {
             $this->add_track_multi_select($firstcourse->id);
         } elseif (!empty($courses)) {
             $this->add_track_multi_select($this->_customdata['obj']->courseid);
         }
     } else {
         $extra_params = array();
         $mform->addElement('static', 'courseid', get_string('course', 'block_curr_admin') . ':');
         // Get current action and set param accordingly
         $current_action = optional_param('action', 'view', PARAM_ALPHA);
         $extra_params['action'] = $current_action;
         $extra_params['s'] = 'crs';
         // Want to set the url for the course
         $extra_params['id'] = $this->_customdata['obj']->courseid;
         // Course id
         $course_url = $this->get_moodle_url($extra_params);
         $course_name = '(' . $this->_customdata['obj']->course->idnumber . ')' . '<a href="' . $course_url . '" >' . $this->_customdata['obj']->course->name . '</a>';
         $this->set_data(array('courseid' => $course_name));
         $mform->setHelpButton('courseid', array('cmclassform/course', get_string('course', 'block_curr_admin'), 'block_curr_admin'));
         $this->add_track_multi_select($this->_customdata['obj']->courseid);
     }
     if (!empty($this->_customdata['obj']->courseid)) {
         $mform->freeze('courseid');
     } else {
         $mform->addRule('courseid', get_string('required'), 'required', NULL, 'client');
     }
     // Done adding course select
     //get_string('general');
     $mform->addElement('text', 'idnumber', get_string('class_idnumber', 'block_curr_admin') . ':');
     $mform->addRule('idnumber', get_string('required'), 'required', NULL, 'client');
     $mform->setType('idnumber', PARAM_TEXT);
     $mform->setHelpButton('idnumber', array('cmclassform/idnumber', get_string('class_idnumber', 'block_curr_admin'), 'block_curr_admin'));
     $mform->addElement('date_selector', 'startdate', get_string('class_startdate', 'block_curr_admin') . ':', array('optional' => true, 'disabled' => 'disabled'));
     $mform->setHelpButton('startdate', array('cmclassform/startdate', get_string('class_startdate', 'block_curr_admin'), 'block_curr_admin'));
     $mform->addElement('date_selector', 'enddate', get_string('class_enddate', 'block_curr_admin') . ':', array('optional' => true));
     // They may very likely be a much better way of checking for this...
     if (empty($obj->starttimehour) and empty($obj->starttimeminute)) {
         $mform->addElement('time_selector', 'starttime', get_string('class_starttime', 'block_curr_admin') . ':', array('optional' => true, 'checked' => 'checked', 'display_12h' => $CURMAN->config->time_format_12h));
     } else {
         $mform->addElement('time_selector', 'starttime', get_string('class_starttime', 'block_curr_admin') . ':', array('optional' => true, 'checked' => 'unchecked', 'display_12h' => $CURMAN->config->time_format_12h));
     }
     $mform->setHelpButton('starttime', array('cmclassform/starttime', get_string('class_starttime', 'block_curr_admin'), 'block_curr_admin'));
     // Do the same thing for the endtime
     if (empty($obj->endtimehour) and empty($obj->endtimeminute)) {
         $mform->addElement('time_selector', 'endtime', get_string('class_endtime', 'block_curr_admin') . ':', array('optional' => true, 'checked' => 'checked', 'display_12h' => $CURMAN->config->time_format_12h));
     } else {
         $mform->addElement('time_selector', 'endtime', get_string('class_endtime', 'block_curr_admin') . ':', array('optional' => true, 'checked' => 'unchecked', 'display_12h' => $CURMAN->config->time_format_12h));
     }
     $mform->addElement('text', 'maxstudents', get_string('class_maxstudents', 'block_curr_admin') . ':');
     $mform->setType('maxstudents', PARAM_INT);
     $mform->setHelpButton('maxstudents', array('cmclassform/maxstudents', get_string('class_maxstudents', 'block_curr_admin'), 'block_curr_admin'));
     // Environment selector
     $envs = environment_get_listing();
     $envs = $envs ? $envs : array();
     $o_envs = array(get_string('none', 'block_curr_admin'));
     foreach ($envs as $env) {
         $o_envs[$env->id] = $env->name;
     }
     $mform->addElement('select', 'environmentid', get_string('environment', 'block_curr_admin') . ':', $o_envs);
     $mform->setHelpButton('environmentid', array('cmclassform/environment', get_string('environment', 'block_curr_admin'), 'block_curr_admin'));
     // Course selector
     if (empty($this->_customdata['obj']->moodlecourseid)) {
         $this->add_moodle_course_select();
     } else {
         global $CURMAN;
         $coursename = $CURMAN->db->get_field('course', 'fullname', 'id', $this->_customdata['obj']->moodlecourseid);
         $mform->addElement('static', 'class_attached_course', get_string('class_attached_course', 'block_curr_admin') . ':', "<a href=\"{$CFG->wwwroot}/course/view.php?id={$this->_customdata['obj']->moodlecourseid}\">{$coursename}</a>");
         $mform->setHelpButton('class_attached_course', array('cmclassform/moodlecourseid', get_string('moodlecourse', 'block_curr_admin'), 'block_curr_admin'));
         $mform->addElement('hidden', 'moodlecourseid');
     }
     $mform->addElement('checkbox', 'enrol_from_waitlist', get_string('waitlistenrol', 'block_curr_admin') . ':');
     $mform->setHelpButton('enrol_from_waitlist', array('cmclassform/waitlistenrol', get_string('waitlistenrol', 'block_curr_admin'), 'block_curr_admin'));
     // custom fields
     $fields = field::get_for_context_level('class');
     $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('class', '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();
 }
 /**
  * Retrieves the complete set of SQL conditions related to curriculum custom fields
  *
  * @param boolean $showing_curricula True if we are showing curriculum information on the
  *                                   report, false otherwise
  * @return array The complete collection of conditions related to curriculum custom fields & params
  */
 function get_curr_customfield_conditions($showing_curricula)
 {
     $params = array();
     //our return value
     $conditions = array();
     //set up the context level for dealing with curriculum custom fields
     $ctxtlvl = CONTEXT_ELIS_PROGRAM;
     $curriculumfields = field::get_for_context_level($ctxtlvl);
     //iterate through all curriculum custom fields
     foreach ($curriculumfields as $id => $curriculumfield) {
         if ($condition = $this->get_curr_customfield_condition($showing_curricula, $id, $curriculumfield)) {
             $conditions[] = $condition[0];
             $params = array_merge($params, $condition[1]);
         }
     }
     return array($conditions, $params);
 }
示例#21
0
 /**
  * Make field list
  *
  * @param array $groups A two dimensional array of groups => choices => values
  */
 function make_field_list($groups)
 {
     // Force $groups to be an associative array
     foreach ($groups as $key => $choices) {
         if (!$this->is_assoc_array($choices)) {
             $groups[$key] = array_fill_keys($choices, '');
         }
     }
     if (get_class($this) != 'generalized_filter_userprofilematch') {
         // UPM filter uses Moodle profile, we should obey 'extra' option
         // Generate a list of custom fields
         foreach ($this->sections as $group => $section) {
             $ctxtlvl = \local_eliscore\context\helper::get_level_from_name($section['name']);
             $this->sections[$group]['contextlevel'] = $ctxtlvl;
             // Add custom fields to array
             $extrafields = field::get_for_context_level($ctxtlvl);
             $this->get_custom_fields($group, $extrafields);
         }
     }
     // Generate the standard fields
     foreach ($groups as $group => $choices) {
         $custom_fields = isset($this->_fields[$group]) ? $this->_fields[$group] : array();
         $this->_fields[$group] = array();
         foreach ($choices as $name => $alias) {
             $label = $name;
             if (!empty($alias)) {
                 $label = get_string($alias, $this->languagefile);
             } else {
                 if (isset($this->labels[$group]) && array_key_exists($name, $this->labels[$group])) {
                     $label = get_string($this->labels[$group][$name], $this->languagefile);
                 } else {
                     foreach ($this->sections as $section) {
                         if (array_key_exists($name, $section['custom'])) {
                             $label = $section['custom'][$name];
                         }
                     }
                 }
             }
             $this->_fields[$group][$name] = $label;
         }
         if (!empty($this->sections[$group]['custom'])) {
             $this->_fields[$group] = array_merge($this->_fields[$group], $this->sections[$group]['custom']);
         }
         if (!empty($custom_fields)) {
             $this->_fields[$group] = array_merge($this->_fields[$group], $custom_fields);
         }
     }
 }
示例#22
0
 /**
  * Constructor
  *
  * @param string $uniqueid Unique prefix for filters
  * @param string $label    Filter label
  * @param array  $options  Filter options (see above)
  * @return array The sub-filters
  * @uses $CFG
  */
 function generalized_filter_curriculumclass($uniqueid, $label, $options = array())
 {
     global $CFG;
     parent::multifilter($uniqueid, $label, $options);
     $this->_fields = array();
     require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_connection', 'yui_json', "{$CFG->wwwroot}/curriculum/js/dependentselect.js"), true);
     if (empty($options['help'])) {
         $options['help'] = array();
     }
     // Get table aliases
     if (empty($options['tables'])) {
         $options['tables'] = array();
     }
     $allfields = array();
     foreach ($this->labels as $group => $labels) {
         foreach ($labels as $key => $val) {
             $this->record_short_field_name($group . '-' . $key);
         }
     }
     // Check for & assign table aliases
     foreach ($this->tables as $group => $tables) {
         if (!array_key_exists($group, $options['tables'])) {
             continue;
         }
         foreach ($tables as $key => $val) {
             if (!empty($options['tables'][$group][$key])) {
                 // use defaults table aliases if not specified
                 $this->tables[$group][$key] = $options['tables'][$group][$key];
             }
         }
     }
     foreach ($this->sections as $group => $section) {
         $ctxtlvl = context_level_base::get_custom_context_level($section['name'], 'block_curr_admin');
         $this->sections[$group]['contextlevel'] = $ctxtlvl;
         // Add custom fields to array
         $extrafields = field::get_for_context_level($ctxtlvl);
         $this->get_custom_fields($group, $extrafields);
     }
     // Force $options['choices'] to be an associative array
     foreach ($options['choices'] as $key => $choices) {
         if (!$this->is_assoc_array($choices)) {
             $options['choices'][$key] = array_fill_keys($choices, '');
         }
     }
     foreach ($options['choices'] as $group => $choices) {
         $allfields[$group] = array();
         foreach ($choices as $name => $alias) {
             $label = $name;
             if (!empty($alias)) {
                 $label = get_string($alias, $this->languagefile);
             } else {
                 if (array_key_exists($name, $this->defaultlabels[$group])) {
                     $label = get_string($this->defaultlabels[$group][$name], $this->languagefile);
                 } else {
                     foreach ($this->sections as $section) {
                         if (array_key_exists($name, $section['custom'])) {
                             $label = $section['custom'][$name];
                         }
                     }
                 }
             }
             $allfields[$group][$name] = $label;
         }
         if (!empty($options['extra']) && !empty($this->sections[$group]['custom'])) {
             $allfields[$group] = array_merge($allfields[$group], $this->sections[$group]['custom']);
         }
     }
     foreach ($allfields as $group => $fields) {
         $this->_filters[$group] = array();
         foreach ($fields as $name => $label) {
             // must setup select choices for specific fields
             $myoptions = $this->make_filter_options($group, $name, $options['help'], $options['tables']);
             if (!is_array($myoptions)) {
                 continue;
             }
             $filterid = $this->_uniqueid . $group . '-' . substr($name, 0, MAX_FILTER_SUFFIX_LEN);
             $ftype = (string) $this->fieldtofiltermap[$group][$name];
             $advanced = !empty($options['advanced'][$group]) && in_array($name, $options['advanced'][$group]) || !empty($options['notadvanced'][$group]) && !in_array($name, $options['notadvanced'][$group]);
             $this->_filters[$group][$name] = new generalized_filter_entry($filterid, $myoptions['talias'], $myoptions['dbfield'], $label, $advanced, $ftype, $myoptions);
         }
     }
 }
示例#23
0
 public function set_from_data($data)
 {
     $fields = field::get_for_context_level('curriculum', '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);
 }
示例#24
0
 /**
  * Displays the portion of the field editing form specific to a context level
  *
  * @param  string  $contextlevel_name  The description of the context level, such
  *                                     as 'course' or 'class'
  * @param  string  $field_header       The display string used for the header above
  *                                     the field value entry elements
  * @param  string  $button_text        Text to display on the add button
  * @uses   $CFG
  * @uses   $DB
  */
 private function display_for_context($contextlevel_name, $field_header, $button_text)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/local/elisprogram/lib/contexts.php';
     $fields = field::get_for_context_level($contextlevel_name)->to_array();
     $fields = $fields ? $fields : array();
     // only retrieve fields for the specified context level
     $contextlevel = \local_eliscore\context\helper::get_level_from_name($contextlevel_name);
     $questions = $DB->get_records('block_courserequest_fields', array('contextlevel' => $contextlevel));
     print '<fieldset class="hidden">';
     if (!empty($questions)) {
         print '<table cellpadding="2">';
         print '<tr align="right">';
         // print '<th><span style="margin-right:10px;">'.get_string('name_on_form', 'block_courserequest').'</span></th>';
         print '<th><span style="margin-right:10px;">' . get_string('existing_fields', 'block_courserequest') . '</span></th>';
         print '<th><span style="margin-right:10px;">' . $field_header . '</span></th>';
         print '</tr>';
         foreach ($questions as $question) {
             print '<tr>';
             if ($question->fieldid) {
                 $field = new field($question->fieldid);
                 try {
                     $fieldname = $field->name;
                 } catch (dml_missing_record_exception $ex) {
                     continue;
                     // ELIS-4014: custom field deleted!
                 }
             } else {
                 $fieldname = 'select a field';
             }
             // print "<td><input type="text" name=\"custom_name[]\" value=\"$value\" /></td>";
             print "<td>{$fieldname}</td>";
             print "<td><select name=\"field[{$question->id}]\" />";
             // print '<option value="none">none</option>';
             foreach ($fields as $f) {
                 if ($f->id == $question->fieldid) {
                     print '<option value="' . $f->id . '" selected="true">' . $f->name . '</option>';
                     $selected = true;
                 } else {
                     print '<option value="' . $f->id . '">' . $f->name . '</option>';
                 }
             }
             print "</select></td>";
             print "<td><input type=\"submit\" name=\"delete[{$question->id}]\" value=\"" . get_string('delete', 'block_courserequest') . '" /></td>';
             print '</tr>';
         }
         print '</table>';
     }
     $add_element_name = "add_field_{$contextlevel}";
     print '<div style="margin-top:5px"><input type="submit" name="' . $add_element_name . '" value="' . $button_text . '" /></div>';
     print '</fieldset>';
 }
示例#25
0
 function validate_custom_fields($data, $eliscontext)
 {
     $errors = array();
     $contextlevel = \local_eliscore\context\helper::get_level_from_name($eliscontext);
     $fields = field::get_for_context_level($contextlevel);
     $fields = $fields ? $fields : array();
     if (!empty($data['id'])) {
         $contextclass = \local_eliscore\context\helper::get_class_for_level($contextlevel);
         $context = $contextclass::instance($data['id']);
         $contextid = $context->id;
     } else {
         $contextid = 0;
     }
     foreach ($fields as $field) {
         $field = new field($field);
         $key = "field_{$field->shortname}";
         if ($errstr = manual_field_validation(isset($data[$key]) ? $data[$key] : null, $field, $contextid)) {
             $errors[$key] = $errstr;
         }
         //error_log("cmform.class.php::validation(): contextid = {$contextid}, data[{$key}] = {$data[$key]}, errors[$key] = {$errstr}");
     }
     return $errors;
 }
示例#26
0
 function validation($data, $files)
 {
     global $CFG, $CURMAN;
     $errors = parent::validation($data, $files);
     // Use a default for 'id' if we're doing an add
     if (!$data['id']) {
         $data['id'] = 0;
     }
     if (!empty($data['username'])) {
         if (!$this->check_unique(USRTABLE, 'username', $data['username'], $data['id'])) {
             $errors['username_group'] = get_string('badusername', 'block_curr_admin');
         }
     } else {
         if (!$data['id'] && empty($data['id_same_user'])) {
             $errors['username_group'] = get_string('required');
         }
     }
     if (!empty($data['idnumber'])) {
         if (!$this->check_unique(USRTABLE, 'idnumber', $data['idnumber'], $data['id'])) {
             $errors['idnumber'] = get_string('badidnumber', 'block_curr_admin');
         }
     }
     // Validate the supplied email addresses as best we can...
     if (!empty($data['email'])) {
         if (!$this->check_unique(USRTABLE, 'email', $data['email'], $data['id'])) {
             $errors['email'] = get_string('emailexists');
         }
     }
     if (!empty($data['email2'])) {
         if (!$this->check_unique(USRTABLE, 'email', $data['email2'], $data['id'])) {
             $errors['email2'] = get_string('emailexists');
         }
     }
     if (!empty($data['contactemail'])) {
         if (!$this->check_unique(USRTABLE, 'email', $data['contactemail'], $data['id'])) {
             $errors['contactemail'] = get_string('emailexists');
         }
     }
     // validate custom profile fields
     $fields = field::get_for_context_level(context_level_base::get_custom_context_level('user', 'block_curr_admin'));
     $fields = $fields ? $fields : array();
     if ($data['id']) {
         $context = get_context_instance(context_level_base::get_custom_context_level('user', 'block_curr_admin'), $data['id']);
         $contextid = $context->id;
     } else {
         $contextid = 0;
     }
     foreach ($fields as $field) {
         $field = new field($field);
         $key = "field_{$field->shortname}";
         if ($field->multivalued) {
             $manual = new field_owner($field->owners['manual']);
             $fielddata = isset($data[$key]) ? $data[$key] : array();
             if ($manual->param_required) {
                 if (empty($fielddata)) {
                     $errors[$key] = get_string('required');
                 } else {
                     if (!empty($manual->param_options)) {
                         $options = explode("\n", $manual->param_options);
                         array_walk($options, 'trim_cr');
                         // TBD: defined below
                         foreach ($fielddata as $entry) {
                             if (!in_array($entry, $options)) {
                                 $errors[$key] = get_string('required');
                                 break;
                             }
                         }
                     }
                 }
             }
             if (!isset($errors[$key]) && $field->forceunique && $contextid) {
                 $where = "contextid != {$contextid} AND fieldid = {$field->id}";
                 if ($recs = get_records_select($field->data_table(), $where, 'contextid, data')) {
                     $curcontext = -1;
                     $vals = null;
                     foreach ($recs as $rec) {
                         if ($curcontext != $rec->contextid) {
                             if (!empty($vals)) {
                                 $adif = array_diff($vals, $fielddata);
                                 if (empty($adif)) {
                                     $errors[$key] = get_string('valuealreadyused');
                                     // TBD^^^ "[These/This combination of] values already uesd!"
                                     $vals = null;
                                     break;
                                 }
                             }
                             $curcontext = $rec->contextid;
                             $vals = array();
                         }
                         $vals[] = $rec->data;
                     }
                     if (!empty($vals)) {
                         $adif = array_diff($vals, $fielddata);
                         if (empty($adif)) {
                             $errors[$key] = get_string('valuealreadyused');
                             // TBD^^^ "[These/This combination of] values already uesd!"
                         }
                     }
                 }
             }
         } else {
             if ($field->forceunique) {
                 // NON-MULTIVALUED case
                 $fielddata = $CURMAN->db->get_record($field->data_table(), 'fieldid', $field->id, 'data', $data[$key]);
                 //print_object($fielddata);
                 if ($fielddata && $fielddata->contextid != $contextid) {
                     $errors[$key] = get_string('valuealreadyused');
                 }
             }
         }
     }
     return $errors;
 }
 /**
  * Return a boolean to indicate whether or not this filter is displayed
  * depending upon whether any custom fields are found for this user
  * @param string       $field_type  type of custom field to check
  * @return boolean  true if the filter is to show
  */
 function check_for_custom_fields($field_type)
 {
     // Get custom course fields by context level
     $context = context_level_base::get_custom_context_level($field_type, 'block_curr_admin');
     $fields = field::get_for_context_level($context);
     $fields = $fields ? $fields : array();
     $testfields = array();
     foreach ($fields as $field) {
         //make sure the current user can access this field in at least one
         //course context
         $owners = field_owner::get_for_field($field);
         if (!block_php_report_field_accessible($owners)) {
             continue;
         }
         return true;
     }
     return false;
 }
 *
 */
require_once '../../../../config.php';
require_once $CFG->dirroot . '/curriculum/config.php';
require_once $CFG->dirroot . '/curriculum/lib/customfield.class.php';
require_once $CFG->dirroot . '/blocks/php_report/sharedlib.php';
// Get required yui javascript for ajax calls
require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_connection', "{$CFG->wwwroot}/curriculum/js/associate.class.js", "{$CFG->wwwroot}/curriculum/js/customfields.js"), true);
$lang_file = 'rlreport_individual_course_progress';
$site = get_site();
$block_id = required_param('instance', PARAM_RAW);
$fieldidlist = optional_param('fieldidlist', null, PARAM_TEXT);
$fieldnamelist = optional_param('fieldnamelist', null, PARAM_TEXT);
// Get custom course fields by context level
$context = context_level_base::get_custom_context_level('course', 'block_curr_admin');
$fields = field::get_for_context_level($context);
$fields = $fields ? $fields : array();
//Unserialize fieldidlist to check against field list
if (isset($fieldidlist)) {
    $fieldidlist = @unserialize(base64_decode($fieldidlist));
}
if (isset($fieldnamelist)) {
    $fieldnamelist = @unserialize(base64_decode($fieldnamelist));
}
$categories = field_category::get_for_context_level($context);
$categories = $categories ? $categories : array();
// divide the fields into categories
$fieldsbycategory = array();
foreach ($categories as $category) {
    $fieldsbycategory[$category->name] = array();
}
示例#29
0
文件: lib.php 项目: jamesmcq/elis
/**
 * Migrate a single Moodle user to the Program Management system.  Will
 * only do this for users who have an idnumber set.
 *
 * @param object $mu Moodle user object
 * @return boolean Whether user was synchronized or not
 */
function pm_moodle_user_to_pm($mu)
{
    global $CFG, $DB;
    require_once $CFG->dirroot . '/lib/moodlelib.php';
    require_once elis::lib('data/customfield.class.php');
    require_once elispm::lib('data/user.class.php');
    require_once elispm::lib('data/usermoodle.class.php');
    require_once elis::lib('data/data_filter.class.php');
    require_once $CFG->dirroot . '/user/profile/lib.php';
    require_once elis::lib('lib.php');
    if (!isset($mu->id)) {
        return true;
    }
    // re-fetch, in case this is from a stale event
    $mu = $DB->get_record('user', array('id' => $mu->id));
    if (user_not_fully_set_up($mu) || !$mu->confirmed) {
        // Prevent the sync if a bare-bones user record is being created by create_user_record
        // or Moodle user has not yet been confirmed.
        return true;
    }
    //not going to be concerned with city or password for now
    if (empty($mu->idnumber) && elis::$config->local_elisprogram->auto_assign_user_idnumber) {
        //make sure the current user's username does not match up with some other user's
        //idnumber (necessary since usernames and idnumbers aren't bound to one another)
        if (!$DB->record_exists('user', array('idnumber' => $mu->username))) {
            $mu->idnumber = $mu->username;
            $DB->update_record('user', $mu);
        }
    }
    // skip user if no ID number set
    if (empty($mu->idnumber)) {
        return true;
    }
    // track whether we're syncing an idnumber change over to the PM system
    $idnumber_updated = false;
    // track whether an associated Moodle user is linked to the current PM user
    $moodle_user_exists = false;
    // determine if the user is already noted as having been associated to a PM user
    // this will join to Moodle user and PM user table to ensure data correctness
    $filters = array();
    $filters[] = new join_filter('muserid', 'user', 'id');
    $filters[] = new join_filter('cuserid', user::TABLE, 'id');
    $filters[] = new field_filter('muserid', $mu->id);
    if ($um = usermoodle::find($filters)) {
        if ($um->valid()) {
            $um = $um->current();
            //signal that an associated user already exists
            $moodle_user_exists = true;
            // determine if the Moodle user idnumber was updated
            if ($um->idnumber != $mu->idnumber) {
                //signal that the idnumber was synced over
                $idnumber_updated = true;
                // update the PM user with the new idnumber
                $cmuser = new user();
                $cmuser->id = $um->cuserid;
                $cmuser->idnumber = $mu->idnumber;
                $cmuser->save();
                // update the association table with the new idnumber
                $um->idnumber = $mu->idnumber;
                $um->save();
            }
        }
    }
    // find the linked PM user
    //filter for the basic condition on the Moodle user id
    $condition_filter = new field_filter('id', $mu->id);
    //filter for joining the association table
    $association_filter = new join_filter('muserid', 'user', 'id', $condition_filter);
    //outermost filter
    $filter = new join_filter('id', usermoodle::TABLE, 'cuserid', $association_filter);
    $cu = user::find($filter);
    if ($cu->valid()) {
        $cu = $cu->current();
    } else {
        // if a user with the same username but different idnumber exists,
        // we can't sync over because it will violate PM user uniqueness
        // constraints
        $cu = user::find(new field_filter('username', $mu->username));
        if ($cu->valid()) {
            return true;
        }
        // if no such PM user exists, create a new one
        $cu = new user();
        $cu->transfercredits = 0;
        $cu->timecreated = time();
    }
    // synchronize standard fields
    $cu->username = $mu->username;
    $cu->password = $mu->password;
    // only need to update the idnumber if it wasn't handled above
    if (!$idnumber_updated) {
        $cu->idnumber = $mu->idnumber;
    }
    $cu->firstname = $mu->firstname;
    $cu->lastname = $mu->lastname;
    $cu->email = $mu->email;
    $cu->address = $mu->address;
    $cu->city = $mu->city;
    $cu->country = $mu->country;
    if (!empty($mu->phone1)) {
        $cu->phone = $mu->phone1;
    }
    if (!empty($mu->phone2)) {
        $cu->phone2 = $mu->phone2;
    }
    if (!empty($mu->lang)) {
        $cu->language = $mu->lang;
    }
    $cu->timemodified = time();
    // synchronize custom profile fields
    profile_load_data($mu);
    fix_moodle_profile_fields($mu);
    $fields = field::get_for_context_level(CONTEXT_ELIS_USER);
    $fields = $fields ? $fields : array();
    require_once elis::plugin_file('elisfields_moodleprofile', 'custom_fields.php');
    foreach ($fields as $field) {
        $field = new field($field);
        if (!moodle_profile_can_sync($field->shortname)) {
            continue;
        }
        if (isset($field->owners['moodle_profile']) && isset($mu->{"profile_field_{$field->shortname}"})) {
            // check if should sync user profile field settings
            if ($field->owners['moodle_profile']->exclude == pm_moodle_profile::sync_from_moodle) {
                sync_profile_field_settings_from_moodle($field);
            }
            $fieldname = "field_{$field->shortname}";
            $cu->{$fieldname} = $mu->{"profile_field_{$field->shortname}"};
        }
    }
    //specifically tell the user save not to use the local_elisprogram_usr_mdl for syncing
    //because the record hasn't been inserted yet (see below)
    try {
        $cu->save(false);
    } catch (Exception $ex) {
        if (in_cron()) {
            mtrace(get_string('record_not_created_reason', 'local_elisprogram', array('message' => $ex->getMessage() . " [{$mu->id}]")));
            return false;
        } else {
            throw new Exception($ex->getMessage());
        }
    }
    // if no user association record exists, create one
    if (!$moodle_user_exists) {
        $um = new usermoodle();
        $um->cuserid = $cu->id;
        $um->muserid = $mu->id;
        $um->idnumber = $mu->idnumber;
        $um->save();
    }
    return true;
}
示例#30
0
 public function set_from_data($data)
 {
     if (!empty($data->moodleCourses['autocreate'])) {
         $this->autocreate = $data->moodleCourses['autocreate'];
     } else {
         $this->autocreate = false;
     }
     if (isset($data->disablestart)) {
         $this->startdate = 0;
     }
     if (isset($data->disableend)) {
         $this->enddate = 0;
     }
     if (!empty($data->moodleCourses['moodlecourseid']) && !$this->autocreate) {
         $this->moodlecourseid = $data->moodleCourses['moodlecourseid'];
     } else {
         $this->moodlecourseid = 0;
     }
     if (isset($data->track)) {
         $this->track = $data->track;
     }
     $this->oldmax = $this->maxstudents;
     $fields = field::get_for_context_level('class', '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);
 }