III. MOODLE TIZIMIDA DASTURIY KOMPONENTA (PLAGIN) YARATISH VA O’RNATISH Moodle tizimi uchun PHP tilida plagin yaratish texnologiyasi.
LMS moodle tizimida plagin yaratish uchun albatta php texnologiyasidan foydalaniladi shu uchun biz quyidagi php kodlar asosida LMS moodle tizimida plaginni qanday yaratishni ko’rib chiqamiz:
class block_graph_stats extends block_base {
/*
* Standard block API function for initializing block instance
* @return void
*/
public function init() {
$this->title = get_string('blockname', 'block_graph_stats');
}
public function has_config() {
return true;
}
public function instance_allow_config() {
return true;
}
public function instance_allow_multiple() {
return false;
}
public function applicable_formats() {
return array(
'site' => true,
'course-view' => true);
}
public function get_required_javascript() {
parent::get_required_javascript();
$this->page->requires->jquery();
}
public function get_content() {
global $CFG, $COURSE, $USER, $DB;
if ($this->content !== null) {
return $this->content;
}
/*
* number of day for the graph
* @var int
*/
$daysnb = 30;
$daysnb = $CFG->daysnb;
$this->content = new stdClass;
$this->content->text = '';
$this->content->footer = '';
include_once('graph_google.php');
$this->content->text .= graph_google($COURSE->id, get_string('graphtitle', 'block_graph_stats', $daysnb));
// Add a link to course report for today.
if (has_capability('report/log:view', context_course::instance($COURSE->id))) {
$this->content->text .= html_writer::start_tag('div' , array('class' => 'moredetails'));
$this->content->text .= html_writer::link(new moodle_url('/blocks/graph_stats/details.php?course_id=' .
$COURSE->id), get_string('moredetails', 'block_graph_stats') ,
array('title' => get_string('moredetails', 'block_graph_stats')));
$this->content->text .= html_writer::end_tag('div');
}
// Add some details in the footer.
if ($COURSE->id > 1) {
// In a course.
$params = array('time' => mktime(0, 0, 0, date("m") , date("d"), date("Y")), 'course' => $COURSE->id);
$sql = "SELECT COUNT(DISTINCT(userid)) as countid FROM {log}
WHERE time > :time AND action = 'view' AND course = :course ";
$connections = $DB->get_record_sql($sql , $params);
$this->content->footer .= get_string('connectedtoday', 'block_graph_stats') . $connections->countid;
} else {
// In the front page.
$params = array('time' => mktime(0, 0, 0, date("m") , date("d"), date("Y")));
$sql = "SELECT COUNT(userid) as countid FROM {log} WHERE time > :time AND action = 'login' ";
$connections = $DB->get_record_sql($sql, $params);
$this->content->footer .= get_string('connectedtoday', 'block_graph_stats') . $connections->countid;
$users = $DB->get_records('user', array('deleted' => 0, 'confirmed' => 1));
$courses = $DB->get_records('course', array('visible' => 1));
$this->content->footer .= '
'.get_string('membersnb', 'block_graph_stats') . count($users);
$this->content->footer .= '
'.get_string('coursesnb', 'block_graph_stats') . count($courses);
}
return $this->content;
}}
Do'stlaringiz bilan baham: |