-
Notifications
You must be signed in to change notification settings - Fork 6
/
block_course_search.php
101 lines (88 loc) · 3.16 KB
/
block_course_search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
* *************************************************************************
* * OOHOO - Course Search **
* *************************************************************************
* @package block **
* @subpackage coursesearch **
* @name Course Search **
* @copyright oohoo.biz **
* @link http://oohoo.biz **
* @author Patrick Thibaudeau **
* @author Nicolas Bretin **
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **
* *************************************************************************
* ************************************************************************ */
class block_course_search extends block_base
{
/**
* Init the block
*/
function init()
{
$this->title = get_string('pluginname', 'block_course_search');
}
/**
* Applicable formats
* @return array
*/
function applicable_formats()
{
return array('all' => true);
}
/**
*
* @return boolean
*/
function instance_allow_multiple()
{
return false;
}
/**
* Return the content
* @global stdClass $CFG
* @return string
*/
function get_content()
{
global $CFG;
require_once($CFG->dirroot . '/course/lib.php');
$course = $this->page->course;
if ($this->content !== NULL)
{
return $this->content;
}
$this->content = new stdClass;
if(class_exists('context_course'))
{
$context = context_course::instance($course->id);
}
else
{
$context = get_context_instance(CONTEXT_COURSE, $course->id);
}
$this->content->footer = ' ';
$text = "<div class=\"searchform\">";
$text .= "<form style='display:inline;' name='course_search_form' id='block_course_search_form' action='$CFG->wwwroot/blocks/course_search/results.php' method='post'>";
$text .= "<fieldset class=\"invisiblefieldset\">";
$text .= get_string('searchfor', 'block_course_search') . "<br>";
$text .= "<input type='hidden' name='courseid' id='courseid' value='$course->id'/>";
$text .= "<input type='text' name='q' id='q' value=''/>";
$text .= "<br><input type='submit' id='searchform_button' value='" . get_string('submit', 'block_course_search') . "'>";
$text .= "</fieldset>";
$text .= "</form>";
$text .= "</div>";
$this->content->text = $text;
return $this->content;
}
/**
* The block should only be dockable when the title of the block is not empty
* and when parent allows docking.
*
* @return bool
*/
public function instance_can_be_docked()
{
return (!empty($this->title) && parent::instance_can_be_docked());
}
}