• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP get_course_and_cm_from_cmid函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: update_activity_completion_status_manually

 /**
  * Update completion status for the current user in an activity, only for activities with manual tracking.
  * @param  int $cmid      Course module id
  * @param  bool $completed Activity completed or not
  * @return array            Result and possible warnings
  * @since Moodle 2.9
  * @throws moodle_exception
  */
 public static function update_activity_completion_status_manually($cmid, $completed)
 {
     // Validate and normalize parameters.
     $params = self::validate_parameters(self::update_activity_completion_status_manually_parameters(), array('cmid' => $cmid, 'completed' => $completed));
     $cmid = $params['cmid'];
     $completed = $params['completed'];
     $warnings = array();
     $context = context_module::instance($cmid);
     self::validate_context($context);
     list($course, $cm) = get_course_and_cm_from_cmid($cmid);
     // Set up completion object and check it is enabled.
     $completion = new completion_info($course);
     if (!$completion->is_enabled()) {
         throw new moodle_exception('completionnotenabled', 'completion');
     }
     // Check completion state is manual.
     if ($cm->completion != COMPLETION_TRACKING_MANUAL) {
         throw new moodle_exception('cannotmanualctrack', 'error');
     }
     $targetstate = $completed ? COMPLETION_COMPLETE : COMPLETION_INCOMPLETE;
     $completion->update_state($cm, $targetstate);
     $result = array();
     $result['status'] = true;
     $result['warnings'] = $warnings;
     return $result;
 }
开发者ID:Hirenvaghasiya,项目名称:moodle,代码行数:34,代码来源:external.php


示例2: update

 /**
  * Updates course module name
  *
  * @param int $itemid course module id
  * @param string $newvalue new name
  * @return static
  */
 public static function update($itemid, $newvalue)
 {
     list($course, $cm) = get_course_and_cm_from_cmid($itemid);
     $context = context_module::instance($cm->id);
     // Check access.
     require_login($course, false, $cm, true, true);
     require_capability('moodle/course:manageactivities', $context);
     // Update value.
     set_coursemodule_name($cm->id, $newvalue);
     // Return instance.
     $cm = get_fast_modinfo($course)->get_cm($cm->id);
     return new static($cm, true);
 }
开发者ID:rushi963,项目名称:moodle,代码行数:20,代码来源:course_module_name.php


示例3: optional_param

// Part ID.
$user = optional_param('user', 0, PARAM_INT);
// User ID.
$do = optional_param('do', "submissions", PARAM_ALPHAEXT);
$action = optional_param('action', "", PARAM_ALPHA);
$viewcontext = optional_param('view_context', "window", PARAM_ALPHAEXT);
$notice = null;
if (isset($_SESSION["notice"])) {
    $notice = $_SESSION["notice"];
    $notice["type"] = empty($_SESSION["notice"]["type"]) ? "general" : $_SESSION["notice"]["type"];
    unset($_SESSION["notice"]);
}
if ($id) {
    //Pre 2.8 does not have the function get_course_and_cm_from_cmid.
    if ($CFG->branch >= 28) {
        list($course, $cm) = get_course_and_cm_from_cmid($id, 'turnitintooltwo');
    } else {
        $cm = get_coursemodule_from_id('turnitintooltwo', $id, 0, false, MUST_EXIST);
        $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
    }
    if (!$cm) {
        turnitintooltwo_print_error('coursemodidincorrect', 'turnitintooltwo');
    }
    if (!($course = $DB->get_record("course", array("id" => $cm->course)))) {
        turnitintooltwo_print_error('coursemisconfigured', 'turnitintooltwo');
    }
    if (!($turnitintooltwo = $DB->get_record("turnitintooltwo", array("id" => $cm->instance)))) {
        turnitintooltwo_print_error('coursemodincorrect', 'turnitintooltwo');
    }
} else {
    if (!($turnitintooltwo = $DB->get_record("turnitintooltwo", array("id" => $a)))) {
开发者ID:NeillM,项目名称:moodle-mod_turnitintooltwo,代码行数:31,代码来源:view.php


示例4: test_get_course_and_cm_from_instance

 /**
  * Tests function for getting $course and $cm at once quickly from modinfo
  * based on instance id or record.
  */
 public function test_get_course_and_cm_from_instance()
 {
     global $CFG, $DB;
     $this->resetAfterTest();
     // Create a course and an activity.
     $generator = $this->getDataGenerator();
     $course = $generator->create_course(array('shortname' => 'Halls'));
     $page = $generator->create_module('page', array('course' => $course->id, 'name' => 'Annie'));
     // Successful usage.
     list($course, $cm) = get_course_and_cm_from_instance($page->id, 'page');
     $this->assertEquals('Halls', $course->shortname);
     $this->assertInstanceOf('cm_info', $cm);
     $this->assertEquals('Annie', $cm->name);
     // With id in object.
     $fakeinstance = (object) array('id' => $page->id);
     list($course, $cm) = get_course_and_cm_from_instance($fakeinstance, 'page');
     $this->assertEquals('Halls', $course->shortname);
     $this->assertEquals('Annie', $cm->name);
     // With both id and course in object.
     $fakeinstance->course = $course->id;
     list($course, $cm) = get_course_and_cm_from_instance($fakeinstance, 'page');
     $this->assertEquals('Halls', $course->shortname);
     $this->assertEquals('Annie', $cm->name);
     // With supplied course id.
     list($course, $cm) = get_course_and_cm_from_instance($page->id, 'page', $course->id);
     $this->assertEquals('Annie', $cm->name);
     // With supplied course object (modified just so we can check it is
     // indeed reusing the supplied object).
     $course->silly = true;
     list($course, $cm) = get_course_and_cm_from_instance($page->id, 'page', $course);
     $this->assertEquals('Annie', $cm->name);
     $this->assertTrue($course->silly);
     // Doesn't exist (or is wrong type).
     try {
         get_course_and_cm_from_instance($page->id, 'forum');
         $this->fail();
     } catch (moodle_exception $e) {
         $this->assertInstanceOf('dml_exception', $e);
     }
     // Invalid module name.
     try {
         get_course_and_cm_from_cmid($page->cmid, '1337 h4x0ring');
         $this->fail();
     } catch (coding_exception $e) {
         $this->assertContains('Invalid modulename parameter', $e->getMessage());
     }
     // Create a second hidden activity.
     $hiddenpage = $generator->create_module('page', array('course' => $course->id, 'name' => 'Annie', 'visible' => 0));
     // Create 2 user accounts, one is a manager who can see everything.
     $user = $generator->create_user();
     $generator->enrol_user($user->id, $course->id);
     $manager = $generator->create_user();
     $generator->enrol_user($manager->id, $course->id, $DB->get_field('role', 'id', array('shortname' => 'manager'), MUST_EXIST));
     // User can see the normal page but not the hidden one.
     list($course, $cm) = get_course_and_cm_from_cmid($page->cmid, 'page', 0, $user->id);
     $this->assertTrue($cm->uservisible);
     list($course, $cm) = get_course_and_cm_from_cmid($hiddenpage->cmid, 'page', 0, $user->id);
     $this->assertFalse($cm->uservisible);
     // Manager can see the hidden one too.
     list($course, $cm) = get_course_and_cm_from_cmid($hiddenpage->cmid, 'page', 0, $manager->id);
     $this->assertTrue($cm->uservisible);
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:66,代码来源:modinfolib_test.php


示例5: required_param

// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * deletes a template
 *
 * @author Andreas Grabs
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package mod_feedback
 */
require_once "../../config.php";
require_once "lib.php";
$current_tab = 'templates';
$id = required_param('id', PARAM_INT);
$deletetempl = optional_param('deletetempl', false, PARAM_INT);
$baseurl = new moodle_url('/mod/feedback/delete_template.php', array('id' => $id));
$PAGE->set_url($baseurl);
list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
$context = context_module::instance($cm->id);
require_login($course, true, $cm);
require_capability('mod/feedback:deletetemplate', $context);
$feedback = $PAGE->activityrecord;
$systemcontext = context_system::instance();
// Process template deletion.
if ($deletetempl) {
    require_sesskey();
    $template = $DB->get_record('feedback_template', array('id' => $deletetempl), '*', MUST_EXIST);
    if ($template->ispublic) {
        require_capability('mod/feedback:createpublictemplate', $systemcontext);
        require_capability('mod/feedback:deletetemplate', $systemcontext);
    }
    feedback_delete_template($template);
    redirect($baseurl, get_string('template_deleted', 'feedback'));
开发者ID:evltuma,项目名称:moodle,代码行数:31,代码来源:delete_template.php


示例6: optional_param

$cmid = optional_param('cmid', 0, PARAM_INT);
$overrideid = optional_param('id', 0, PARAM_INT);
$action = optional_param('action', null, PARAM_ALPHA);
$reset = optional_param('reset', false, PARAM_BOOL);
$override = null;
if ($overrideid) {
    if (!($override = $DB->get_record('quiz_overrides', array('id' => $overrideid)))) {
        print_error('invalidoverrideid', 'quiz');
    }
    if (!($quiz = $DB->get_record('quiz', array('id' => $override->quiz)))) {
        print_error('invalidcoursemodule');
    }
    list($course, $cm) = get_course_and_cm_from_instance($quiz, 'quiz');
} else {
    if ($cmid) {
        list($course, $cm) = get_course_and_cm_from_cmid($cmid, 'quiz');
        $quiz = $DB->get_record('quiz', array('id' => $cm->instance), '*', MUST_EXIST);
    } else {
        print_error('invalidcoursemodule');
    }
}
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$url = new moodle_url('/mod/quiz/overrideedit.php');
if ($action) {
    $url->param('action', $action);
}
if ($overrideid) {
    $url->param('id', $overrideid);
} else {
    $url->param('cmid', $cmid);
}
开发者ID:pzhu2004,项目名称:moodle,代码行数:31,代码来源:overrideedit.php


示例7: dirname

 * @copyright  2014 Marina Glancy
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
/// (Replace stopwatch with the name of your module and remove this line)
require_once dirname(dirname(__DIR__)) . '/config.php';
require_once $CFG->dirroot . '/mod/stopwatch/lib.php';
require_once $CFG->dirroot . '/mod/stopwatch/locallib.php';
require_once $CFG->libdir . '/completionlib.php';
$cmid = optional_param('id', 0, PARAM_INT);
// course_module ID, or
$stopwatchid = optional_param('s', 0, PARAM_INT);
// stopwatch instance ID - it should be named as the first character of the module
$cmd = optional_param('cmd', null, PARAM_ALPHA);
$durationstr = optional_param('durationstr', null, PARAM_NOTAGS);
if ($cmid) {
    list($course, $cm) = get_course_and_cm_from_cmid($cmid, 'stopwatch');
} elseif ($stopwatchid) {
    list($course, $cm) = get_course_and_cm_from_instance($stopwatchid, 'stopwatch');
} else {
    print_error('You must specify a course_module ID or an instance ID');
}
require_login($course, true, $cm);
$stopwatch = $PAGE->activityrecord;
$cmcontext = context_module::instance($cm->id);
$cansubmit = has_capability('mod/stopwatch:submit', $cmcontext, null, false);
$cangrade = has_capability('mod/stopwatch:grade', $cmcontext);
if ($cmd === 'updateduration' && $cansubmit && $durationstr && confirm_sesskey()) {
    mod_stopwatch_update_timer($cm, $stopwatch, mod_stopwatch_string_to_duration($durationstr));
    redirect($cm->url);
}
if ($cmd === 'updategrades' && $cangrade && confirm_sesskey()) {
开发者ID:marinaglancy,项目名称:moodle-mod_stopwatch,代码行数:31,代码来源:view.php


示例8: required_param

// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * This file is the entry point to the assign module. All pages are rendered from here
 *
 * @package   mod_assign
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once '../../config.php';
require_once $CFG->dirroot . '/mod/assign/locallib.php';
$id = required_param('id', PARAM_INT);
list($course, $cm) = get_course_and_cm_from_cmid($id, 'assign');
require_login($course, true, $cm);
$context = context_module::instance($cm->id);
require_capability('mod/assign:view', $context);
$assign = new assign($context, $cm, $course);
$urlparams = array('id' => $id, 'action' => optional_param('action', '', PARAM_TEXT), 'rownum' => optional_param('rownum', 0, PARAM_INT), 'useridlistid' => optional_param('useridlistid', $assign->get_useridlist_key_id(), PARAM_ALPHANUM));
$url = new moodle_url('/mod/assign/view.php', $urlparams);
$PAGE->set_url($url);
// Update module completion status.
$assign->set_module_viewed();
// Apply overrides.
$assign->update_effective_access($USER->id);
// Get the assign class to
// render the page.
echo $assign->view(optional_param('action', '', PARAM_TEXT));
开发者ID:lucaboesch,项目名称:moodle,代码行数:31,代码来源:view.php


示例9: dirname

// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * @package   mod_treasurehunt
 * @copyright 2016 onwards Adrian Rodriguez Fernandez <[email protected]>
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
// Replace treasurehunt with the name of your module and remove this line.
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
require_once "{$CFG->dirroot}/mod/treasurehunt/locallib.php";
require_once $CFG->libdir . '/formslib.php';
global $USER;
$id = required_param('id', PARAM_INT);
list($course, $cm) = get_course_and_cm_from_cmid($id, 'treasurehunt');
$treasurehunt = $DB->get_record('treasurehunt', array('id' => $cm->instance), '*', MUST_EXIST);
require_login($course, true, $cm);
$context = context_module::instance($cm->id);
require_capability('mod/treasurehunt:play', $context, null, false);
//Poner evento de edicion o algo asi
/* $event = \mod_treasurehunt\event\course_module_viewed::create(array(
  'objectid' => $PAGE->cm->instance,
  'context' => $PAGE->context,
  ));
  $event->add_record_snapshot('course', $PAGE->course);
  $event->add_record_snapshot($PAGE->cm->modname, $treasurehunt);
  $event->trigger(); */
// Print the page header.
$PAGE->set_url('/mod/treasurehunt/play.php', array('id' => $cm->id));
$PAGE->set_title(format_string($treasurehunt->name));
开发者ID:juacas,项目名称:moodle-mod_treasurehunt,代码行数:31,代码来源:play.php


示例10: define

// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * Availability password - Ajax file
 *
 * @package    availability_password
 * @copyright  2016 Davo Smith, Synergy Learning UK on behalf of Alexander Bias, University of Ulm <[email protected]>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
define('AJAX_SCRIPT', true);
require_once dirname(__FILE__) . '/../../../config.php';
global $PAGE;
$cmid = required_param('id', PARAM_INT);
$password = required_param('password', PARAM_RAW);
/** @var cm_info $cm */
list($course, $cm) = get_course_and_cm_from_cmid($cmid);
$url = new moodle_url('/availability/condition/password/ajax.php', array('id' => $cm->id));
$PAGE->set_url($url);
require_login($course, false);
require_sesskey();
$ret = (object) ['error' => 0, 'success' => 0];
if (\availability_password\condition::submit_password_for_cm($cm, $password)) {
    $ret->success = 1;
    // Check if the activity can now be accessed.
    $modinfo = get_fast_modinfo($course);
    $cminfo = $modinfo->get_cm($cm->id);
    if ($cminfo->available) {
        $ret->redirect = $cm->url->out(false);
    }
}
echo json_encode($ret);
开发者ID:moodleuulm,项目名称:moodle-availability_password,代码行数:31,代码来源:ajax.php


示例11: required_param

//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * This file is the entry point to the sepl module. All pages are rendered from here
 *
 * @package   mod_sepl
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once '../../config.php';
require_once $CFG->dirroot . '/mod/sepl/locallib.php';
$id = required_param('id', PARAM_INT);
$urlparams = array('id' => $id, 'action' => optional_param('action', '', PARAM_TEXT), 'rownum' => optional_param('rownum', 0, PARAM_INT), 'useridlistid' => optional_param('action', 0, PARAM_INT));
$url = new moodle_url('/mod/sepl/view.php', $urlparams);
list($course, $cm) = get_course_and_cm_from_cmid($id, 'sepl');
require_login($course, true, $cm);
$PAGE->set_url($url);
$context = context_module::instance($cm->id);
require_capability('mod/sepl:view', $context);
$sepl = new sepl($context, $cm, $course);
$completion = new completion_info($course);
$completion->set_module_viewed($cm);
// Get the sepl class to
// render the page.
echo $sepl->view(optional_param('action', '', PARAM_TEXT));
开发者ID:krzpassrl,项目名称:SRL_Moodle_Baseline,代码行数:31,代码来源:view.php


示例12: dirname

 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
require_once dirname(__FILE__) . '/locallib.php';
require_once $CFG->libdir . '/completionlib.php';
require_once $CFG->libdir . '/filelib.php';
require_once $CFG->libdir . '/rsslib.php';
require_once dirname(__FILE__) . '/imageclass.php';
global $DB;
$id = optional_param('id', 0, PARAM_INT);
$l = optional_param('l', 0, PARAM_INT);
$page = optional_param('page', 0, PARAM_INT);
$search = optional_param('search', '', PARAM_TEXT);
$editing = optional_param('editing', 0, PARAM_BOOL);
if ($id) {
    list($course, $cm) = get_course_and_cm_from_cmid($id, 'lightboxgallery');
    if (!($gallery = $DB->get_record('lightboxgallery', array('id' => $cm->instance)))) {
        print_error('invalidcoursemodule');
    }
} else {
    if (!($gallery = $DB->get_record('lightboxgallery', array('id' => $l)))) {
        print_error('invalidlightboxgalleryid', 'lightboxgallery');
    }
    list($course, $cm) = get_course_and_cm_from_instance($gallery, 'lightboxgallery');
}
require_login($course, true, $cm);
if ($gallery->ispublic) {
    $userid = isloggedin() ? $USER->id : 0;
} else {
    require_login($course, true, $cm);
    $userid = $USER->id;
开发者ID:OctaveBabel,项目名称:moodle-itop,代码行数:31,代码来源:view.php


示例13: observer

 public static function observer(\core\event\base $event)
 {
     global $DB;
     $unlocked_content = false;
     if (!block_game_content_unlock_helper::is_student($event->userid)) {
         return;
     }
     $uss = $DB->get_records_sql("SELECT * FROM {content_unlock_system} WHERE deleted = ? AND " . $DB->sql_compare_text('conditions') . " = " . $DB->sql_compare_text('?'), array('deleted' => 0, 'conditions' => $event->eventname));
     foreach ($uss as $unlocksystem) {
         $ccm = get_course_and_cm_from_cmid($unlocksystem->coursemoduleid);
         if ($event->courseid != $ccm[0]->id) {
             continue;
         }
         if (!(content_unlock_satisfies_conditions($unlocksystem->restrictions, $event->courseid, $event->userid) && content_unlock_satisfies_advanced_conditions($unlocksystem, $event) && content_unlock_satisfies_block_conditions($unlocksystem, $event->courseid, $event->userid))) {
             continue;
         }
         $blockcontextid = $DB->get_field('block_instances', 'parentcontextid', array('id' => $unlocksystem->blockinstanceid));
         if (!$blockcontextid) {
             continue;
         }
         $blockcontext = context::instance_by_id($blockcontextid);
         $context = context::instance_by_id($event->contextid);
         if (strpos($context->path, $blockcontext->path) !== 0 && $blockcontext->instanceid != SITEID) {
             continue;
         }
         $sql = "SELECT count(c.id)\n\t\t\t\tFROM {content_unlock_log} c\n\t\t\t\t\tINNER JOIN {logstore_standard_log} l ON c.logid = l.id\n\t\t\t\tWHERE l.userid = :userid\n\t\t\t\t\tAND c.unlocksystemid = :unlocksystemid";
         $params['userid'] = $event->userid;
         $params['unlocksystemid'] = $unlocksystem->id;
         if ($DB->count_records_sql($sql, $params) > 0) {
             continue;
         }
         $manager = get_log_manager();
         $selectreaders = $manager->get_readers('\\core\\log\\sql_reader');
         if ($selectreaders) {
             $reader = reset($selectreaders);
         }
         $selectwhere = "eventname = :eventname\n\t\t\t\tAND component = :component\n\t\t\t\tAND action = :action\n\t\t\t\tAND target = :target\n\t\t\t\tAND crud = :crud\n\t\t\t\tAND edulevel = :edulevel\n\t\t\t\tAND contextid = :contextid\n\t\t\t\tAND contextlevel = :contextlevel\n\t\t\t\tAND contextinstanceid = :contextinstanceid\n\t\t\t\tAND userid = :userid \n\t\t\t\tAND anonymous = :anonymous\n\t\t\t\tAND timecreated = :timecreated";
         $params['eventname'] = $event->eventname;
         $params['component'] = $event->component;
         $params['action'] = $event->action;
         $params['target'] = $event->target;
         $params['crud'] = $event->crud;
         $params['edulevel'] = $event->edulevel;
         $params['contextid'] = $event->contextid;
         $params['contextlevel'] = $event->contextlevel;
         $params['contextinstanceid'] = $event->contextinstanceid;
         $params['userid'] = $event->userid;
         $params['anonymous'] = $event->anonymous;
         $params['timecreated'] = $event->timecreated;
         $logid = $reader->get_events_select($selectwhere, $params, '', 0, 0);
         $logid = array_keys($logid)[0];
         $record = new stdClass();
         $record->logid = $logid;
         $record->unlocksystemid = $unlocksystem->id;
         $DB->insert_record('content_unlock_log', $record);
         $unlocked_content = true;
         if ($unlocksystem->mode == 0) {
             if ($unlocksystem->coursemodulevisibility == 1) {
                 set_section_visible($event->courseid, $ccm[1]->sectionnum, 1);
             }
             set_coursemodule_visible($unlocksystem->coursemoduleid, $unlocksystem->coursemodulevisibility);
         } else {
             groups_add_member($unlocksystem->groupid, $event->userid);
         }
     }
     if ($unlocked_content) {
         $params = array('context' => $context);
         $event = \block_game_content_unlock\event\content_unlocked::create($params);
         $event->trigger();
     }
 }
开发者ID:LoysGibertoni,项目名称:mdl_block_content_unlock,代码行数:71,代码来源:helper.php


示例14: get_content

 public function get_content()
 {
     global $DB, $USER;
     $this->content = new stdClass();
     $this->content->text = '';
     $this->content->footer = '';
     if (user_has_role_assignment($USER->id, 5)) {
         $eventsarray = content_unlock_generate_events_list();
         $us = $DB->get_records('content_unlock_system', array('deleted' => 0, 'blockinstanceid' => $this->instance->id));
         if (!empty($us)) {
             $unlocklist = '';
             $course = $DB->get_record('course', array('id' => $this->page->course->id));
             $info = get_fast_modinfo($course);
             foreach ($us as $unlocksystem) {
                 $sql = "SELECT *\n\t\t\t\t\t\t\tFROM {content_unlock_log} c\n\t\t\t\t\t\t\t\tINNER JOIN {logstore_standard_log} l ON c.logid = l.id\n\t\t\t\t\t\t\tWHERE l.userid = :userid\n\t\t\t\t\t\t\t\tAND c.unlocksystemid = :unlocksystemid";
                 $params['userid'] = $USER->id;
                 $params['unlocksystemid'] = $unlocksystem->id;
                 $unlocked_content = $DB->record_exists_sql($sql, $params);
                 if ($unlocked_content) {
                     continue;
                 }
                 $ccm = get_course_and_cm_from_cmid($unlocksystem->coursemoduleid);
                 if ($this->page->course->id != $ccm[0]->id) {
                     continue;
                 }
                 if (!(content_unlock_satisfies_conditions($unlocksystem->restrictions, $this->page->course->id, $USER->id) && (in_array($unlocksystem->conditions, self::$resource_events) || content_unlock_satisfies_block_conditions($unlocksystem, $this->page->course->id, $USER->id)))) {
                     continue;
                 }
                 $cm = $info->get_cm($unlocksystem->coursemoduleid);
                 $eventdescription = is_null($unlocksystem->eventdescription) ? $eventsarray[$unlocksystem->conditions] : $unlocksystem->eventdescription;
                 $unlocklist = $unlocklist . '<li>' . $cm->name . ' (' . get_string('modulename', $cm->modname) . ') por ' . (in_array($unlocksystem->conditions, self::$resource_events) ? content_unlock_get_block_conditions_text($unlocksystem) : $eventdescription) . '</li>';
             }
             if (strlen($unlocklist) > 0) {
                 $this->content->text = '<p>Você pode desbloquear:<ul>' . $unlocklist . '</ul></p>';
             }
         }
         if (isset($this->config)) {
             $lastunlocksnumber = isset($this->config->lastunlocksnumber) ? $this->config->lastunlocksnumber : 1;
         } else {
             $lastunlocksnumber = 0;
         }
         if ($lastunlocksnumber > 0) {
             $sql = "SELECT c.id as id, s.coursemoduleid as coursemoduleid, s.eventdescription as eventdescription, s.conditions as conditions, s.connective as connective\n\t\t\t\t\tFROM\n\t\t\t\t\t\t{content_unlock_log} c\n\t\t\t\t\tINNER JOIN {logstore_standard_log} l ON c.logid = l.id\n\t\t\t\t\tINNER JOIN {content_unlock_system} s ON c.unlocksystemid = s.id\n\t\t\t\t\tWHERE l.userid = :userid\n\t\t\t\t\t\tAND l.courseid = :courseid\n\t\t\t\t\t\tAND s.blockinstanceid = :blockinstanceid\n\t\t\t\t\tORDER BY c.id DESC";
             $params['userid'] = $USER->id;
             $params['courseid'] = $this->page->course->id;
             $params['blockinstanceid'] = $this->instance->id;
             $lastunlocks = $DB->get_records_sql($sql, $params, 0, $lastunlocksnumber);
             if (!empty($lastunlocks)) {
                 $lastunlockslist = '';
                 foreach ($lastunlocks as $lu) {
                     $ccm = get_course_and_cm_from_cmid($lu->coursemoduleid);
                     $course = $DB->get_record('course', array('id' => $ccm[0]->id));
                     $info = get_fast_modinfo($course);
                     $cm = $info->get_cm($lu->coursemoduleid);
                     $eventdescription = is_null($lu->eventdescription) ? $eventsarray[$lu->conditions] : $lu->eventdescription;
                     $lastunlockslist = $lastunlockslist . '<li>' . $cm->name . ' (' . get_string('modulename', $cm->modname) . ') por ' . (in_array($lu->conditions, self::$resource_events) ? content_unlock_get_block_conditions_text($lu) : $eventdescription) . '</li>';
                 }
                 $this->content->text = $this->content->text . '<p>Você desbloqueou recentemente:<ul>' . $lastunlockslist . '</ul></p>';
             }
         }
     }
     return $this->content;
 }
开发者ID:LoysGibertoni,项目名称:mdl_block_content_unlock,代码行数:63,代码来源:block_game_content_unlock.php


示例15: specific_definition

    protected function specific_definition($mform)
    {
        global $COURSE, $DB, $USER;
        $context = context_course::instance($COURSE->id);
        if (has_capability('block/game_content_unlock:addunlocksystem', $context)) {
            $mform->addElement('header', 'configheader', get_string('unlocksystemeditpage', 'block_game_content_unlock'));
            $mform->addElement('text', 'config_title', 'Título do bloco');
            $mform->setType('config_title', PARAM_TEXT);
            $mform->addElement('select', 'config_lastunlocksnumber', 'Número de últimos desbloqueios exibidos', array(0, 1, 2, 3, 4, 5, 6), null);
            $mform->addRule('config_lastunlocksnumber', null, 'required', null, 'client');
            $mform->setDefault('config_lastunlocksnumber', 1);
            $mform->setType('config_lastunlocksnumber', PARAM_TEXT);
            $eventslist = report_eventlist_list_generator::get_non_core_event_list();
            $eventsarray = array();
            foreach ($eventslist as $value) {
                $description = explode("\\", explode(".", strip_tags($value['fulleventname']))[0]);
                $eventsarray[$value['eventname']] = $description[0] . " (" . $value['eventname'] . ")";
            }
            $course = $DB->get_record('course', array('id' => $COURSE->id));
            $info = get_fast_modinfo($course);
            $sql = "SELECT *\n\t\t\t\tFROM {content_unlock_system} s\n\t\t\t\t\tINNER JOIN {content_unlock_processor} p ON s.id = p.unlocksystemid\n\t\t\t\tWHERE p.processorid = :processorid\n\t\t\t\t\tAND s.blockinstanceid = :blockinstanceid\n\t\t\t\t\tAND s.deleted = 0";
            $params['processorid'] = $USER->id;
            $params['blockinstanceid'] = $this->block->instance->id;
            $unlock_systems = $DB->get_records_sql($sql, $params);
            $html = '<table>
						<tr>
							<th>ID</th>
							<th>Condições</th>
							<th>Módulo</th>
							<th>Visibilidade</th>
							<th>Descrição</th>
							<th>Gerenciar condições</th>
							<th>Editar</th>
							<th>Remover</th>
						</tr>';
            foreach ($unlock_systems as $value) {
                $condition_manage_url = new moodle_url('/blocks/game_content_unlock/conditionmanage.php', array('courseid' => $COURSE->id, 'unlocksystemid' => $value->id));
                $urledit = new moodle_url('/blocks/game_content_unlock/unlocksystemedit.php', array('courseid' => $COURSE->id, 'unlocksystemid' => $value->id));
                $urlremove = new moodle_url('/blocks/game_content_unlock/unlocksystemdelete.php', array('courseid' => $COURSE->id, 'unlocksystemid' => $value->id));
                // Evitar que sistemas de outros cursos sejam exibidos - mudar?
                $ccm = get_course_and_cm_from_cmid($value->coursemoduleid);
                if ($COURSE->id != $ccm[0]->id) {
                    continue;
                }
                $cm = $info->get_cm($value->coursemoduleid);
                $html = $html . '<tr>
									<td>' . $value->id . '</td>
									<td>' . $eventsarray[$value->conditions] . '</td>
									<td>' . $cm->name . '</td>
									<td>' . $value->coursemodulevisibility . '</td>
									<td>' . $value->eventdescription . '</td>
									<td>' . html_writer::link($condition_manage_url, 'Gerenciar condições') . '</td>
									<td>' . html_writer::link($urledit, 'Editar') . '</td>
									<td>' . html_writer::link($urlremove, 'Remover') . '</td>
								</tr>';
            }
            $url = new moodle_url('/blocks/game_content_unlock/unlocksystemadd.php', array('blockid' => $this->block->instance->id, 'courseid' => $COURSE->id));
            $html = $html . '</table>' . html_writer::link($url, get_string('unlocksystemaddpage', 'block_game_content_unlock'));
            $mform->addElement('html', $html);
        }
    }
开发者ID:LoysGibertoni,项目名称:mdl_block_content_unlock,代码行数:61,代码来源:edit_form.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP get_course_and_cm_from_instance函数代码示例发布时间:2022-05-15
下一篇:
PHP get_course函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap