/** * @method add_users * @todo add_users is the function to add the registrar to a school * @param array $userids user array * @param int $schoolid Schoolid */ public function add_users($userids, $schoolid) { global $CFG, $DB, $OUTPUT, $USER; $hierarchy = new hierarchy (); $currenturl = "{$CFG->wwwroot}/local/collegestructure/assignusers.php"; if (empty($userids)) { /* ---nothing to do--- */ return; } $userids = array_reverse($userids); foreach ($userids as $userid) { $registrar = new stdClass(); $registrar->userid = $userid; $registrar->schoolid = $schoolid; $getroleid = $hierarchy->get_registrar_roleid(); foreach ($getroleid as $getid) { $context = context_user::instance($userid); $systemcontext = context_system::instance(); if (has_capability('local/clclasses:approveclclasses', $context)) { $roleid = $getid->id; } elseif (has_capability('local/collegestructure:manage', $systemcontext)) { $roleid = $getid->id; } elseif (has_capability('local/clclasses:submitgrades', $systemcontext)) { $roleid = $getid->id; } elseif (!has_capability('local/clclasses:submitgrades', $systemcontext)) { $roleid = $getid->id; } elseif (!has_capability('local/clclasses:approveclclasses', $context)) { $roleid = $getid->id; } else { $roleid = $getid->id; } } $registrar->roleid = $roleid; $now = date("d-m-Y"); $registrar->timecreated = strtotime($now); $registrar->usermodified = $USER->id; $school = $DB->get_record('local_school', array('id' => $schoolid)); $checkexist = $DB->get_record('local_school_permissions', array('userid' => $userid, 'schoolid' => $schoolid)); if ($checkexist) { $hierarchy->set_confirmation(get_string('alreadyassigned', 'local_collegestructure', array('school' => $school->fullname)), $currenturl); } else { $ll = $DB->insert_record('local_school_permissions', $registrar); } if ($ll) { /* ---start of vijaya--- */ $conf = new object(); $conf->username = $DB->get_field('user', 'username', array('id' => $userid)); $conf->schoolname = $DB->get_field('local_school', 'fullname', array('id' => $schoolid)); $message = get_string('msg_add_reg_schl', 'local_collegestructure', $conf); $userfrom = $DB->get_record('user', array('id' => $USER->id)); $userto = $DB->get_record('user', array('id' => $userid)); $message_post_message = message_post_message($userfrom, $userto, $message, FORMAT_HTML); /* ---end of vijaya--- */ // $hierarchy->set_confirmation(get_string('assignedsuccess', 'local_collegestructure'), $currenturl,array('style' => 'notifysuccess')); } } if ($ll) { $hierarchy->set_confirmation(get_string('assignedsuccess', 'local_collegestructure'), $currenturl, array('style' => 'notifysuccess')); } else { $hierarchy->set_confirmation(get_string('assignedfailed', 'local_collegestructure'), $currenturl, array('style' => 'notifyproblem')); } }