当前位置: 首页>>代码示例>>PHP>>正文


PHP cohort_add_member函数代码示例

本文整理汇总了PHP中cohort_add_member函数的典型用法代码示例。如果您正苦于以下问题:PHP cohort_add_member函数的具体用法?PHP cohort_add_member怎么用?PHP cohort_add_member使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cohort_add_member函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: add_member

 /**
  * Add a member to the cohort if they are not alread in the cohort
  *
  * @param int $userid id from user table of user
  * @return void
  */
 public function add_member($userid)
 {
     if (!isset($this->members[$userid])) {
         cohort_add_member($this->cohort->id, $userid);
         $this->members[$userid] = $userid;
     }
 }
开发者ID:albertolarah,项目名称:moodle-local_dev,代码行数:13,代码来源:sync-cohorts.php

示例2: execute

 public function execute()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/cohort/lib.php';
     require_once $CFG->dirroot . '/enrol/cohort/locallib.php';
     foreach ($this->arguments as $argument) {
         $this->expandOptionsManually(array($argument));
         $options = $this->expandedOptions;
         // Sanity Checks.
         // Check if cohorst exists.
         if (!($cohorts = $DB->get_records('cohort', array('name' => $argument)))) {
             echo "Cohort does not exist\n";
             exit(0);
         }
         // Check if enough arguments.
         if (empty($options['courseid']) && empty($options['userid'])) {
             echo "Not enough arguments, provide userid or courseid\n";
         }
         // Check if course exists.
         $course = '';
         if (!empty($options['courseid'])) {
             if (!($course = $DB->get_record('course', array('id' => $options['courseid'])))) {
                 echo "Course does not exist\n";
                 exit(0);
             }
         }
         // Check if user exists.
         if (!empty($options['userid'])) {
             if (!($user = $DB->get_record('user', array('id' => $options['userid'])))) {
                 echo "User does not exist\n";
                 exit(0);
             }
         }
         // Add cohort to course
         if (!empty($course)) {
             foreach ($cohorts as $cohort) {
                 // Check if cohort enrolment already exists
                 if ($cohortenrolment = $DB->get_record('enrol', array('customint1' => $cohort->id, 'courseid' => $options['courseid']))) {
                     echo " Notice: Cohort already enrolled into course\n";
                 } else {
                     $enrol = enrol_get_plugin('cohort');
                     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
                     $enrol->add_instance($course, array('name' => $argument . '_sync', 'status' => 0, 'customint1' => $cohort->id, 'roleid' => $studentrole->id, 'customint2' => '0'));
                     echo "Cohort enrolled\n";
                 }
                 $this->enrol_cohort_sync($course->id);
             }
         }
         if (!empty($user)) {
             foreach ($cohorts as $cohort) {
                 cohort_add_member($cohort->id, $options['userid']);
                 echo "User enrolled\n";
                 if (!empty($course)) {
                     $this->enrol_cohort_sync($course->id);
                 }
             }
         }
     }
 }
开发者ID:dariogs,项目名称:moosh,代码行数:59,代码来源:CohortEnrol.php

示例3: test_report

 /**
  * @runInSeparateProcess
  */
 public function test_report()
 {
     $this->resetAfterTest(true);
     $user = $this->getDataGenerator()->create_user();
     $this->adduser($user->id);
     $this->setUser($user);
     $course = $this->getDataGenerator()->create_course();
     $cohort = $this->getDataGenerator()->create_cohort(array('idnumber' => 1234.56789));
     cohort_add_member($cohort->id, $user->id);
     G\addtermid('1234');
     $this->enroluserincourse($course, $cohort, 'teacher');
     $user2 = $this->getDataGenerator()->create_user();
     $this->adduser($user2->id);
     $user3 = $this->getDataGenerator()->create_user();
     $this->adduser($user3->id);
     $user4 = $this->getDataGenerator()->create_user();
     $this->adduser($user4->id);
     $cohort2 = $this->getDataGenerator()->create_cohort(array('idnumber' => 9876.54321));
     cohort_add_member($cohort2->id, $user2->id);
     cohort_add_member($cohort2->id, $user3->id);
     cohort_add_member($cohort2->id, $user4->id);
     G\addtermid('9876');
     $this->enroluserincourse($course, $cohort2, 'student');
     $year = date("Y");
     $sem = G\semOfDate(date("d"), date("m"));
     G\newassessment($user3->id, time(), 121, $sem, "Student");
     $students = G\studentsofcourse($course->id);
     $numofstudents = count($students);
     $numofstudentsdoneassessment = 0;
     if (count($students) > 0) {
         foreach ($students as $studentid) {
             if (G\doneassessment($studentid, $sem, $year)) {
                 $numofstudentsdoneassessment++;
             }
         }
     }
     $this->assertEquals(3, $numofstudents);
     $this->assertEquals(1, $numofstudentsdoneassessment);
 }
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:42,代码来源:gas_report_Test.php

示例4: test_student_courses

 /**
  * @runInSeparateProcess
  */
 public function test_student_courses()
 {
     $this->resetAfterTest(true);
     $user = $this->getDataGenerator()->create_user();
     $row = array();
     $row['user_id'] = $user->id;
     $row['email'] = null;
     $row['timestamp'] = time();
     G\addvaliduser($row);
     $this->setUser($user);
     $course = $this->getDataGenerator()->create_course();
     $cohort = $this->getDataGenerator()->create_cohort(array('idnumber' => 1234.56789));
     cohort_add_member($cohort->id, $user->id);
     G\addtermid('1234');
     $enrol = enrol_get_plugin('cohort');
     $instance = array();
     $instance['name'] = 'name';
     $instance['status'] = ENROL_INSTANCE_ENABLED;
     // Enable it.
     $instance['customint1'] = $cohort->id;
     // Used to store the cohort id.
     $instance['roleid'] = $enrol->get_config('roleid');
     // Default role for cohort enrol which is usually student.
     $instance['customint2'] = 0;
     // Optional group id.
     $enrol->add_instance($course, $instance);
     $trace = new null_progress_trace();
     enrol_cohort_sync($trace, $course->id);
     $trace->finished();
     $courses = G\coursesas($user->id, 'student');
     $courseids = array();
     foreach ($courses as $newcourse) {
         array_push($courseids, $newcourse->id);
     }
     $this->assertContains($course->id, $courseids);
 }
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:39,代码来源:gas_student_Test.php

示例5: __CreateUser

 public function __CreateUser($username, $password, $firstname, $lastname, $email, $city, $country, $store, $retailer, $lang, $regionkey, $jobtitle, $insertflag, $other)
 {
     global $CFG, $DB;
     $systemcontext = context_system::instance();
     require_once $CFG->dirroot . '/cohort/locallib.php';
     // cohort members added courses.
     $response = new CliniqueServiceResponce();
     $flag = true;
     $popupflag = true;
     $user_exits = array_values($DB->get_records_sql("SELECT count(*) as totaluser FROM {user} WHERE username='{$username}'"));
     $user_email_exists = array_values($DB->get_records_sql("SELECT count(*) as totalemail FROM {user} WHERE email='{$email}'"));
     $regionkey_check = array_values($DB->get_records_sql("SELECT count(*) as Regkeyexists FROM {regionkey} WHERE regionkey='{$regionkey}' AND region='{$city}'"));
     $userDetails = new stdClass();
     // $password = "UGhvdG9uQDEyMw==";
     if ($user_exits[0]->totaluser > 0) {
         $response->response(true, 'msg', "username_exists");
         $flag = false;
         $popupflag = false;
         exit;
     }
     /*if($user_email_exists[0]->totalemail > 0){
     
                      $response->response(true, 'msg', "email_exists");
     				 $flag=false;
     				 $popupflag = false;
     				 exit;
     
     			}*/
     if ($regionkey_check['0']->regkeyexists == 0) {
         $response->response(true, 'msg', "regionkey_not_exists");
         $flag = false;
         $popupflag = false;
         exit;
     }
     if ($popupflag && $insertflag == 'false') {
         $response->response(false, 'msg', "show_popup");
         $flag = false;
         exit;
     }
     if ($flag && $insertflag == 'true') {
         $userDetails->auth = 'email';
         $userDetails->confirmed = '1';
         $userDetails->mnethostid = '1';
         $userDetails->descriptionformat = '1';
         $userDetails->descriptionformat = '1';
         $userDetails->username = $username;
         $password = base64_decode($password);
         $md5pass_val = array("id" => "md5");
         if (!empty($CFG->passwordsaltmain)) {
             $newpass = $password . $CFG->passwordsaltmain;
             $user_pass = array_values($DB->get_records_all_sql("SELECT md5('{$newpass}') as password", $md5pass_val));
             $userDetails->password = $user_pass[0]->password;
         } else {
             $userDetails->password = md5($password);
         }
         $userDetails->firstname = $firstname;
         $userDetails->lastname = $lastname;
         $userDetails->email = $email;
         $userDetails->city = $city;
         $userDetails->country = $country;
         if ($lang == 'zh_ct') {
             $userDetails->lang = 'zh_cn';
         } else {
             $userDetails->lang = $lang;
         }
         $userDetails->timecreated = time();
         $userDetails->timemodified = time();
         //$userDetails->store=$store;
         //$userDetails->retailer=$retailer;
         $userDetails->descriptionformat = '1';
         $lastinsertid = $DB->insert_record('user', $userDetails);
         $cohortid = array_values($DB->get_records_sql("SELECT id FROM {cohort} WHERE idnumber='{$lang}'"));
         $cohortDetails = new stdClass();
         $cohortDetails->cohortid = $cohortid[0]->id;
         $cohortDetails->userid = $lastinsertid;
         $cohortDetails->timeadded = time();
         // if($userDetails->lang == COUNTER_MANAGER_ISO) {
         // cohort_add_member(US_ENGLISH, $lastinsertid);
         // }
         cohort_add_member($cohortid[0]->id, $lastinsertid);
         //$DB->insert_record('cohort_members',$cohortDetails);
         if ($other) {
             $cascade_data = new stdClass();
             $get_country = $DB->get_record('country', array('country_code' => $country));
             $cascade_data->region = $city;
             $cascade_data->country = $get_country->country_name;
             $cascade_data->retailer = $retailer;
             $cascade_data->store = $store;
             $cascade_insert_id = $DB->insert_record('cascade_region', $cascade_data);
         }
         if ($store != '' && !empty($store)) {
             $storeId = array_values($DB->get_records_sql("SELECT id FROM {user_info_field} WHERE shortname='Store'"));
             //Store,
             $user_info_data->fieldid = $storeId['0']->id;
             $user_info_data->userid = $lastinsertid;
             $user_info_data->data = $store;
             $DB->insert_record('user_info_data', $user_info_data);
         }
         if ($retailer != '' && !empty($retailer)) {
             //Retailer
//.........这里部分代码省略.........
开发者ID:vinoth4891,项目名称:clinique,代码行数:101,代码来源:clinique_users.php

示例6: process_cohort_membership_node

 private function process_cohort_membership_node($membershipnode, $xpath, $subtractive = 0)
 {
     global $DB, $CFG;
     $members = $xpath->evaluate("member", $membershipnode);
     $idnumber = $xpath->evaluate("sourcedid/id", $membershipnode)->item(0);
     if ($idnumber) {
         $ship = new stdClass();
         $ship->coursecode = $idnumber->nodeValue;
         if ($ship->courseid = $DB->get_field('cohort', 'id', array('idnumber' => $ship->coursecode))) {
             $cohortrec = $DB->get_fieldset_select('cohort_members', 'userid', 'cohortid=' . $ship->courseid);
             $curlist = array_flip($cohortrec);
             foreach ($members as $mmember) {
                 $midnumber = new stdClass();
                 $midnumber = $xpath->evaluate("sourcedid/id", $mmember)->item(0);
                 if ($midnumber) {
                     $member = new stdClass();
                     $member->idnumber = $midnumber->nodeValue;
                     $userid = $DB->get_field('user', 'id', array('idnumber' => $member->idnumber));
                     $latestlist[$userid] = $userid;
                     if (!isset($curlist[$userid])) {
                         if ($userid != 0 && $userid != '') {
                             cohort_add_member($ship->courseid, $userid);
                         }
                     }
                 }
             }
             if ($subtractive == 1) {
                 foreach ($cohortrec as $curmember) {
                     if (!isset($latestlist[$curmember])) {
                         cohort_remove_member($ship->courseid, $curmember);
                     }
                 }
             }
         }
     }
 }
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:36,代码来源:lib.php

示例7: test_cohort_get_available_cohorts

 public function test_cohort_get_available_cohorts()
 {
     global $DB;
     $this->resetAfterTest();
     $category1 = $this->getDataGenerator()->create_category();
     $category2 = $this->getDataGenerator()->create_category();
     $course1 = $this->getDataGenerator()->create_course(array('category' => $category1->id));
     $course2 = $this->getDataGenerator()->create_course(array('category' => $category2->id));
     $category1ctx = context_coursecat::instance($category1->id);
     $category2ctx = context_coursecat::instance($category2->id);
     $course1ctx = context_course::instance($course1->id);
     $course2ctx = context_course::instance($course2->id);
     $systemctx = context_system::instance();
     $cohort1 = $this->getDataGenerator()->create_cohort(array('contextid' => $category1ctx->id, 'name' => 'aaagrrryyy', 'idnumber' => '', 'description' => ''));
     $cohort2 = $this->getDataGenerator()->create_cohort(array('contextid' => $category1ctx->id, 'name' => 'bbb', 'idnumber' => '', 'description' => 'yyybrrr', 'visible' => 0));
     $cohort3 = $this->getDataGenerator()->create_cohort(array('contextid' => $category2ctx->id, 'name' => 'ccc', 'idnumber' => 'xxarrrghyyy', 'description' => 'po_us'));
     $cohort4 = $this->getDataGenerator()->create_cohort(array('contextid' => $systemctx->id, 'name' => 'ddd'));
     $cohort5 = $this->getDataGenerator()->create_cohort(array('contextid' => $systemctx->id, 'visible' => 0, 'name' => 'eee'));
     /*
     Structure of generated course categories, courses and cohort:
     
     system
       -cohort4 (visible, has 3 members)
       -cohort5 (not visible, no members)
       category1
         -cohort1 (visible, no members)
         -cohort2 (not visible, has 1 member)
         course1
       category2
         -cohort3 (visible, has 2 member)
         course2
     
     In this test we call cohort_get_available_cohorts() for users with different roles
     and with different paramteres ($withmembers, $search, $offset, $limit) to make sure we go
     through all possible options of SQL query.
     */
     // Admin can see visible and invisible cohorts defined in above contexts.
     $this->setAdminUser();
     $result = cohort_get_available_cohorts($course1ctx, COHORT_ALL, 0, 0, '');
     $this->assertEquals(array($cohort1->id, $cohort2->id, $cohort4->id, $cohort5->id), array_keys($result));
     $result = cohort_get_available_cohorts($course1ctx, COHORT_ALL, 0, 2, '');
     $this->assertEquals(array($cohort1->id, $cohort2->id), array_keys($result));
     $result = cohort_get_available_cohorts($course1ctx, COHORT_ALL, 1, 2, '');
     $this->assertEquals(array($cohort2->id, $cohort4->id), array_keys($result));
     $result = cohort_get_available_cohorts($course1ctx, COHORT_ALL, 0, 100, 'yyy');
     $this->assertEquals(array($cohort1->id, $cohort2->id), array_keys($result));
     $result = cohort_get_available_cohorts($course2ctx, COHORT_ALL, 0, 0, '');
     $this->assertEquals(array($cohort3->id, $cohort4->id, $cohort5->id), array_keys($result));
     $result = cohort_get_available_cohorts($course1ctx, COHORT_WITH_MEMBERS_ONLY);
     $this->assertEmpty($result);
     $result = cohort_get_available_cohorts($course2ctx, COHORT_WITH_MEMBERS_ONLY);
     $this->assertEmpty($result);
     // Get list of available cohorts as a teacher in the course.
     $user1 = $this->getDataGenerator()->create_user();
     $teacherrole = $DB->get_record('role', array('shortname' => 'editingteacher'));
     role_assign($teacherrole->id, $user1->id, $course1ctx->id);
     role_assign($teacherrole->id, $user1->id, $course2ctx->id);
     $this->setUser($user1);
     $result = cohort_get_available_cohorts($course1ctx, COHORT_ALL, 0, 0, '');
     $this->assertEquals(array($cohort1->id, $cohort4->id), array_keys($result));
     $result = cohort_get_available_cohorts($course1ctx, COHORT_ALL, 0, 1, '');
     $this->assertEquals(array($cohort1->id), array_keys($result));
     $result = cohort_get_available_cohorts($course1ctx, COHORT_ALL, 1, 1, '');
     $this->assertEquals(array($cohort4->id), array_keys($result));
     $result = cohort_get_available_cohorts($course1ctx, COHORT_ALL, 0, 100, 'yyy');
     $this->assertEquals(array($cohort1->id), array_keys($result));
     $result = cohort_get_available_cohorts($course2ctx, COHORT_ALL, 0, 0, '');
     $this->assertEquals(array($cohort3->id, $cohort4->id), array_keys($result));
     $result = cohort_get_available_cohorts($course1ctx, COHORT_WITH_MEMBERS_ONLY);
     $this->assertEmpty($result);
     // Now add members to cohorts.
     $user2 = $this->getDataGenerator()->create_user();
     $user3 = $this->getDataGenerator()->create_user();
     $user4 = $this->getDataGenerator()->create_user();
     $user5 = $this->getDataGenerator()->create_user();
     $user6 = $this->getDataGenerator()->create_user();
     cohort_add_member($cohort2->id, $user3->id);
     cohort_add_member($cohort3->id, $user2->id);
     cohort_add_member($cohort3->id, $user3->id);
     cohort_add_member($cohort4->id, $user4->id);
     cohort_add_member($cohort4->id, $user5->id);
     cohort_add_member($cohort4->id, $user6->id);
     // Check filtering non-empty cohorts as admin.
     $this->setAdminUser();
     $result = cohort_get_available_cohorts($course1ctx, COHORT_WITH_MEMBERS_ONLY, 0, 0, '');
     $this->assertEquals(array($cohort2->id, $cohort4->id), array_keys($result));
     $this->assertEquals(1, $result[$cohort2->id]->memberscnt);
     $this->assertEquals(3, $result[$cohort4->id]->memberscnt);
     $result = cohort_get_available_cohorts($course2ctx, COHORT_WITH_MEMBERS_ONLY, 0, 0, '');
     $this->assertEquals(array($cohort3->id, $cohort4->id), array_keys($result));
     $this->assertEquals(2, $result[$cohort3->id]->memberscnt);
     $this->assertEquals(3, $result[$cohort4->id]->memberscnt);
     $result = cohort_get_available_cohorts($course1ctx, COHORT_WITH_MEMBERS_ONLY, 0, 0, 'yyy');
     $this->assertEquals(array($cohort2->id), array_keys($result));
     $this->assertEquals(1, $result[$cohort2->id]->memberscnt);
     // Check filtering non-empty cohorts as teacher.
     $this->setUser($user1);
     $result = cohort_get_available_cohorts($course1ctx, COHORT_WITH_MEMBERS_ONLY, 0, 0, '');
     $this->assertEquals(array($cohort4->id), array_keys($result));
     $this->assertEquals(3, $result[$cohort4->id]->memberscnt);
//.........这里部分代码省略.........
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:cohortlib_test.php

示例8: sync_users


//.........这里部分代码省略.........
             //No anon
             print "Skipping anon user - uid {$drupal_user->uid}\n";
             continue;
         }
         print_string('auth_drupalservicesupdateuser', 'auth_drupalservices', array($drupal_user->name . '(' . $drupal_user->uid . ')'));
         $user = $this->create_update_user($drupal_user);
         if (empty($user)) {
             // Something went wrong while creating the user
             print_error('auth_drupalservicescreateaccount', 'auth_drupalservices', array($drupal_user->name));
             continue;
             //Next user
         }
     }
     // now that all the latest updates have been imported, store the revision point we are at.
     set_config('last_vid', $drupal_user->vid, 'auth_drupalservices');
     // Now do cohorts
     if ($this->config->cohorts != 0) {
         $cohort_view = $this->config->cohort_view;
         print "Updating cohorts using services view - {$cohort_view}\n";
         $context = context_system::instance();
         //$processed_cohorts_list = array();
         $drupal_cohorts = $apiObj->Index($cohort_view);
         if (is_null($drupal_cohorts)) {
             print "ERROR: Error retreiving cohorts!\n";
         } else {
             // OK First lets create any Moodle cohorts that are in drupal.
             foreach ($drupal_cohorts as $drupal_cohort) {
                 if ($drupal_cohort->cohort_name == '') {
                     continue;
                     // We don't want an empty cohort name
                 }
                 $drupal_cohort_list[] = $drupal_cohort->cohort_name;
                 if (!$this->cohort_exists($drupal_cohort->cohort_name)) {
                     $newcohort = new stdClass();
                     $newcohort->name = $drupal_cohort->cohort_name;
                     $newcohort->idnumber = $drupal_cohort->cohort_id;
                     $newcohort->description = $drupal_cohort->cohort_description;
                     $newcohort->contextid = $context->id;
                     $newcohort->component = 'auth_drupalservices';
                     $cid = cohort_add_cohort($newcohort);
                     print "Cohort {$drupal_cohort->cohort_name} ({$cid}) created!\n";
                 }
             }
             // Next lets delete any Moodle cohorts that are not in drupal.
             // Now create a unique array
             $drupal_cohort_list = array_unique($drupal_cohort_list);
             //print_r($drupal_cohort_list);
             $moodle_cohorts = $this->moodle_cohorts();
             //print_r($moodle_cohorts);
             foreach ($moodle_cohorts as $moodle_cohort) {
                 if (array_search($moodle_cohort->name, $drupal_cohort_list) === false) {
                     print "{$moodle_cohort->name} not in drupal - deleteing\n";
                     cohort_delete_cohort($moodle_cohort);
                 }
                 $moodle_cohorts_list[$moodle_cohort->id] = $moodle_cohort->name;
             }
             // Cool. Now lets go through each user and add them to cohorts.
             // arrays to use? $userlist - list of uids.
             // $drupal_cohorts - view. $drupal_cohorts_list. Moodle lists.
             foreach ($userlist as $uid) {
                 $drupal_user_cohort_list = array();
                 //print "$uid\n";
                 $user = $DB->get_record('user', array('idnumber' => $uid, 'mnethostid' => $CFG->mnet_localhost_id));
                 // Get array of cohort names this user belongs to.
                 $drupal_user_cohorts = $this->drupal_user_cohorts($uid, $drupal_cohorts);
                 foreach ($drupal_user_cohorts as $drupal_user_cohort) {
                     //get the cohort id frm the moodle list.
                     $cid = array_search($drupal_user_cohort->cohort_name, $moodle_cohorts_list);
                     //print "$cid\n";
                     if (!$DB->record_exists('cohort_members', array('cohortid' => $cid, 'userid' => $user->id))) {
                         cohort_add_member($cid, $user->id);
                         print "Added {$user->username} ({$user->id}) to cohort {$drupal_user_cohort->cohort_name}\n";
                     }
                     // Create a list of enrolled cohorts to use later.
                     $drupal_user_cohort_list[] = $cid;
                 }
                 // Cool. now get this users list of moodle cohorts and compare
                 // with drupal. remove from moodle if needed.
                 $moodle_user_cohorts = $this->moodle_user_cohorts($user);
                 //print_r($moodle_user_cohorts);
                 foreach ($moodle_user_cohorts as $moodle_user_cohort) {
                     if (array_search($moodle_user_cohort->cid, $drupal_user_cohort_list) === false) {
                         cohort_remove_member($moodle_user_cohort->cid, $user->id);
                         print "Removed {$user->username} ({$user->id}) from cohort {$moodle_user_cohort->name}\n";
                     }
                 }
             }
         }
     }
     // End of cohorts
     //LOGOUT
     if (get_config('auth_drupalservices', 'call_logout_service')) {
         $ret = $apiObj->Logout();
         if (is_null($ret)) {
             print "ERROR logging out!\n";
         } else {
             print "Logged out from drupal services\n";
         }
     }
 }
开发者ID:kiklop74,项目名称:moodle-drupalservices,代码行数:101,代码来源:auth.php

示例9: fullname

    $user->fullname = fullname($user, true);
    $user->country = @$countries[$user->country];
    unset($user->firstname);
    unset($user->lastname);
    $users[$key] = $user;
}
unset($countries);
$mform = new user_bulk_cohortadd_form(null, $cohorts);
if (empty($users) or $mform->is_cancelled()) {
    redirect(new moodle_url('/admin/user/user_bulk.php'));
} else {
    if ($data = $mform->get_data()) {
        // process request
        foreach ($users as $user) {
            if (!$DB->record_exists('cohort_members', array('cohortid' => $data->cohort, 'userid' => $user->id))) {
                cohort_add_member($data->cohort, $user->id);
            }
        }
        redirect(new moodle_url('/admin/user/user_bulk.php'));
    }
}
// Need to sort by date
function sort_compare($a, $b)
{
    global $sort, $dir;
    if ($sort == 'lastaccess') {
        $rez = $b->lastaccess - $a->lastaccess;
    } else {
        $rez = strcasecmp(@$a->{$sort}, @$b->{$sort});
    }
    return $dir == 'desc' ? -$rez : $rez;
开发者ID:gabrielrosset,项目名称:moodle,代码行数:31,代码来源:user_bulk_cohortadd.php

示例10: add_cohort_member

 function add_cohort_member($username, $cohort_id)
 {
     global $CFG, $DB;
     $username = utf8_decode($username);
     $username = strtolower($username);
     $conditions = array('username' => $username);
     $user = $DB->get_record('user', $conditions);
     if (!$user) {
         return 0;
     }
     $conditions = array('userid' => $user->id, 'cohortid' => $cohort_id);
     $member = $DB->get_record('cohort_members', $conditions);
     if ($member) {
         return 0;
     }
     cohort_add_member($cohort_id, $user->id);
     return 1;
 }
开发者ID:anawu2006,项目名称:PeerLearning,代码行数:18,代码来源:auth.php

示例11: test_show_enrolme_link


//.........这里部分代码省略.........
     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
     $this->assertNotEmpty($studentrole);
     $course1 = $this->getDataGenerator()->create_course();
     $course2 = $this->getDataGenerator()->create_course();
     $course3 = $this->getDataGenerator()->create_course();
     $course4 = $this->getDataGenerator()->create_course();
     $course5 = $this->getDataGenerator()->create_course();
     $course6 = $this->getDataGenerator()->create_course();
     $course7 = $this->getDataGenerator()->create_course();
     $course8 = $this->getDataGenerator()->create_course();
     $course9 = $this->getDataGenerator()->create_course();
     $course10 = $this->getDataGenerator()->create_course();
     $course11 = $this->getDataGenerator()->create_course();
     $cohort1 = $this->getDataGenerator()->create_cohort();
     $cohort2 = $this->getDataGenerator()->create_cohort();
     // New enrolments are allowed and enrolment instance is enabled.
     $instance1 = $DB->get_record('enrol', array('courseid' => $course1->id, 'enrol' => 'self'), '*', MUST_EXIST);
     $instance1->customint6 = 1;
     $DB->update_record('enrol', $instance1);
     $selfplugin->update_status($instance1, ENROL_INSTANCE_ENABLED);
     // New enrolments are not allowed, but enrolment instance is enabled.
     $instance2 = $DB->get_record('enrol', array('courseid' => $course2->id, 'enrol' => 'self'), '*', MUST_EXIST);
     $instance2->customint6 = 0;
     $DB->update_record('enrol', $instance2);
     $selfplugin->update_status($instance2, ENROL_INSTANCE_ENABLED);
     // New enrolments are allowed , but enrolment instance is disabled.
     $instance3 = $DB->get_record('enrol', array('courseid' => $course3->id, 'enrol' => 'self'), '*', MUST_EXIST);
     $instance3->customint6 = 1;
     $DB->update_record('enrol', $instance3);
     $selfplugin->update_status($instance3, ENROL_INSTANCE_DISABLED);
     // New enrolments are not allowed and enrolment instance is disabled.
     $instance4 = $DB->get_record('enrol', array('courseid' => $course4->id, 'enrol' => 'self'), '*', MUST_EXIST);
     $instance4->customint6 = 0;
     $DB->update_record('enrol', $instance4);
     $selfplugin->update_status($instance4, ENROL_INSTANCE_DISABLED);
     // Cohort member test.
     $instance5 = $DB->get_record('enrol', array('courseid' => $course5->id, 'enrol' => 'self'), '*', MUST_EXIST);
     $instance5->customint6 = 1;
     $instance5->customint5 = $cohort1->id;
     $DB->update_record('enrol', $instance1);
     $selfplugin->update_status($instance5, ENROL_INSTANCE_ENABLED);
     $id = $selfplugin->add_instance($course5, $selfplugin->get_instance_defaults());
     $instance6 = $DB->get_record('enrol', array('id' => $id), '*', MUST_EXIST);
     $instance6->customint6 = 1;
     $instance6->customint5 = $cohort2->id;
     $DB->update_record('enrol', $instance1);
     $selfplugin->update_status($instance6, ENROL_INSTANCE_ENABLED);
     // Enrol start date is in future.
     $instance7 = $DB->get_record('enrol', array('courseid' => $course6->id, 'enrol' => 'self'), '*', MUST_EXIST);
     $instance7->customint6 = 1;
     $instance7->enrolstartdate = time() + 60;
     $DB->update_record('enrol', $instance7);
     $selfplugin->update_status($instance7, ENROL_INSTANCE_ENABLED);
     // Enrol start date is in past.
     $instance8 = $DB->get_record('enrol', array('courseid' => $course7->id, 'enrol' => 'self'), '*', MUST_EXIST);
     $instance8->customint6 = 1;
     $instance8->enrolstartdate = time() - 60;
     $DB->update_record('enrol', $instance8);
     $selfplugin->update_status($instance8, ENROL_INSTANCE_ENABLED);
     // Enrol end date is in future.
     $instance9 = $DB->get_record('enrol', array('courseid' => $course8->id, 'enrol' => 'self'), '*', MUST_EXIST);
     $instance9->customint6 = 1;
     $instance9->enrolenddate = time() + 60;
     $DB->update_record('enrol', $instance9);
     $selfplugin->update_status($instance9, ENROL_INSTANCE_ENABLED);
     // Enrol end date is in past.
     $instance10 = $DB->get_record('enrol', array('courseid' => $course9->id, 'enrol' => 'self'), '*', MUST_EXIST);
     $instance10->customint6 = 1;
     $instance10->enrolenddate = time() - 60;
     $DB->update_record('enrol', $instance10);
     $selfplugin->update_status($instance10, ENROL_INSTANCE_ENABLED);
     // Maximum enrolments reached.
     $instance11 = $DB->get_record('enrol', array('courseid' => $course10->id, 'enrol' => 'self'), '*', MUST_EXIST);
     $instance11->customint6 = 1;
     $instance11->customint3 = 1;
     $DB->update_record('enrol', $instance11);
     $selfplugin->update_status($instance11, ENROL_INSTANCE_ENABLED);
     $selfplugin->enrol_user($instance11, $user2->id, $studentrole->id);
     // Maximum enrolments not reached.
     $instance12 = $DB->get_record('enrol', array('courseid' => $course11->id, 'enrol' => 'self'), '*', MUST_EXIST);
     $instance12->customint6 = 1;
     $instance12->customint3 = 1;
     $DB->update_record('enrol', $instance12);
     $selfplugin->update_status($instance12, ENROL_INSTANCE_ENABLED);
     $this->setUser($user1);
     $this->assertTrue($selfplugin->show_enrolme_link($instance1));
     $this->assertFalse($selfplugin->show_enrolme_link($instance2));
     $this->assertFalse($selfplugin->show_enrolme_link($instance3));
     $this->assertFalse($selfplugin->show_enrolme_link($instance4));
     $this->assertFalse($selfplugin->show_enrolme_link($instance7));
     $this->assertTrue($selfplugin->show_enrolme_link($instance8));
     $this->assertTrue($selfplugin->show_enrolme_link($instance9));
     $this->assertFalse($selfplugin->show_enrolme_link($instance10));
     $this->assertFalse($selfplugin->show_enrolme_link($instance11));
     $this->assertTrue($selfplugin->show_enrolme_link($instance12));
     require_once "{$CFG->dirroot}/cohort/lib.php";
     cohort_add_member($cohort1->id, $user1->id);
     $this->assertTrue($selfplugin->show_enrolme_link($instance5));
     $this->assertFalse($selfplugin->show_enrolme_link($instance6));
 }
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:self_test.php

示例12: test_sync_all_cohort_roles

 public function test_sync_all_cohort_roles()
 {
     $this->setAdminUser();
     $params = (object) array('userid' => $this->userassignto->id, 'roleid' => $this->roleid, 'cohortid' => $this->cohort->id);
     $result = api::create_cohort_role_assignment($params);
     // Verify roles are assigned when users enter the cohort.
     $sync = api::sync_all_cohort_roles();
     $rolesadded = array(array('useridassignedto' => $this->userassignto->id, 'useridassignedover' => $this->userassignover->id, 'roleid' => $this->roleid));
     $rolesremoved = array();
     $expected = array('rolesadded' => $rolesadded, 'rolesremoved' => $rolesremoved);
     $this->assertEquals($sync, $expected);
     // Verify roles are removed when users leave the cohort.
     cohort_remove_member($this->cohort->id, $this->userassignover->id);
     $sync = api::sync_all_cohort_roles();
     $rolesadded = array();
     $rolesremoved = array(array('useridassignedto' => $this->userassignto->id, 'useridassignedover' => $this->userassignover->id, 'roleid' => $this->roleid));
     $expected = array('rolesadded' => $rolesadded, 'rolesremoved' => $rolesremoved);
     $this->assertEquals($sync, $expected);
     // Verify roles assigned by any other component are not removed.
     $usercontext = context_user::instance($this->userassignover->id);
     role_assign($this->roleid, $this->userassignto->id, $usercontext->id);
     $sync = api::sync_all_cohort_roles();
     $rolesadded = array();
     $rolesremoved = array();
     $expected = array('rolesadded' => $rolesadded, 'rolesremoved' => $rolesremoved);
     $this->assertEquals($sync, $expected);
     // Remove manual role assignment.
     role_unassign($this->roleid, $this->userassignto->id, $usercontext->id);
     // Add someone to the cohort again...
     cohort_add_member($this->cohort->id, $this->userassignover->id);
     $sync = api::sync_all_cohort_roles();
     $rolesadded = array(array('useridassignedto' => $this->userassignto->id, 'useridassignedover' => $this->userassignover->id, 'roleid' => $this->roleid));
     $rolesremoved = array();
     $expected = array('rolesadded' => $rolesadded, 'rolesremoved' => $rolesremoved);
     $this->assertEquals($sync, $expected);
     // Verify no fatal errors when a cohort is deleted.
     cohort_delete_cohort($this->cohort);
     $sync = api::sync_all_cohort_roles();
     $rolesadded = array();
     $rolesremoved = array(array('useridassignedto' => $this->userassignto->id, 'useridassignedover' => $this->userassignover->id, 'roleid' => $this->roleid));
     $expected = array('rolesadded' => $rolesadded, 'rolesremoved' => $rolesremoved);
     $this->assertEquals($sync, $expected);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:43,代码来源:api_test.php

示例13: get_string

        $cohort->description = get_string('cohort_synchronized_with_group', 'local_ldap', $groupname);
        //print_r($cohort);
        $cohortid = cohort_add_cohort($cohort);
        print "creating cohort " . $group . PHP_EOL;
    } else {
        $cohortid = $cohort->id;
        $ldap_members = $plugin->ldap_get_group_members($groupname);
    }
    if ($CFG->debug_ldap_groupes) {
        pp_print_object("members of LDAP group {$groupname} known to Moodle", $ldap_members);
    }
    $cohort_members = $plugin->get_cohort_members($cohortid);
    if ($CFG->debug_ldap_groupes) {
        pp_print_object("current members of cohort {$groupname}", $cohort_members);
    }
    foreach ($cohort_members as $userid => $user) {
        if (!isset($ldap_members[$userid])) {
            cohort_remove_member($cohortid, $userid);
            print "removing " . $user->username . " from cohort " . $groupname . PHP_EOL;
        }
    }
    foreach ($ldap_members as $userid => $username) {
        if (!$plugin->cohort_is_member($cohortid, $userid)) {
            cohort_add_member($cohortid, $userid);
            print "adding " . $username . " to cohort " . $groupname . PHP_EOL;
        }
    }
    //break;
}
$difftime = microtime_diff($starttime, microtime());
print "Execution took " . $difftime . " seconds" . PHP_EOL;
开发者ID:jtuttas,项目名称:moodle_local_ldap,代码行数:31,代码来源:sync_cohorts.php

示例14: bulk_batch_enroll_existingstudents

function bulk_batch_enroll_existingstudents($cir, $data){
    
    
    global $CFG,$DB,$USER;
    require_once ($CFG->dirroot . '/group/lib.php');
    $returnurl = new moodle_url('/local/batches/bulk_enroll.php');
    $STD_FIELDS = array('userid', 'serviceid');

    $PRF_FIELDS = array();
   
    $result = '';
    
    $roleid = $data->roleassign;
    $useridfield = $data->firstcolumn;

    $enrollablecount = 0;
    $createdgroupscount = 0;
    $createdgroupingscount = 0;
    $createdgroups = '';
    $createdgroupings = '';
    
    $filecolumns = uu_validate_admission_upload_columns($cir, $STD_FIELDS, $PRF_FIELDS, $returnurl);
    $upt = new uu_progress_tracker();
    $plugin = enrol_get_plugin('manual');
    // init csv import helper
    $cir->init();

    $linenum = 1;
    loop:
    while ($line = $cir->next()) {
    $result=''; $existsmail=0;
    
    $upt->flush();
    $linenum++;
    $existuser = new stdClass();
    // add fields to admission object
    foreach ($line as $keynum => $value) {
        if (!isset($filecolumns[$keynum])) {
            // this should not happen
            continue;
        }
        $key = $filecolumns[$keynum];
	
        $existuser->$key = $value;
    }
     $existuser->linenum = $linenum;
        $batchid= $data->batchid;
        

	if(empty($batchid)){	    
	    echo '<div class="alert alert-error">'.get_string('batchempty', 'local_batches'). '</div>';
            continue;	
	}
	
	if(empty($existuser->serviceid)){
	     echo '<div class="alert alert-error">'.get_string('provideserviceid', 'local_batches'). '</div>';
            continue;	 
	    
	}
	
	if(empty($existuser->userid)){
	     echo '<div class="alert alert-error">'.get_string('provideuserid', 'local_batches'). '</div>';
            continue;	 	    
	}
        
	if($existuser->userid){
	    if(!$DB->record_exists('local_userdata',array('userid'=>$existuser->userid))){
	    echo '<div class="alert alert-error">'.get_string('provideuserid', 'local_batches'). '</div>';
            continue;
		
	    }
	    
	    
	}
	
	
            
        if($DB->record_exists('cohort_members',array('userid'=>$existuser->userid, 'cohortid'=>$batchid))) {
        echo '<div class="alert alert-error">'.get_string('im:already_in', 'local_mass_enroll', fullname($user)). '</div>';

        } else {
               cohort_add_member($batchid, $existuser->userid);
	}    
    
    }// end of while   
} // end of function
开发者ID:anilch,项目名称:Personel,代码行数:86,代码来源:bulk_enrollib.php

示例15: sync_cohorts

 function sync_cohorts($cohorts, $userid)
 {
     global $DB;
     try {
         $queryparams = array($userid);
         $pattern = '/\\d{4}.\\d{5}/is';
         preg_match_all($pattern, str_replace(':', '.', $cohorts), $matches);
         list($insql, $inparams) = $DB->get_in_or_equal($matches[0]);
         $params = array_merge($queryparams, $inparams);
         $cohortsnotenroled = $DB->get_records_sql("select id from {cohort} where idnumber not in (select c.idnumber from {user} u, {cohort} c, {cohort_members} cm where u.id=?" . " and u.id=cm.userid and cm.cohortid=c.id ) and idnumber {$insql}", $params);
         foreach ($cohortsnotenroled as $cohort) {
             cohort_add_member($cohort->id, $userid);
         }
     } catch (moodle_exception $e) {
         error_log('Error in sync_cohorts for user ' . $userid);
         continue;
     }
 }
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:18,代码来源:auth.php


注:本文中的cohort_add_member函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。