/**
  * Run forum cron.
  */
 public function execute()
 {
     global $DB, $CFG;
     $currenttime = time();
     $statement = 'SELECT R.* FROM {ratingallocate} AS R
     LEFT JOIN {ratingallocate_allocations} AS A
     ON R.' . this_db\ratingallocate::ID . '=A.' . this_db\ratingallocate_allocations::RATINGALLOCATEID . '
     WHERE A.' . this_db\ratingallocate_allocations::ID . ' IS NULL AND R.' . this_db\ratingallocate::ACCESSTIMESTOP . '<' . $currenttime;
     $records = $DB->get_records_sql($statement);
     $course = null;
     foreach ($records as $record) {
         $cm = get_coursemodule_from_instance(this_db\ratingallocate::TABLE, $record->{this_db\ratingallocate::ID});
         // Fetch the data for the course, if is has changed
         if (!$course || $course->id != $record->{this_db\ratingallocate::COURSE}) {
             $course = $DB->get_record('course', array('id' => $record->{this_db\ratingallocate::COURSE}), '*', MUST_EXIST);
         }
         // Create ratingallocate instance from record
         $ratingallocate = new \ratingallocate($record, $course, $cm, \context_module::instance($cm->id));
         $currenttime = time();
         $timetoterminate = $CFG->ratingallocate_algorithm_timeout + $ratingallocate->ratingallocate->algorithmstarttime;
         // If last execution exeeds timeout limit assume failure of algorithm run.
         if ($ratingallocate->ratingallocate->algorithmstarttime && $currenttime >= $timetoterminate && $ratingallocate->get_algorithm_status() === \mod_ratingallocate\algorithm_status::running) {
             $ratingallocate->set_algorithm_failed();
             return true;
         }
         // Only start the algorithm, if it should be run by the cron and hasn't been started somehow, yet.
         if ($ratingallocate->ratingallocate->runalgorithmbycron === "1" && $ratingallocate->get_algorithm_status() === \mod_ratingallocate\algorithm_status::notstarted) {
             // Run allocation.
             $ratingallocate->distrubute_choices();
         }
     }
     return true;
 }
Пример #2
0
 /**
  * Test imscp_view
  * @return void
  */
 public function test_imscp_view()
 {
     global $CFG;
     $CFG->enablecompletion = 1;
     $this->resetAfterTest();
     $this->setAdminUser();
     // Setup test data.
     $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
     $imscp = $this->getDataGenerator()->create_module('imscp', array('course' => $course->id), array('completion' => 2, 'completionview' => 1));
     $context = context_module::instance($imscp->cmid);
     $cm = get_coursemodule_from_instance('imscp', $imscp->id);
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     imscp_view($imscp, $course, $cm, $context);
     $events = $sink->get_events();
     // 2 additional events thanks to completion.
     $this->assertCount(3, $events);
     $event = array_shift($events);
     // Checking that the event contains the expected values.
     $this->assertInstanceOf('\\mod_imscp\\event\\course_module_viewed', $event);
     $this->assertEquals($context, $event->get_context());
     $moodleurl = new \moodle_url('/mod/imscp/view.php', array('id' => $cm->id));
     $this->assertEquals($moodleurl, $event->get_url());
     $this->assertEventContextNotUsed($event);
     $this->assertNotEmpty($event->get_name());
     // Check completion status.
     $completion = new completion_info($course);
     $completiondata = $completion->get_data($cm);
     $this->assertEquals(1, $completiondata->completionstate);
 }
Пример #3
0
/**
 * Internal function - creates htmls structure suitable for YUI tree.
 */
function imscp_htmllize_item($item, $imscp, $cm)
{
    global $CFG;
    if ($item['href']) {
        if (preg_match('|^https?://|', $item['href'])) {
            $url = $item['href'];
        } else {
            $context = context_module::instance($cm->id);
            $urlbase = "{$CFG->wwwroot}/pluginfile.php";
            $path = '/' . $context->id . '/mod_imscp/content/' . $imscp->revision . '/' . $item['href'];
            $url = file_encode_url($urlbase, $path, false);
        }
        $result = "<li><a href=\"{$url}\">" . $item['title'] . '</a>';
    } else {
        $result = '<li>' . $item['title'];
    }
    if ($item['subitems']) {
        $result .= '<ul>';
        foreach ($item['subitems'] as $subitem) {
            $result .= imscp_htmllize_item($subitem, $imscp, $cm);
        }
        $result .= '</ul>';
    }
    $result .= '</li>';
    return $result;
}
Пример #4
0
 public function test_event_properties_guessing()
 {
     global $USER;
     $this->resetAfterTest();
     $course = $this->getDataGenerator()->create_course();
     $forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id));
     $context = context_module::instance($forum->cmid);
     $event = \core_tests\event\unittest_executed::create(array('context' => $context, 'objectid' => 5));
     // Check guessed course ID, and default properties.
     $this->assertSame('\\core_tests\\event\\unittest_executed', $event->eventname);
     $this->assertSame('core_tests', $event->component);
     $this->assertSame('executed', $event->action);
     $this->assertSame('unittest', $event->target);
     $this->assertSame(5, $event->objectid);
     $this->assertEquals($context, $event->get_context());
     $this->assertEquals($course->id, $event->courseid);
     $this->assertSame($USER->id, $event->userid);
     $this->assertNull($event->relateduserid);
     $user = $this->getDataGenerator()->create_user();
     $context = context_user::instance($user->id);
     $event = \core_tests\event\unittest_executed::create(array('contextid' => $context->id, 'objectid' => 5));
     // Check guessing on contextid, and user context level.
     $this->assertEquals($context, $event->get_context());
     $this->assertEquals($context->id, $event->contextid);
     $this->assertEquals($context->contextlevel, $event->contextlevel);
     $this->assertSame(0, $event->courseid);
     $this->assertSame($USER->id, $event->userid);
     $this->assertSame($user->id, $event->relateduserid);
 }
Пример #5
0
 public function test_import_chapters_events()
 {
     $course = $this->getDataGenerator()->create_course();
     $book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));
     $context = context_module::instance($book->cmid);
     $record = new stdClass();
     $record->contextid = $context->id;
     $record->component = 'phpunit';
     $record->filearea = 'test';
     $record->itemid = 0;
     $record->filepath = '/';
     $record->filename = 'chapters.zip';
     $fs = get_file_storage();
     $file = $fs->create_file_from_pathname($record, __DIR__ . '/fixtures/chapters.zip');
     // Importing the chapters.
     $sink = $this->redirectEvents();
     toolbook_importhtml_import_chapters($file, 2, $book, $context, false);
     $events = $sink->get_events();
     // Checking the results.
     $this->assertCount(5, $events);
     foreach ($events as $event) {
         $this->assertInstanceOf('\\mod_book\\event\\chapter_created', $event);
         $this->assertEquals($context, $event->get_context());
         $chapter = $event->get_record_snapshot('book_chapters', $event->objectid);
         $this->assertNotEmpty($chapter);
         $this->assertEventContextNotUsed($event);
     }
 }
Пример #6
0
    public function test_book_exported() {
        // There is no proper API to call to test the event, so what we are
        // doing here is simply making sure that the events returns the right information.

        $course = $this->getDataGenerator()->create_course();
        $book = $this->getDataGenerator()->create_module('book', array('course' => $course->id));

        $params = array(
            'context' => context_module::instance($book->cmid),
            'objectid' => $book->id
        );
        $event = \booktool_exportimscp\event\book_exported::create($params);

        // Triggering and capturing the event.
        $sink = $this->redirectEvents();
        $event->trigger();
        $events = $sink->get_events();
        $this->assertCount(1, $events);
        $event = reset($events);

        // Checking that the event contains the expected values.
        $this->assertInstanceOf('\booktool_exportimscp\event\book_exported', $event);
        $this->assertEquals(context_module::instance($book->cmid), $event->get_context());
        $this->assertEquals($book->id, $event->objectid);
        $expected = array($course->id, 'book', 'exportimscp', 'tool/exportimscp/index.php?id=' . $book->cmid,
            $book->id, $book->cmid);
        $this->assertEventLegacyLogData($expected, $event);
        $this->assertEventContextNotUsed($event);
    }
Пример #7
0
 public function test_generator()
 {
     global $DB;
     $this->resetAfterTest(true);
     $this->assertEquals(0, $DB->count_records('forum'));
     $course = $this->getDataGenerator()->create_course();
     /** @var mod_forum_generator $generator */
     $generator = $this->getDataGenerator()->get_plugin_generator('mod_forum');
     $this->assertInstanceOf('mod_forum_generator', $generator);
     $this->assertEquals('forum', $generator->get_modulename());
     $generator->create_instance(array('course' => $course->id));
     $generator->create_instance(array('course' => $course->id));
     $forum = $generator->create_instance(array('course' => $course->id));
     $this->assertEquals(3, $DB->count_records('forum'));
     $cm = get_coursemodule_from_instance('forum', $forum->id);
     $this->assertEquals($forum->id, $cm->instance);
     $this->assertEquals('forum', $cm->modname);
     $this->assertEquals($course->id, $cm->course);
     $context = context_module::instance($cm->id);
     $this->assertEquals($forum->cmid, $context->instanceid);
     // test gradebook integration using low level DB access - DO NOT USE IN PLUGIN CODE!
     $forum = $generator->create_instance(array('course' => $course->id, 'assessed' => 1, 'scale' => 100));
     $gitem = $DB->get_record('grade_items', array('courseid' => $course->id, 'itemtype' => 'mod', 'itemmodule' => 'forum', 'iteminstance' => $forum->id));
     $this->assertNotEmpty($gitem);
     $this->assertEquals(100, $gitem->grademax);
     $this->assertEquals(0, $gitem->grademin);
     $this->assertEquals(GRADE_TYPE_VALUE, $gitem->gradetype);
 }
Пример #8
0
 /**
  * Constructor - instantiates one object of this class
  */
 public function __construct($name, $blockid, $moduleid = null, $plan = null)
 {
     global $DB;
     // Check blockid exists
     if (!($block = $DB->get_record('block_instances', array('id' => $blockid)))) {
         throw new backup_task_exception('block_task_block_instance_not_found', $blockid);
     }
     $this->blockid = $blockid;
     $this->blockname = $block->blockname;
     $this->contextid = context_block::instance($this->blockid)->id;
     $this->moduleid = $moduleid;
     $this->modulename = null;
     $this->parentcontextid = null;
     // If moduleid passed, check exists, supports moodle2 format and save info
     // Check moduleid exists
     if (!empty($moduleid)) {
         if (!($coursemodule = get_coursemodule_from_id(false, $moduleid))) {
             throw new backup_task_exception('block_task_coursemodule_not_found', $moduleid);
         }
         // Check activity supports this moodle2 backup format
         if (!plugin_supports('mod', $coursemodule->modname, FEATURE_BACKUP_MOODLE2)) {
             throw new backup_task_exception('block_task_activity_lacks_moodle2_backup_support', $coursemodule->modname);
         }
         $this->moduleid = $moduleid;
         $this->modulename = $coursemodule->modname;
         $this->parentcontextid = context_module::instance($this->moduleid)->id;
     }
     parent::__construct($name, $plan);
 }
Пример #9
0
 public function create_content($glossary, $record = array(), $aliases = array())
 {
     global $DB, $USER, $CFG;
     $this->entrycount++;
     $now = time();
     $record = (array) $record + array('glossaryid' => $glossary->id, 'timecreated' => $now, 'timemodified' => $now, 'userid' => $USER->id, 'concept' => 'Glossary entry ' . $this->entrycount, 'definition' => 'Definition of glossary entry ' . $this->entrycount, 'definitionformat' => FORMAT_MOODLE, 'definitiontrust' => 0, 'usedynalink' => $CFG->glossary_linkentries, 'casesensitive' => $CFG->glossary_casesensitive, 'fullmatch' => $CFG->glossary_fullmatch);
     if (!isset($record['teacherentry']) || !isset($record['approved'])) {
         $context = context_module::instance($glossary->cmid);
         if (!isset($record['teacherentry'])) {
             $record['teacherentry'] = has_capability('mod/glossary:manageentries', $context, $record['userid']);
         }
         if (!isset($record['approved'])) {
             $defaultapproval = $glossary->defaultapproval;
             $record['approved'] = $defaultapproval || has_capability('mod/glossary:approve', $context);
         }
     }
     $id = $DB->insert_record('glossary_entries', $record);
     if ($aliases) {
         foreach ($aliases as $alias) {
             $ar = new stdClass();
             $ar->entryid = $id;
             $ar->alias = $alias;
             $DB->insert_record('glossary_alias', $ar);
         }
     }
     return $DB->get_record('glossary_entries', array('id' => $id), '*', MUST_EXIST);
 }
Пример #10
0
 public function test_generator()
 {
     global $DB, $SITE;
     $this->resetAfterTest(true);
     // Must be a non-guest user to create resources.
     $this->setAdminUser();
     // There are 0 resources initially.
     $this->assertEquals(0, $DB->count_records('resource'));
     // Create the generator object and do standard checks.
     $generator = $this->getDataGenerator()->get_plugin_generator('mod_resource');
     $this->assertInstanceOf('mod_resource_generator', $generator);
     $this->assertEquals('resource', $generator->get_modulename());
     // Create three instances in the site course.
     $generator->create_instance(array('course' => $SITE->id));
     $generator->create_instance(array('course' => $SITE->id));
     $resource = $generator->create_instance(array('course' => $SITE->id));
     $this->assertEquals(3, $DB->count_records('resource'));
     // Check the course-module is correct.
     $cm = get_coursemodule_from_instance('resource', $resource->id);
     $this->assertEquals($resource->id, $cm->instance);
     $this->assertEquals('resource', $cm->modname);
     $this->assertEquals($SITE->id, $cm->course);
     // Check the context is correct.
     $context = context_module::instance($cm->id);
     $this->assertEquals($resource->cmid, $context->instanceid);
     // Check that generated resource module contains a file.
     $fs = get_file_storage();
     $files = $fs->get_area_files($context->id, 'mod_resource', 'content', false, '', false);
     $this->assertEquals(1, count($files));
 }
Пример #11
0
function showListOfLinks($id, $resop)
{
    global $OUTPUT, $DB;
    //need it to check capability
    $cm = get_coursemodule_from_id('resop', $id, 0, false, MUST_EXIST);
    $context = context_module::instance($cm->id);
    echo $OUTPUT->heading(get_string('entries', 'resop'), 4);
    echo $OUTPUT->action_link(new moodle_url('view.php', array('id' => $id, 'action' => 'showAll')), get_string('showall', 'resop'));
    // Required
    //linkliste Klassen/Resources - specific for this resop instance
    $text = $resop->type == 'typeexam' ? get_string('resExam', 'resop') : get_string('resFree', 'resop');
    echo $OUTPUT->heading($text, 4);
    $resources = $DB->get_records_sql('SELECT DISTINCT name FROM {resop_resource_user} ru JOIN {resop_resource} rr ' . " ON ru.resid=rr.id  WHERE ru.actid={$resop->id} ORDER BY name");
    //ok, should only be the resources which are handled in this resop instance
    foreach ($resources as $key => $value) {
        echo $OUTPUT->action_link(new moodle_url('view.php', array('id' => $id, 'action' => 'showClass', 'class' => $key)), $key);
        // Required
        echo "&nbsp;&nbsp;&nbsp;";
    }
    //link list owner over all instances of resop modul
    if (has_capability('mod/resop:book', $context)) {
        echo $OUTPUT->heading(get_string('bookedby_header', 'resop'), 4);
        $resources = $DB->get_records_sql('SELECT DISTINCT name FROM {resop_resource_user} ru JOIN {resop_resop_user} rru ' . 'on ru.uid = rru.uid JOIN {resop_user} u on ru.uid=u.id ORDER BY name');
        foreach ($resources as $key => $value) {
            echo $OUTPUT->action_link(new moodle_url('view.php', array('id' => $id, 'action' => 'showBooker', 'name' => $key)), $key);
            echo "&nbsp;&nbsp;&nbsp;";
        }
    }
}
Пример #12
0
 /**
  * Convenience method to create event object from data when grading group without knowledge of the groups id
  *
  * @param \stdClass $cm course module object
  * @param \stdClass $data grading data to log
  * @return \mod_grouptool\group_graded event object
  */
 public static function create_without_groupid(\stdClass $cm, \stdClass $data)
 {
     // Trigger overview event.
     $data->type = 'users';
     $event = self::create(array('objectid' => $cm->instance, 'context' => \context_module::instance($cm->id), 'other' => (array) $data));
     return $event;
 }
 public function test_create_instance()
 {
     global $DB;
     $this->resetAfterTest(true);
     $course = $this->getDataGenerator()->create_course();
     $this->assertFalse($DB->record_exists('questionnaire', array('course' => $course->id)));
     /** @var mod_questionnaire_generator $generator */
     $generator = $this->getDataGenerator()->get_plugin_generator('mod_questionnaire');
     $this->assertInstanceOf('mod_questionnaire_generator', $generator);
     $this->assertEquals('questionnaire', $generator->get_modulename());
     $questionnaire = $generator->create_instance(array('course' => $course->id));
     $this->assertEquals(1, $DB->count_records('questionnaire'));
     $cm = get_coursemodule_from_instance('questionnaire', $questionnaire->id);
     $this->assertEquals($questionnaire->id, $cm->instance);
     $this->assertEquals('questionnaire', $cm->modname);
     $this->assertEquals($course->id, $cm->course);
     $context = context_module::instance($cm->id);
     $this->assertEquals($questionnaire->cmid, $context->instanceid);
     $survey = $DB->get_record('questionnaire_survey', array('id' => $questionnaire->sid));
     $this->assertEquals($survey->id, $questionnaire->sid);
     $this->assertEquals($questionnaire->name, $survey->name);
     $this->assertEquals($questionnaire->name, $survey->title);
     // Should test creating a public questionnaire, template questionnaire and creating one from a template.
     // Should test event creation if open dates and close dates are specified?
 }
 public function definition()
 {
     $mform = $this->_form;
     $currententry = $this->_customdata['current'];
     $publication = $this->_customdata['publication'];
     $cm = $this->_customdata['cm'];
     $definitionoptions = $this->_customdata['definitionoptions'];
     $attachmentoptions = $this->_customdata['attachmentoptions'];
     $context = context_module::instance($cm->id);
     // Prepare format_string/text options.
     $fmtoptions = array('context' => $context);
     if ($publication->get_instance()->obtainteacherapproval) {
         $text = get_string('published_aftercheck', 'publication');
     } else {
         $text = get_string('published_immediately', 'publication');
     }
     $mform->addElement('header', 'myfiles', get_string('myfiles', 'publication'));
     $mform->addElement('static', 'guideline', get_string('guideline', 'publication'), $text);
     $mform->addElement('filemanager', 'attachment_filemanager', '', null, $attachmentoptions);
     // Hidden params.
     $mform->addElement('hidden', 'id');
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'cmid');
     $mform->setType('cmid', PARAM_INT);
     // Buttons.
     $this->add_action_buttons(true, get_string('save_changes', 'publication'));
     $this->set_data($currententry);
 }
 function create_instance()
 {
     // Include module lib
     $modlib = '../../mod/' . $this->module_name() . '/lib.php';
     if (file_exists($modlib)) {
         global $CFG;
         require_once $modlib;
     } else {
         return array(false, 'Module lib not found');
     }
     $ret = $this->set_module_instance_params();
     if (!$ret[0]) {
         return $ret;
     }
     // Add instance and update course_modules DB row
     $addinstancefunction = $this->module_name() . '_add_instance';
     if ($this->get_num_instance_function_params() == 1) {
         $returnfromfunc = $addinstancefunction($this->moduleobj);
     } else {
         $returnfromfunc = $addinstancefunction($this->moduleobj, true);
     }
     if (!$returnfromfunc or !is_number($returnfromfunc)) {
         // undo everything we can
         $modcontext = context_module::instance($this->moduleobj->coursemodule);
         $modcontext->delete();
         $DB->delete_records('course_modules', array('id' => $this->moduleobj->coursemodule));
         if (!is_number($returnfromfunc)) {
             return array(false, "{$addinstancefunction} is not a valid function");
         } else {
             return array(false, 'Cannot add new module');
         }
     }
     $this->moduleobj->instance = $returnfromfunc;
     return array(true, '');
 }
Пример #16
0
 /**
  * Returns the document associated with this activity.
  *
  * This default implementation for activities sets the activity name to title and the activity intro to
  * content. Any activity can overwrite this function if it is interested in setting other fields than the
  * default ones, or to fill description optional fields with extra stuff.
  *
  * @param stdClass $record
  * @param array    $options
  * @return \core_search\document
  */
 public function get_document($record, $options = array())
 {
     try {
         $cm = $this->get_cm($this->get_module_name(), $record->id, $record->course);
         $context = \context_module::instance($cm->id);
     } catch (\dml_missing_record_exception $ex) {
         // Notify it as we run here as admin, we should see everything.
         debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' . $ex->getMessage(), DEBUG_DEVELOPER);
         return false;
     } catch (\dml_exception $ex) {
         // Notify it as we run here as admin, we should see everything.
         debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER);
         return false;
     }
     // Prepare associative array with data from DB.
     $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
     $doc->set('title', content_to_text($record->name, false));
     $doc->set('content', content_to_text($record->intro, $record->introformat));
     $doc->set('contextid', $context->id);
     $doc->set('courseid', $record->course);
     $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID);
     $doc->set('modified', $record->{static::MODIFIED_FIELD_NAME});
     // Check if this document should be considered new.
     if (isset($options['lastindexedtime'])) {
         $createdfield = static::CREATED_FIELD_NAME;
         if (!empty($createdfield) && $options['lastindexedtime'] < $record->{$createdfield}) {
             // If the document was created after the last index time, it must be new.
             $doc->set_is_new(true);
         }
     }
     return $doc;
 }
 /**
  * Search a list of modules.
  *
  * @param $modulecode
  * @return array [string]
  * @throws \invalid_parameter_exception
  */
 public static function get_submission_status($submissionid)
 {
     global $DB, $USER;
     $params = self::validate_parameters(self::get_submission_status_parameters(), array('submissionid' => $submissionid));
     $submissionid = $params['submissionid'];
     $submission = $DB->get_record('turnitintooltwo_submissions', array('id' => $submissionid));
     if (!$submission) {
         return array('status' => 'error');
     }
     // Grab more data.
     $turnitintooltwo = $DB->get_record('turnitintooltwo', array('id' => $submission->turnitintooltwoid));
     list($course, $cm) = get_course_and_cm_from_instance($turnitintooltwo, 'turnitintooltwo');
     // Check this is our submission.
     if ($USER->id !== $submission->userid && !has_capability('mod/turnitintooltwo:grade', \context_module::instance($cm->id))) {
         return array('status' => 'nopermission');
     }
     // What is the status?
     $status = $DB->get_record('turnitintooltwo_sub_status', array('submissionid' => $submissionid));
     if (!$status) {
         return array('status' => 'queued');
     }
     // Decode the receipt.
     $digitalreceipt = (array) json_decode($status->receipt);
     // Woo!
     if ($status->status == \mod_turnitintooltwo\task\submit_assignment::STATUS_SUCCESS) {
         $turnitintooltwoview = new \turnitintooltwo_view();
         $digitalreceipt = $turnitintooltwoview->show_digital_receipt($digitalreceipt);
         $digitalreceipt = \html_writer::tag("div", $digitalreceipt, array("id" => "box_receipt"));
         return array('status' => 'success', 'message' => $digitalreceipt);
     }
     return array('status' => 'failed', 'message' => \html_writer::tag("div", $digitalreceipt["message"], array("class" => "alert alert-danger")));
 }
Пример #18
0
 /**
  * Renders the videofile page header.
  *
  * @param videofile videofile
  * @return string
  */
 public function video_header($videofile)
 {
     global $CFG;
     $output = '';
     $name = format_string($videofile->get_instance()->name, true, $videofile->get_course());
     $title = $this->page->course->shortname . ': ' . $name;
     $coursemoduleid = $videofile->get_course_module()->id;
     $context = context_module::instance($coursemoduleid);
     // Add videojs css and js files.
     $this->page->requires->css('/mod/videofile/video-js-4.6.3/video-js.min.css');
     $this->page->requires->js('/mod/videofile/video-js-4.6.3/video.js', true);
     // Set the videojs flash fallback url.
     $swfurl = new moodle_url('/mod/videofile/video-js-4.6.3/video-js.swf');
     $this->page->requires->js_init_code('videojs.options.flash.swf = "' . $swfurl . '";');
     // Yui module handles responsive mode video resizing.
     if ($videofile->get_instance()->responsive) {
         $config = get_config('videofile');
         $this->page->requires->yui_module('moodle-mod_videofile-videojs', 'M.mod_videofile.videojs.init', array($videofile->get_instance()->id, $swfurl, $videofile->get_instance()->width, $videofile->get_instance()->height, (bool) $config->limitdimensions));
     }
     // Header setup.
     $this->page->set_title($title);
     $this->page->set_heading($this->page->course->fullname);
     $output .= $this->output->header();
     $output .= $this->output->heading($name, 3);
     if (!empty($videofile->get_instance()->intro)) {
         $output .= $this->output->box_start('generalbox boxaligncenter', 'intro');
         $output .= format_module_intro('videofile', $videofile->get_instance(), $coursemoduleid);
         $output .= $this->output->box_end();
     }
     return $output;
 }
Пример #19
0
function xmldb_oublog_install()
{
    global $DB, $CFG;
    require_once $CFG->dirroot . '/course/lib.php';
    // Setup the global blog.
    $oublog = new stdClass();
    $oublog->course = SITEID;
    $oublog->name = 'Personal Blogs';
    $oublog->intro = '';
    $oublog->introformat = FORMAT_HTML;
    $oublog->accesstoken = md5(uniqid(rand(), true));
    $oublog->maxvisibility = 300;
    // OUBLOG_VISIBILITY_PUBLIC.
    $oublog->global = 1;
    $oublog->allowcomments = 2;
    // OUBLOG_COMMENTS_ALLOWPUBLIC.
    if (!($oublog->id = $DB->insert_record('oublog', $oublog))) {
        return false;
    }
    $mod = new stdClass();
    $mod->course = SITEID;
    $mod->module = $DB->get_field('modules', 'id', array('name' => 'oublog'));
    $mod->instance = $oublog->id;
    $mod->visible = 1;
    $mod->visibleold = 0;
    $mod->section = 1;
    if (!($cm = add_course_module($mod))) {
        return true;
    }
    set_config('oublogsetup', null);
    // For unit tests to work, it's necessary to create context now.
    context_module::instance($cm);
    return true;
}
Пример #20
0
 /**
  * Returns a list of glossaries in a provided list of courses.
  *
  * If no list is provided all glossaries that the user can view will be returned.
  *
  * @param array $courseids the course IDs.
  * @return array of glossaries
  * @since Moodle 3.1
  */
 public static function get_glossaries_by_courses($courseids = array())
 {
     $params = self::validate_parameters(self::get_glossaries_by_courses_parameters(), array('courseids' => $courseids));
     $warnings = array();
     $courses = array();
     $courseids = $params['courseids'];
     if (empty($courseids)) {
         $courses = enrol_get_my_courses();
         $courseids = array_keys($courses);
     }
     // Array to store the glossaries to return.
     $glossaries = array();
     // Ensure there are courseids to loop through.
     if (!empty($courseids)) {
         list($courses, $warnings) = external_util::validate_courses($courseids, $courses);
         // Get the glossaries in these courses, this function checks users visibility permissions.
         $glossaries = get_all_instances_in_courses('glossary', $courses);
         foreach ($glossaries as $glossary) {
             $context = context_module::instance($glossary->coursemodule);
             $glossary->name = external_format_string($glossary->name, $context->id);
             list($glossary->intro, $glossary->introformat) = external_format_text($glossary->intro, $glossary->introformat, $context->id, 'mod_glossary', 'intro', null);
         }
     }
     $result = array();
     $result['glossaries'] = $glossaries;
     $result['warnings'] = $warnings;
     return $result;
 }
Пример #21
0
 public function __construct($id = 0, $questionnaire = null, &$course, &$cm, $addquestions = true)
 {
     global $DB;
     if ($id) {
         $questionnaire = $DB->get_record('questionnaire', array('id' => $id));
     }
     if (is_object($questionnaire)) {
         $properties = get_object_vars($questionnaire);
         foreach ($properties as $property => $value) {
             $this->{$property} = $value;
         }
     }
     if (!empty($this->sid)) {
         $this->add_survey($this->sid);
     }
     $this->course = $course;
     $this->cm = $cm;
     // When we are creating a brand new questionnaire, we will not yet have a context.
     if (!empty($cm) && !empty($this->id)) {
         $this->context = context_module::instance($cm->id);
     } else {
         $this->context = null;
     }
     if ($addquestions && !empty($this->sid)) {
         $this->add_questions($this->sid);
     }
     $this->usehtmleditor = true;
     // RT
     // Load the capabilities for this user and questionnaire, if not creating a new one.
     if (!empty($this->cm->id)) {
         $this->capabilities = questionnaire_load_capabilities($this->cm->id);
     }
 }
Пример #22
0
 /**
  * Sets up the edit page
  *
  * @param string $baseurl the base url of the
  *
  * @return array Array of variables that the page is set up with
  */
 public function setup_page($baseurl)
 {
     global $PAGE, $CFG, $DB;
     $this->pagevars = array();
     $pageurl = new \moodle_url($baseurl);
     $pageurl->remove_all_params();
     $id = optional_param('cmid', false, PARAM_INT);
     $quizid = optional_param('quizid', false, PARAM_INT);
     // get necessary records from the DB
     if ($id) {
         $cm = get_coursemodule_from_id('activequiz', $id, 0, false, MUST_EXIST);
         $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
         $quiz = $DB->get_record('activequiz', array('id' => $cm->instance), '*', MUST_EXIST);
     } else {
         $quiz = $DB->get_record('activequiz', array('id' => $quizid), '*', MUST_EXIST);
         $course = $DB->get_record('course', array('id' => $quiz->course), '*', MUST_EXIST);
         $cm = get_coursemodule_from_instance('activequiz', $quiz->id, $course->id, false, MUST_EXIST);
     }
     $this->get_parameters();
     // get the rest of the parameters and set them in the class
     if ($CFG->version < 2011120100) {
         $this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
     } else {
         $this->context = \context_module::instance($cm->id);
     }
     // set up question lib
     list($this->pageurl, $this->contexts, $cmid, $cm, $quiz, $this->pagevars) = question_edit_setup('editq', '/mod/activequiz/edit.php', true);
     $PAGE->set_url($this->pageurl);
     $this->pagevars['pageurl'] = $this->pageurl;
     $PAGE->set_title(strip_tags($course->shortname . ': ' . get_string("modulename", "activequiz") . ': ' . format_string($quiz->name, true)));
     $PAGE->set_heading($course->fullname);
     // setup classes needed for the edit page
     $this->RTQ = new \mod_activequiz\activequiz($cm, $course, $quiz, $this->pagevars);
     $this->RTQ->get_renderer()->init($this->RTQ, $this->pageurl, $this->pagevars);
 }
Пример #23
0
/**
 * Deletes an assignment instance
 *
 * @param $id
 */
function assignment_delete_instance($id)
{
    global $CFG, $DB;
    if (!($assignment = $DB->get_record('assignment', array('id' => $id)))) {
        return false;
    }
    $result = true;
    // Now get rid of all files
    $fs = get_file_storage();
    if ($cm = get_coursemodule_from_instance('assignment', $assignment->id)) {
        $context = context_module::instance($cm->id);
        $fs->delete_area_files($context->id);
    }
    if (!$DB->delete_records('assignment_submissions', array('assignment' => $assignment->id))) {
        $result = false;
    }
    if (!$DB->delete_records('event', array('modulename' => 'assignment', 'instance' => $assignment->id))) {
        $result = false;
    }
    if (!$DB->delete_records('assignment', array('id' => $assignment->id))) {
        $result = false;
    }
    grade_update('mod/assignment', $assignment->course, 'mod', 'assignment', $assignment->id, 0, NULL, array('deleted' => 1));
    return $result;
}
Пример #24
0
    public function test_generator() {
        global $DB, $SITE;

        $this->resetAfterTest(true);

        $this->assertEquals(0, $DB->count_records('assignment'));

        /** @var mod_assignment_generator $generator */
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment');
        $this->assertInstanceOf('mod_assignment_generator', $generator);
        $this->assertEquals('assignment', $generator->get_modulename());

        $generator->create_instance(array('course'=>$SITE->id));
        $generator->create_instance(array('course'=>$SITE->id));
        $assignment = $generator->create_instance(array('course'=>$SITE->id));
        $this->assertEquals(3, $DB->count_records('assignment'));

        $cm = get_coursemodule_from_instance('assignment', $assignment->id);
        $this->assertEquals($assignment->id, $cm->instance);
        $this->assertEquals('assignment', $cm->modname);
        $this->assertEquals($SITE->id, $cm->course);

        $context = context_module::instance($cm->id);
        $this->assertEquals($assignment->cmid, $context->instanceid);
    }
Пример #25
0
 /**
  * Returns the document associated with this activity.
  *
  * Overwriting base_activity method as page contents field is required,
  * description field is not.
  *
  * @param stdClass $record
  * @param array    $options
  * @return \core_search\document
  */
 public function get_document($record, $options = array())
 {
     try {
         $cm = $this->get_cm($this->get_module_name(), $record->id, $record->course);
         $context = \context_module::instance($cm->id);
     } catch (\dml_missing_record_exception $ex) {
         // Notify it as we run here as admin, we should see everything.
         debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' . $ex->getMessage(), DEBUG_DEVELOPER);
         return false;
     } catch (\dml_exception $ex) {
         // Notify it as we run here as admin, we should see everything.
         debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER);
         return false;
     }
     // Prepare associative array with data from DB.
     $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
     $doc->set('title', content_to_text($record->name, false));
     $doc->set('content', content_to_text($record->content, $record->contentformat));
     $doc->set('contextid', $context->id);
     $doc->set('courseid', $record->course);
     $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID);
     $doc->set('modified', $record->timemodified);
     $doc->set('description1', content_to_text($record->intro, $record->introformat));
     return $doc;
 }
Пример #26
0
 /**
  * Builds and returns the body of the email notification in plain text.
  *
  * @param object $post
  * @param object $userto
  * @return string The email body in plain text format.
  */
 public function makeMailText($post, $userto)
 {
     global $CFG, $cm;
     $praxe = praxe_record::getData();
     if (!isset($userto->viewfullnames[$praxe->id])) {
         if (!($cm = get_coursemodule_from_instance('praxe', $praxe->id, $this->course->id))) {
             print_error('Course Module ID was incorrect');
         }
         $modcontext = context_module::instance($cm->id);
         $viewfullnames = has_capability('moodle/site:viewfullnames', $modcontext, $userto->id);
     } else {
         $viewfullnames = $userto->viewfullnames[$praxe->id];
     }
     //$by = New stdClass;
     //$by->name = fullname($userfrom, $viewfullnames);
     //$by->date = userdate($post->modified, "", $userto->timezone);
     //$strbynameondate = get_string('bynameondate', 'forum', $by);
     $strpraxes = get_string('modulenameplural', 'praxe');
     $posttext = '';
     $posttext = $this->course->shortname . " -> " . $strpraxes . " -> " . format_string($praxe->name, true);
     $posttext .= "\n---------------------------------------------------------------------\n";
     $posttext .= format_string($this->subject, true);
     //$posttext .= "\n".$strbynameondate."\n";
     $posttext .= "\n---------------------------------------------------------------------\n";
     $posttext .= format_text_email(trusttext_strip($post), FORMAT_PLAIN);
     $posttext .= "\n\n---------------------------------------------------------------------\n";
     $site = get_site();
     foreach ($this->linkstofoot as $link) {
         $posttext .= $link->text . ": " . $link->link . "\t";
         //$posttext .= get_string('confirmorrefusestudent','praxe').": ".$CFG->wwwroot.'/course/view.php?id='.$cm->id."\n\n";
     }
     $posttext .= "\n\n" . $site->shortname . ": " . $CFG->wwwroot . "\n";
     return $posttext;
 }
Пример #27
0
 /**
  * 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;
 }
Пример #28
0
 public function display($quiz, $cm, $course)
 {
     global $CFG, $DB, $OUTPUT;
     // Initialise the required data.
     $this->mode = 'stack';
     $this->context = context_module::instance($cm->id);
     list($currentgroup, $students, $groupstudents, $allowed) = $this->load_relevant_students($cm, $course);
     $this->qubaids = quiz_statistics_qubaids_condition($quiz->id, $currentgroup, $groupstudents, true);
     $questionsused = $this->get_stack_questions_used_in_attempt($this->qubaids);
     $questionid = optional_param('questionid', 0, PARAM_INT);
     // Display the appropriate page.
     $this->print_header_and_tabs($cm, $course, $quiz);
     if (!$questionsused) {
         $this->display_no_stack_questions();
     } else {
         if (!$questionid) {
             $this->display_index($questionsused);
         } else {
             if (array_key_exists($questionid, $questionsused)) {
                 $this->display_analysis($questionsused[$questionid]);
             } else {
                 $this->display_unknown_question();
             }
         }
     }
 }
Пример #29
0
 /**
  * Returns the document associated with this post id.
  *
  * @param stdClass $record Post info.
  * @return \core_search\document
  */
 public function get_document($record)
 {
     try {
         $cm = $this->get_cm('forum', $record->forumid, $record->courseid);
         $context = \context_module::instance($cm->id);
     } catch (\dml_missing_record_exception $ex) {
         // Notify it as we run here as admin, we should see everything.
         debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' . $ex->getMessage(), DEBUG_DEVELOPER);
         return false;
     } catch (\dml_exception $ex) {
         // Notify it as we run here as admin, we should see everything.
         debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER);
         return false;
     }
     // Prepare associative array with data from DB.
     $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
     $doc->set('title', $record->subject);
     $doc->set('content', content_to_text($record->message, $record->messageformat));
     $doc->set('contextid', $context->id);
     $doc->set('type', \core_search\manager::TYPE_TEXT);
     $doc->set('courseid', $record->courseid);
     $doc->set('userid', $record->userid);
     $doc->set('modified', $record->modified);
     return $doc;
 }
 public function display($discussion)
 {
     // Obtain list of other forums in this course where the user has the
     // 'move discussion' feature
     $course = $discussion->get_forum()->get_course();
     $modinfo = get_fast_modinfo($course);
     $results = array();
     foreach ($modinfo->instances['forumng'] as $other) {
         // Don't let user move discussion to its current forum
         if ($other->instance == $discussion->get_forum()->get_id() || $other->id == $discussion->get_forum()->get_course_module_id()) {
             continue;
         }
         $othercontext = context_module::instance($other->id);
         if (has_capability('mod/forumng:movediscussions', $othercontext)) {
             $results[$other->id] = $other->name;
         }
     }
     if (count($results) == 0) {
         return '';
     }
     // Make list alphabetical
     uasort($results, array('forumngfeature_move', 'sort_ignore_case'));
     // Build select using the list
     $out = mod_forumng_utils::get_renderer();
     $select = html_writer::select($results, 'target', '', array('' => get_string('movethisdiscussionto', 'forumngfeature_move')));
     return '<form method="post" action="feature/move/move.php"><div>' . $discussion->get_link_params(mod_forumng::PARAM_FORM) . $select . '<input class="forumng-zero-disable" ' . 'type="submit" value="' . get_string('move') . '" /></div></form>';
 }