Skip to content

Instantly share code, notes, and snippets.

View prateeksachan's full-sized avatar
🖖

Prateek Sachan prateeksachan

🖖
View GitHub Profile
@prateeksachan
prateeksachan / gist:5283246
Created April 1, 2013 04:28
MDL-38765: Testing Instructions
1.Turn Editing ON
2.Click on any course.
3.Click on "Add an activity or resource"
4.Choose "Quiz" as the option. Click Add.
5.Fill up details for the Quiz. In the "Grade" options, specify a finite attempt value.
6.Add questions to the Quiz.
7.Log in as a student.
8.Take the quiz making all the attempts.
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
@prateeksachan
prateeksachan / solr-for-global-search.php
Last active December 18, 2015 05:59
gsoc-week-1-gist-1
<?php
$options = array( 'hostname' => 127.0.0.1 );
$client = new SolrClient($options, "4.0");
?>
<fieldType name="tint" class="solr.TrieIntField" precisionStep="8" positionIncrementGap="0"/>
<fieldType name="tfloat" class="solr.TrieFloatField" precisionStep="8" positionIncrementGap="0"/>
<fieldType name="tlong" class="solr.TrieLongField" precisionStep="8" positionIncrementGap="0"/>
<fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" positionIncrementGap="0"/>
[response] => SolrObject Object
(
[numFound] => 3
[start] => 0
[docs] => Array
(
[0] => SolrObject Object
(
[id] => 1
[title] => Array
$s = '';
$s.= '<add>';
for ($id = 1; $id <=1000; $id++){
$s.= '<doc>';
$s.= '<field name="id">' . $id . '</field>';
$s.= '<field name="courseid" update="set">2</field>';
$s.= '</doc>';
}
$s.= '</add>';
<?php
function mod_get_search_iterator($from = 0) {
global $DB;
$sql = "SELECT id, modified FROM {mod_table} WHERE modified >= ? ORDER BY modified ASC";
return $DB->get_recordset_sql($sql, array($from));
}
?>
<?php
foreach ($mods as $key => $name) {
set_config($name . '_indexingstart', 0, 'search');
set_config($name . '_indexingend', 0, 'search');
set_config($name . '_lastindexrun', 0, 'search');
set_config($name . '_docsignored', 0, 'search');
set_config($name . '_docsprocessed', 0, 'search');
set_config($name . '_recordsprocessed', 0, 'search');
}
?>
<?php
//get a chapter's records for each chapter id
$chapter = $DB->get_record('book_chapters', array('id' => $id), '*', MUST_EXIST);
//get book record for that chapter
$book = $DB->get_record('book', array('id' => $chapter->bookid), '*', MUST_EXIST);
$doc = new SolrInputDocument();
$doc->addField('id', 'book_' . $chapter->id);
$doc->addField('name', $book->name);
<?php
$url = search_curl_url(); // returns SOLR_SERVER_HOSTNAME . ':' . SOLR_SERVER_PORT . '/solr/update/extract?'
$url .= 'literal.id=' . 'forum_file_' . $id . '&literal.module=forum&literal.type=3&literal.courseid=' . $post->course;
$params = array();
$params[$id] = $file; // adds the $file stdClass object into $params array
$curl->post($url, $params); // sets CURLOPT_POST = 1
// sets CURLOPT_POSTFIELDS = array ($id => '@' . $filepath) via add_to_curl_request
// finally posts this curl request
?>