網頁

2011年11月28日 星期一

Moodle mod



Moodle开发笔记7-Activity module开发


Newmodule Template Code


Download for Moodle 1.9


發生修改完平台網頁無法顯示中文連結,這時候可以嘗試下面解決方案;

1.使用編輯器修改完畢,將修改檔案格式改為utf8

這樣就可以支援顯示中文!

Development:lib/formslib.php Form Definition

mod_form.php

$mform->addElement('date_time_selector', 'timeopen', get_string('quizopen', 'quiz'), array('optional'=>true)); $mform->setHelpButton('timeopen', array('timeopen', get_string('quizopen', 'quiz'), 'quiz'));

 C:\AppServ\www\moodle19\lang\en_utf8\help\quiz\timeopen.html



mod_form.php 到 view.php

資料庫的對應表 `mdl_course_modules`


Moodle插件开发笔记12: Database操作(二)






get_field_select($table, $return, $select)
  

$select = "action='login' order by id desc limit 1";
$login_userid = get_field_select('log', 'userid', $select); //取得moodle記錄檔login登入的使用者最新一筆
echo $login_userid ;
get_field_sql($sql)
  
$sql = "select userid from mdl_log where action='login' order by id desc limit 1";
$login_userid = get_field_sql($sql); //取得moodle記錄檔login登入的使用者最新一筆
echo $login_userid ;
get_records_select($table, $select='', $sort='', $fields='*', $limitfrom='', $limitnum='')
  

 //get_records_select($table, $select='', $sort='', $fields='*', $limitfrom='', $limitnum='')
 $action = get_records_select("log","userid=2","id ASC");
 //table_column("id", "time", "userid", "ip", "course", "module", "cmid", "action", "url", "info");
  if(!empty($action)) {
    foreach ($action as $value) {
     echo  "admin in ".$value->module." : ";
     echo  $value->action."
"; } }
老師與課程相對應的欄位(輸入老師帳號密碼,查出所屬課程)
  


require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/lib.php');
   
   mysql_query("SET NAMES 'utf-8'"); 
   
   $moodle_course_id =2;
   $select = "courseid='$moodle_course_id' order by timeaccess desc limit 1"; 
   $login_userid = get_field_select('user_lastaccess', 'userid', $select);
   $moodle_teacher_username = get_field('user', 'username', 'id', $login_userid); 
   
   echo "
最後一位作用的使用者:".$moodle_teacher_username ;
   
   
   
   $user = $moodle_teacher_username ;// teacher_name
   
   $sql = "select mdl_course.fullname FROM mdl_course, mdl_context , mdl_role_assignments, mdl_user
   where mdl_context.instanceid = mdl_course.id and 
   mdl_context.id=mdl_role_assignments.contextid and 
   mdl_role_assignments.userid=mdl_user.id and
   mdl_role_assignments.roleid=3 and
   mdl_user.username='$user'
   order by mdl_course.id  desc limit 1";   
   $course_fullname = get_field_sql($sql);
 
   
   echo "
與".$user."對應的課程名稱(老師才會顯示):".$course_fullname ;


SELECT mdl_course.id, mdl_course.fullname
FROM `mdl_role_assignments` ,  `mdl_context`, `mdl_course`,`mdl_user`
where mdl_context.instanceid=mdl_course.id and 
mdl_context.id=mdl_role_assignments.contextid and 
mdl_role_assignments.userid=mdl_user.id and
mdl_role_assignments.roleid=3 and
mdl_user.username="tea01"and mdl_user.password =md5("abc123")
order by mdl_course.id



update_record()


$data = new stdClass;
$data->id = '666';
$data->othercolumn = $newvalue;
$res = $this->datalib->update_record('tablename', $data);





mod_form.php 傳值給 lib.php 
mod_form.php a form to set up or update an instance of this module



class mod_newmodule_mod_form extends moodleform_mod {
..
$mform->addElement('text', 'name', get_string('newmodulename', 'newmodule'), array('size'=>'64'));
}
...
 
lib.php - any/all functions defined by the module should be in here.
function newmodule_add_instance($newmodule) {

  
$newmodule_name=  $newmodule->name; //mform name的值
}
 

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。