本文整理汇总了PHP中core_competency\api::remove_competency_from_course_module方法的典型用法代码示例。如果您正苦于以下问题:PHP api::remove_competency_from_course_module方法的具体用法?PHP api::remove_competency_from_course_module怎么用?PHP api::remove_competency_from_course_module使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core_competency\api
的用法示例。
在下文中一共展示了api::remove_competency_from_course_module方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_list_course_modules_using_competency
public function test_list_course_modules_using_competency()
{
global $SITE;
$this->resetAfterTest(true);
$dg = $this->getDataGenerator();
$lpg = $dg->get_plugin_generator('core_competency');
$u1 = $dg->create_user();
$u2 = $dg->create_user();
$course = $dg->create_course();
$course2 = $dg->create_course();
$this->setAdminUser();
$f = $lpg->create_framework();
$c = $lpg->create_competency(array('competencyframeworkid' => $f->get_id()));
$c2 = $lpg->create_competency(array('competencyframeworkid' => $f->get_id()));
$cc = api::add_competency_to_course($course->id, $c->get_id());
$cc2 = api::add_competency_to_course($course->id, $c2->get_id());
// First check we get an empty list when there are no links.
$expected = array();
$result = api::list_course_modules_using_competency($c->get_id(), $course->id);
$this->assertEquals($expected, $result);
$pagegenerator = $this->getDataGenerator()->get_plugin_generator('mod_page');
$page = $pagegenerator->create_instance(array('course' => $course->id));
$cm = get_coursemodule_from_instance('page', $page->id);
// Add a link and list again.
$ccm = api::add_competency_to_course_module($cm, $c->get_id());
$expected = array($cm->id);
$result = api::list_course_modules_using_competency($c->get_id(), $course->id);
$this->assertEquals($expected, $result);
// Check a different course.
$expected = array();
$result = api::list_course_modules_using_competency($c->get_id(), $course2->id);
$this->assertEquals($expected, $result);
// Remove the link and check again.
$result = api::remove_competency_from_course_module($cm, $c->get_id());
$expected = true;
$this->assertEquals($expected, $result);
$expected = array();
$result = api::list_course_modules_using_competency($c->get_id(), $course->id);
$this->assertEquals($expected, $result);
// Now add 2 links.
api::add_competency_to_course_module($cm, $c->get_id());
api::add_competency_to_course_module($cm, $c2->get_id());
$result = api::list_course_module_competencies_in_course_module($cm->id);
$this->assertEquals($result[0]->get_competencyid(), $c->get_id());
$this->assertEquals($result[1]->get_competencyid(), $c2->get_id());
// Now re-order.
api::reorder_course_module_competency($cm, $c->get_id(), $c2->get_id());
$result = api::list_course_module_competencies_in_course_module($cm->id);
$this->assertEquals($result[0]->get_competencyid(), $c2->get_id());
$this->assertEquals($result[1]->get_competencyid(), $c->get_id());
// And re-order again.
api::reorder_course_module_competency($cm, $c->get_id(), $c2->get_id());
$result = api::list_course_module_competencies_in_course_module($cm->id);
$this->assertEquals($result[0]->get_competencyid(), $c->get_id());
$this->assertEquals($result[1]->get_competencyid(), $c2->get_id());
}
示例2: tool_lp_coursemodule_edit_post_actions
/**
* Hook the add/edit of the course module.
*
* @param stdClass $data Data from the form submission.
* @param stdClass $course The course.
*/
function tool_lp_coursemodule_edit_post_actions($data, $course)
{
if (!get_config('core_competency', 'enabled')) {
return $data;
}
// It seems like the form did not contain any of the form fields, we can return.
if (!isset($data->competency_rule) && !isset($data->competencies)) {
return $data;
}
// We bypass the API here and go direct to the persistent layer - because we don't want to do permission
// checks here - we need to load the real list of existing course module competencies.
$existing = \core_competency\course_module_competency::list_course_module_competencies($data->coursemodule);
$existingids = array();
foreach ($existing as $cmc) {
array_push($existingids, $cmc->get_competencyid());
}
$newids = isset($data->competencies) ? $data->competencies : array();
$removed = array_diff($existingids, $newids);
$added = array_diff($newids, $existingids);
foreach ($removed as $removedid) {
\core_competency\api::remove_competency_from_course_module($data->coursemodule, $removedid);
}
foreach ($added as $addedid) {
\core_competency\api::add_competency_to_course_module($data->coursemodule, $addedid);
}
if (isset($data->competency_rule)) {
// Now update the rules for each course_module_competency.
$current = \core_competency\api::list_course_module_competencies_in_course_module($data->coursemodule);
foreach ($current as $coursemodulecompetency) {
\core_competency\api::set_course_module_competency_ruleoutcome($coursemodulecompetency, $data->competency_rule);
}
}
return $data;
}
示例3: process_courses
//.........这里部分代码省略.........
// The competency was already in the course...
if ($this->removeoriginalwhenalreadypresent) {
$competenciestoremovefromcourse[$competencyid] = true;
} else {
$this->log_warning($courseid, $competencyid, null, get_string('warningdestinationcoursecompetencyalreadyexists', 'tool_lpmigrate'));
}
}
} catch (moodle_exception $e) {
// There was a major problem with this competency, we will ignore it entirely for the course.
$skipcompetencies[$competencyid] = true;
$this->log_error($courseid, $competencyid, null, get_string('errorwhilemigratingcoursecompetencywithexception', 'tool_lpmigrate', $e->getMessage()));
try {
$transaction->rollback($e);
} catch (moodle_exception $e) {
// Catch the re-thrown exception.
}
continue;
}
$transaction->allow_commit();
}
// Then, convert the module competencies.
if (!empty($this->modulecompetencies[$courseid])) {
foreach ($this->modulecompetencies[$courseid] as $cmid => $competencyids) {
foreach ($competencyids as $competencyid) {
$this->modulecompetencyexpectedmigrations++;
// This mapped competency was not added to the course.
if (!empty($skipcompetencies[$competencyid])) {
continue;
}
$remove = true;
$mapto = isset($this->mappings[$competencyid]) ? $this->mappings[$competencyid] : false;
// We don't have mapping.
if ($mapto === false) {
if (!$this->removewhenmappingismissing) {
$remove = false;
}
} else {
// We have a mapping.
$transaction = $DB->start_delegated_transaction();
try {
// The competency was added successfully.
if (api::add_competency_to_course_module($cmid, $mapto)) {
// Find the added module competency.
$mc = course_module_competency::get_record(array('cmid' => $cmid, 'competencyid' => $mapto));
// Set the competency rule.
api::set_course_module_competency_ruleoutcome($mc, $this->modulecompetenciesoutcomes[$courseid][$cmid][$competencyid]);
// Adapt the sortorder.
api::reorder_course_module_competency($cmid, $mapto, $competencyid);
$this->modulecompetencymigrations++;
} else {
// The competency was already in the module.
if (!$this->removeoriginalwhenalreadypresent) {
$remove = false;
$competencieswithissues[$competencyid] = true;
$this->log_warning($courseid, $competencyid, $cmid, get_string('warningdestinationmodulecompetencyalreadyexists', 'tool_lpmigrate'));
}
}
} catch (moodle_exception $e) {
// There was a major problem with this competency in this module.
$competencieswithissues[$competencyid] = true;
$message = get_string('errorwhilemigratingmodulecompetencywithexception', 'tool_lpmigrate', $e->getMessage());
$this->log_error($courseid, $competencyid, $cmid, $message);
try {
$transaction->rollback($e);
} catch (moodle_exception $e) {
// Catch the re-thrown exception.
}
continue;
}
$transaction->allow_commit();
}
try {
// Go away competency!
if ($remove && api::remove_competency_from_course_module($cmid, $competencyid)) {
$this->modulecompetencyremovals++;
}
} catch (moodle_exception $e) {
$competencieswithissues[$competencyid] = true;
$this->log_warning($courseid, $competencyid, $cmid, get_string('warningcouldnotremovemodulecompetency', 'tool_lpmigrate'));
}
}
}
}
// Finally, we remove the course competencies, but only for the 100% successful ones.
foreach ($competenciestoremovefromcourse as $competencyid => $unused) {
// Skip competencies with issues.
if (isset($competencieswithissues[$competencyid])) {
continue;
}
try {
// Process the course competency.
api::remove_competency_from_course($courseid, $competencyid);
$this->coursecompetencyremovals++;
} catch (moodle_exception $e) {
$this->log_warning($courseid, $competencyid, null, get_string('warningcouldnotremovecoursecompetency', 'tool_lpmigrate'));
}
}
}
$this->progress->end_progress();
}