Moodle二次開發(1)-- 微創新

Moodle二次開發(1)-- 微創新 

[複製連接]
Moodle版本:2.1

一、用戶登陸後導向到個人主頁

在Moodle中遍尋不到這個設置,我記得在2.3版本好像有。沒辦法只有仔細了看了下代碼。發現 login/index.php中有段代碼比較合符要求。
  1.     /// Go to my-moodle page instead of site homepage if defaulthomepage set to homepage_my
  2.         if (!empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_MY && !is_siteadmin() && !isguestuser()) {
  3.             if ($urltogo == $CFG->wwwroot or $urltogo == $CFG->wwwroot.'/' or $urltogo == $CFG->wwwroot.'/index.php') {
  4.                 $urltogo = $CFG->wwwroot.'/my/';
  5.             }
  6.         }
複製代碼
其中「defaulthomepage」這個單詞引發了個人注意,靈機一動,到數據庫中配置表「mdl_config」中搜了下,竟然發現了這個配置參數,默認值是0,將它修改爲1。

登陸後正常進入「個人主頁」。功能實現。


二、普通用戶在個人主頁中沒法返回網站首頁

這個問題是上一個問題引發的,若使用管理員賬號登陸,能正常回到首頁,當是不能對首頁再進行編輯;如果普通用戶,根本就沒有權限回首頁了。悲催的規則,沒搞明白是Moodle的bug,仍是我沒配置對。

處理的方式很簡單,就是把「網站首頁」先屏蔽吧。在lib目錄下找到navigationlib.php,在函數initialise中有一段代碼。
  1.         if (get_home_page() == HOMEPAGE_SITE) {
  2.             // The home element should be my moodle because the root element is the site
  3.             if (isloggedin() && !isguestuser()) {  // Makes no sense if you aren't logged in
  4.                 $this->rootnodes['home'] = $this->add(get_string('myhome'), new moodle_url('/my/'), self::TYPE_SETTING, null, 'home');
  5.             }
  6.         } else {
  7.             // The home element should be the site because the root node is my moodle
  8.             $this->rootnodes['home'] = $this->add(get_string('sitehome'), new moodle_url('/'), self::TYPE_SETTING, null, 'home');
  9.             if ($CFG->defaulthomepage == HOMEPAGE_MY) {
  10.                 // We need to stop automatic redirection
  11.                 $this->rootnodes['home']->action->param('redirect', '0');
  12.             }
  13.         }
複製代碼
將else語句後面的屏蔽掉吧。算是解決一個問題,功能完成。

三、成員列表中,屏蔽按字母搜索

在課程中,有個成員列表,其中的按字母搜索比較的有趣。爲了避免讓它妨礙使用的心情,決定把它先屏蔽掉。

在lib目錄下,其中有個tablelib.php,其中有段代碼。
  1.     /**
  2.      * This function is not part of the public api.
  3.      */
  4.     function print_initials_bar() {
  5.        /* if ((!empty($this->sess->i_last) || !empty($this->sess->i_first) ||$this->use_initials)
  6.                     && isset($this->columns['fullname'])) {
  7.             $alpha  = explode(',', get_string('alphabet', 'langconfig'));
  8.             // Bar of first initials
  9.             if (!empty($this->sess->i_first)) {
  10.                 $ifirst = $this->sess->i_first;
  11.             } else {
  12.                 $ifirst = '';
  13.             }
  14.             $this->print_one_initials_bar($alpha, $ifirst, 'firstinitial',
  15.                     get_string('firstname'), $this->request[TABLE_VAR_IFIRST]);
  16.             // Bar of last initials
  17.             if (!empty($this->sess->i_last)) {
  18.                 $ilast = $this->sess->i_last;
  19.             } else {
  20.                 $ilast = '';
  21.             }
  22.             $this->print_one_initials_bar($alpha, $ilast, 'lastinitial',
  23.                     get_string('lastname'), $this->request[TABLE_VAR_ILAST]);
  24.         }*/
  25.     }
複製代碼
如上屏蔽掉它裏面的代碼,再次刷新頁面,功能完成。


四、屏蔽資源、活動中不要的選項

在課程中,添加活動或資源時,有不少選項,好比什麼SCORM、IMS這些,平時基本不用,太專業了。如何把它屏蔽掉呢?

開始想法是改代碼,後來發現一個好辦法,就是把這些插件卸載掉。Moodle在這方面作得比較好,大部分東西都是插件的形式,不像我常常動不動就考慮改代碼,改結構,差了不是一個檔次啊。

卸載了相應插件後,還須要把對應目錄所有刪除,不然登陸後沒法正常訪問,老是提示你插件安裝不全,須要升級。


(轉自:http://blog.csdn.net/36/article/details/8185606)
相關文章
相關標籤/搜索