Ejemplo n.º 1
0
 function do_default()
 {
     global $CFG, $DB;
     $target = $this->get_new_page(array('action' => 'default'));
     $configform = new $this->form_class($target->url);
     if ($configform->is_cancelled()) {
         $target = $this->get_new_page(array('action' => 'default'), true);
         redirect($target->url);
         return;
     }
     $configform->set_data(elis::$config->local_elisprogram);
     if ($configdata = $configform->get_data()) {
         $old_cluster_groups = elis::$config->local_elisprogram->cluster_groups;
         $old_site_course_cluster_groups = elis::$config->local_elisprogram->site_course_cluster_groups;
         $old_cluster_groupings = elis::$config->local_elisprogram->cluster_groupings;
         // Track settings
         self::config_set_value($configdata, 'userdefinedtrack', 0);
         // Course catalog / Learning plan settings
         self::config_set_value($configdata, 'disablecoursecatalog', 0);
         self::config_set_value($configdata, 'catalog_collapse_count');
         // Curriculum expiration settings (ELIS-1172)
         $curassupdate = false;
         // We need to check for an required update before setting the variable as the API call requires the
         // variable to be set before the changes can take place.
         if (isset($configdata->curriculum_expiration_start) && $configdata->curriculum_expiration_start != elis::$config->local_elisprogram->curriculum_expiration_start) {
             $curassupdate = true;
         }
         self::config_set_value($configdata, 'enable_curriculum_expiration', 0);
         self::config_set_value($configdata, 'curriculum_expiration_start', '');
         // If this setting is changed, we need to update the existing curriclum expiration values
         if ($curassupdate) {
             require_once elispm::lib('data/curriculumstudent.class.php');
             if ($rs = $DB->get_recordset(curriculumstudent::TABLE, null, '', 'id, userid, curriculumid')) {
                 $timenow = time();
                 foreach ($rs as $curass) {
                     $update = new stdClass();
                     $update->id = $curass->id;
                     $update->timeexpired = calculate_curriculum_expiry(false, $curass->curriculumid, $curass->userid);
                     $update->timemodified = $timenow;
                     $DB->update_record(curriculumstudent::TABLE, $update);
                 }
                 $rs->close();
             }
         }
         // Certificate settings
         self::config_set_value($configdata, 'disablecertificates', 0);
         self::config_set_value($configdata, 'certificate_border_image', 'Fancy1-blue.jpg');
         self::config_set_value($configdata, 'certificate_seal_image', 'none');
         self::config_set_value($configdata, 'certificate_template_file', 'default.php');
         // Interface settings
         self::config_set_value($configdata, 'time_format_12h', 0);
         self::config_set_value($configdata, 'mymoodle_redirect', 0);
         // User settings
         self::config_set_value($configdata, 'auto_assign_user_idnumber', 0);
         $old_cfg = elis::$config->local_elisprogram->auto_assign_user_idnumber;
         // if this setting is changed to true, synchronize the users
         if (isset($configdata->auto_assign_user_idnumber) && $configdata->auto_assign_user_idnumber != 0 && $old_cfg == 0) {
             //TODO: Needs to be ported to ELIS 2
             //                cm_migrate_moodle_users(true, 0);
         }
         self::config_set_value($configdata, 'default_instructor_role', 0);
         self::config_set_value($configdata, 'restrict_to_elis_enrolment_plugin', 0);
         // Cluster settings
         self::config_set_value($configdata, 'cluster_groups', 0);
         self::config_set_value($configdata, 'site_course_cluster_groups', 0);
         self::config_set_value($configdata, 'cluster_groupings', 0);
         //settings specifically for the curriculum administration block
         self::config_set_value($configdata, 'num_block_icons', 5);
         self::config_set_value($configdata, 'display_clusters_at_top_level', 1);
         self::config_set_value($configdata, 'display_curricula_at_top_level', 0);
         //default role assignments on cm entities
         self::config_set_value($configdata, 'default_cluster_role_id', 0);
         self::config_set_value($configdata, 'default_curriculum_role_id', 0);
         self::config_set_value($configdata, 'default_course_role_id', 0);
         self::config_set_value($configdata, 'default_class_role_id', 0);
         self::config_set_value($configdata, 'default_track_role_id', 0);
         // TODO: ELIS 2 port of roles
         //enrolment synchronization roles
         /*$old_role_sync = elis::$config->local_elisprogram->enrolment_role_sync_student_role;
           self::config_set_value($configdata, 'enrolment_role_sync_student_role', 0);
           if (isset($configdata->enrolment_role_sync_student_role)
               && $configdata->enrolment_role_sync_student_role != 0
               && $configdata->enrolment_role_sync_student_role != $old_role_sync) {
               require_once CURMAN_DIRLOCATION . '/plugins/enrolrolesync/lib.php';
               enrolment_role_sync::student_sync_role_set();
           }
           $old_role_sync = elis::$config->local_elisprogram->enrolment_role_sync_instructor_role;
           self::config_set_value($configdata, 'enrolment_role_sync_instructor_role', 0);
           if (isset($configdata->enrolment_role_sync_instructor_role)
               && $configdata->enrolment_role_sync_instructor_role != 0
               && $configdata->enrolment_role_sync_instructor_role != $old_role_sync) {
               require_once CURMAN_DIRLOCATION . '/plugins/enrolrolesync/lib.php';
               enrolment_role_sync::instructor_sync_role_set();
           }
           */
         // autocreate settings
         self::config_set_value($configdata, 'autocreated_unknown_is_yes', 0);
         //trigger events
         if (!empty($configdata->cluster_groups) && empty($old_cluster_groups)) {
             events_trigger('crlm_cluster_groups_enabled', 0);
         }
         if (!empty($configdata->site_course_cluster_groups) && empty($old_site_course_cluster_groups)) {
             events_trigger('crlm_site_course_cluster_groups_enabled', 0);
         }
         if (!empty($configdata->cluster_groupings) && empty($old_cluster_groupings)) {
             events_trigger('crlm_cluster_groupings_enabled', 0);
         }
     }
     //$configform->display();
     $this->display('default');
 }
Ejemplo n.º 2
0
 public function update()
 {
     $result = parent::update();
     $result = $result && field_data::set_for_context_from_datarecord('curriculum', $this);
     // If this setting is changed, we need to update the existing curriclum expiration values (ELIS-1172)
     if ($rs = get_recordset_select(CURASSTABLE, "timeexpired != 0 AND curriculumid = {$this->id}", '', 'id, userid')) {
         $timenow = time();
         while ($curass = rs_fetch_next_record($rs)) {
             $update = new stdClass();
             $update->id = $curass->id;
             $update->timeexpired = calculate_curriculum_expiry(NULL, $this->id, $curass->userid);
             $update->timemodified = $timenow;
             update_record(CURASSTABLE, $update);
         }
         rs_close($rs);
     }
     return $result;
 }
 /**
  * Perform all actions to mark this student record complete.
  *
  * @param  mixed    $time     Student's curriculum completion time (ignored if equal to FALSE)
  * @param  mixed    $credits  The number of credits awarded (ignored if false)
  * @param  boolean  $locked   TRUE if the curriculum enrolment should be locked, otherwise false
  */
 function complete($time = false, $credits = false, $locked = false)
 {
     global $CFG, $CURMAN;
     require_once CURMAN_DIRLOCATION . '/lib/notifications.php';
     $this->completed = STUSTATUS_PASSED;
     if ($time !== false) {
         $this->timecompleted = $time;
     }
     if ($this->timecompleted <= 0 || !is_numeric($this->timecompleted)) {
         $this->timecompleted = time();
     }
     // Handle a curriculum with an expiry date defined (ELIS-1172):
     if (!empty($CURMAN->config->enable_curriculum_expiration) && !empty($this->curriculum->frequency)) {
         $this->timeexpired = calculate_curriculum_expiry($this);
     }
     if ($credits !== false) {
         $this->credits = $credits;
     }
     if ($locked !== false) {
         $this->locked = $locked ? 1 : 0;
     }
     // Get the certificate code.  This batch of code tries to ensure
     // that the random string is unique trying
     if (empty($this->certificatecode)) {
         $this->certificatecode = null;
         $counter = 0;
         $attempts = 10;
         $maximumchar = 15;
         $addchar = 0;
         // This loop will try to generate a unique string 11 times.  On the 11th attempt
         // if string is still not unique then it will add to the length of the string
         // If the length of the string exceed the maximum length set by $maximumchar
         // then stop the loop and return an error
         do {
             $code = cm_certificate_generate_code($addchar);
             $exists = curriculum_code_exists($code);
             if (!$exists) {
                 $this->certificatecode = $code;
                 break;
             }
             // If the counter is equal to the number of attempts
             if ($counter == $attempts) {
                 // Set counter back to zero and add a character to the string
                 $counter = 0;
                 $addchar++;
             }
             // increment counter otherwise this is an infinite loop
             $counter++;
         } while ($maximumchar >= $addchar);
         // Check if the length has exceeded the maximum length
         if ($maximumchar < $addchar) {
             if (!cm_certificate_email_random_number_fail($this)) {
                 $message = get_string('certificate_email_fail', 'block_curr_admin');
                 notify($message);
             }
             print_error('certificate_code_error', 'block_curr_admin');
         }
     }
     if ($this->update()) {
         /// Does the user receive a notification?
         $sendtouser = $CURMAN->config->notify_curriculumcompleted_user;
         $sendtorole = $CURMAN->config->notify_curriculumcompleted_role;
         $sendtosupervisor = $CURMAN->config->notify_curriculumcompleted_supervisor;
         /// If nobody receives a notification, we're done.
         if (!$sendtouser && !$sendtorole && !$sendtosupervisor) {
             return true;
         }
         $context = get_system_context();
         /// Make sure this is a valid user.
         $enroluser = new user($this->userid);
         if (empty($enroluser->id)) {
             print_error('nouser', 'block_curr_admin');
             return true;
         }
         $message = new notification();
         /// Set up the text of the message
         $text = empty($CURMAN->config->notify_curriculumcompleted_message) ? get_string('notifycurriculumcompletedmessagedef', 'block_curr_admin') : $CURMAN->config->notify_curriculumcompleted_message;
         $search = array('%%userenrolname%%', '%%curriculumname%%');
         $replace = array(fullname($this->user), $this->curriculum->name);
         $text = str_replace($search, $replace, $text);
         $eventlog = new Object();
         $eventlog->event = 'curriculum_completed';
         $eventlog->instance = $this->id;
         /// Store the assignment id.
         if ($sendtouser) {
             //todo: figure out why a log object is passed in here
             $message->send_notification($text, $this->user, null, $eventlog);
         }
         $users = array();
         if ($sendtorole) {
             /// Get all users with the notify_classenrol capability.
             if ($roleusers = get_users_by_capability($context, 'block/curr_admin:notify_curriculumcomplete')) {
                 $users = $users + $roleusers;
             }
         }
         if ($sendtosupervisor) {
             /// Get parent-context users.
             if ($supervisors = cm_get_users_by_capability('user', $this->userid, 'block/curr_admin:notify_curriculumcomplete')) {
                 $users = $users + $supervisors;
             }
         }
         foreach ($users as $user) {
             $message->send_notification($text, $user, $enroluser);
         }
     }
 }
Ejemplo n.º 4
0
 public function save()
 {
     $isnew = empty($this->id);
     $now = time();
     if ($isnew) {
         $this->timecreated = $now;
         if (!empty(elis::$config->local_elisprogram->enable_curriculum_expiration) && elis::$config->local_elisprogram->curriculum_expiration_start == CURR_EXPIRE_ENROL_START && $this->_db->get_field(curriculum::TABLE, 'frequency', array('id' => $this->curriculumid))) {
             // We need to load this record from the DB fresh so we don't accidentally overwrite legitimate
             // values with something empty when we update the record.
             $this->timecreated = time();
             $timeexpired = calculate_curriculum_expiry($this);
             if ($timeexpired > 0) {
                 $this->timeexpired = $timeexpired;
             }
         }
     }
     $this->timemodified = $now;
     parent::save();
 }
Ejemplo n.º 5
0
 function action_default()
 {
     global $CFG, $CURMAN;
     require_once $CFG->dirroot . '/curriculum/form/configform.class.php';
     $configform = new cmconfigform('index.php', $this);
     $configform->set_data($CURMAN->config);
     if ($configdata = $configform->get_data()) {
         $old_cluster_groups = $CURMAN->config->cluster_groups;
         $old_site_course_cluster_groups = $CURMAN->config->site_course_cluster_groups;
         $old_cluster_groupings = $CURMAN->config->cluster_groupings;
         // Track settings
         self::config_set_value($configdata, 'userdefinedtrack', 0);
         // Course catalog / Learning plan settings
         self::config_set_value($configdata, 'disablecoursecatalog', 0);
         self::config_set_value($configdata, 'catalog_collapse_count');
         // Curriculum expiration settings (ELIS-1172)
         $curassupdate = false;
         // We need to check for an required update before setting the variable as the API call requires the
         // variable to be set before the changes can take place.
         if (isset($configdata->curriculum_expiration_start) && $configdata->curriculum_expiration_start != $CURMAN->config->curriculum_expiration_start) {
             $curassupdate = true;
         }
         self::config_set_value($configdata, 'enable_curriculum_expiration', 0);
         self::config_set_value($configdata, 'curriculum_expiration_start', '');
         // If this setting is changed, we need to update the existing curriclum expiration values
         if ($curassupdate) {
             if ($rs = get_recordset(CURASSTABLE, '', '', '', 'id, userid, curriculumid')) {
                 $timenow = time();
                 while ($curass = rs_fetch_next_record($rs)) {
                     $update = new stdClass();
                     $update->id = $curass->id;
                     $update->timeexpired = calculate_curriculum_expiry(false, $curass->curriculumid, $curass->userid);
                     $update->timemodified = $timenow;
                     update_record(CURASSTABLE, $update);
                 }
                 rs_close($rs);
             }
         }
         // Certificate settings
         self::config_set_value($configdata, 'disablecertificates', 0);
         self::config_set_value($configdata, 'certificate_border_image', 'Fancy1-blue.jpg');
         self::config_set_value($configdata, 'certificate_seal_image', 'none');
         self::config_set_value($configdata, 'certificate_template_file', 'default.php');
         // Interface settings
         self::config_set_value($configdata, 'time_format_12h', 0);
         self::config_set_value($configdata, 'mymoodle_redirect', 0);
         // User settings
         self::config_set_value($configdata, 'auto_assign_user_idnumber', 0);
         $old_cfg = $CURMAN->config->auto_assign_user_idnumber;
         // if this setting is changed to true, synchronize the users
         if (isset($configdata->auto_assign_user_idnumber) && $configdata->auto_assign_user_idnumber != 0 && $old_cfg == 0) {
             cm_migrate_moodle_users(true, 0);
         }
         self::config_set_value($configdata, 'default_instructor_role', 0);
         self::config_set_value($configdata, 'restrict_to_elis_enrolment_plugin', 0);
         // Cluster settings
         self::config_set_value($configdata, 'cluster_groups', 0);
         self::config_set_value($configdata, 'site_course_cluster_groups', 0);
         self::config_set_value($configdata, 'cluster_groupings', 0);
         //settings specifically for the curriculum administration block
         self::config_set_value($configdata, 'num_block_icons', 5);
         self::config_set_value($configdata, 'display_clusters_at_top_level', 1);
         self::config_set_value($configdata, 'display_curricula_at_top_level', 0);
         //default role assignments on cm entities
         self::config_set_value($configdata, 'default_cluster_role_id', 0);
         self::config_set_value($configdata, 'default_curriculum_role_id', 0);
         self::config_set_value($configdata, 'default_course_role_id', 0);
         self::config_set_value($configdata, 'default_class_role_id', 0);
         self::config_set_value($configdata, 'default_track_role_id', 0);
         //enrolment synchronization roles
         $old_role_sync = $CURMAN->config->enrolment_role_sync_student_role;
         self::config_set_value($configdata, 'enrolment_role_sync_student_role', 0);
         if (isset($configdata->enrolment_role_sync_student_role) && $configdata->enrolment_role_sync_student_role != 0 && $configdata->enrolment_role_sync_student_role != $old_role_sync) {
             require_once CURMAN_DIRLOCATION . '/plugins/enrolment_role_sync/lib.php';
             enrolment_role_sync::student_sync_role_set();
         }
         $old_role_sync = $CURMAN->config->enrolment_role_sync_instructor_role;
         self::config_set_value($configdata, 'enrolment_role_sync_instructor_role', 0);
         if (isset($configdata->enrolment_role_sync_instructor_role) && $configdata->enrolment_role_sync_instructor_role != 0 && $configdata->enrolment_role_sync_instructor_role != $old_role_sync) {
             require_once CURMAN_DIRLOCATION . '/plugins/enrolment_role_sync/lib.php';
             enrolment_role_sync::instructor_sync_role_set();
         }
         // autocreate settings
         self::config_set_value($configdata, 'autocreated_unknown_is_yes', 0);
         // legacy settings
         self::config_set_value($configdata, 'legacy_show_inactive_users', 0);
         //trigger events
         if (!empty($configdata->cluster_groups) && empty($old_cluster_groups)) {
             events_trigger('crlm_cluster_groups_enabled', 0);
         }
         if (!empty($configdata->site_course_cluster_groups) && empty($old_site_course_cluster_groups)) {
             events_trigger('crlm_site_course_cluster_groups_enabled', 0);
         }
         if (!empty($configdata->cluster_groupings) && empty($old_cluster_groupings)) {
             events_trigger('crlm_cluster_groupings_enabled', 0);
         }
     }
     $configform->display();
 }
Ejemplo n.º 6
0
 public function save()
 {
     $isnew = empty($this->id);
     parent::save();
     if (!$isnew) {
         // If this setting is changed, we need to update the existing curriclum expiration values (ELIS-1172)
         if ($rs = $this->_db->get_recordset_select(curriculumstudent::TABLE, "timecompleted = 0 AND curriculumid = {$this->id}", null, 'id, userid')) {
             $timenow = time();
             foreach ($rs as $rec) {
                 $update = new stdClass();
                 $update->id = $rec->id;
                 $update->timeexpired = calculate_curriculum_expiry(NULL, $this->id, $rec->userid);
                 $update->timemodified = $timenow;
                 $this->_db->update_record(curriculumstudent::TABLE, $update);
             }
             $rs->close();
         }
     }
     field_data::set_for_context_from_datarecord(CONTEXT_ELIS_PROGRAM, $this);
 }