フォーラムに新規投稿や返信を行う際, 文書にタグをつける機能があります.
このタグを, 投稿者が手動でつけることなく自動で付与することは可能でしょうか?
イメージとしましては, 予めタグがいくつか用意されており, 文書内にタグと一致する文字列があった場合に投稿者が手動で設定しなくとも該当のタグが付与された状態で投稿される, といった感じです.
> このタグを, 投稿者が手動でつけることなく自動で付与することは可能でしょうか?
不可能ではないと思います。
もしかしたら、以下のプログラム修正でご希望の動きに近くなるのではないでしょうか。
------------------------------------------------
Moodleバージョン:
3.7.3 (Build: 20191111)
修正対象プログラム:
config.php
修正箇所:
28行目
[ 修正前 ]
require_once(__DIR__ . '/lib/setup.php');
// Some servers may need a special rewrite rule to work around internal path length limitations:
// RewriteRule (^.*/theme/yui_combo\.php)(/.*) $1?file=$2
// There is no php closing tag in this file,
// it is intentional because it prevents trailing whitespace problems!
[ 修正後 (例) ]
require_once(__DIR__ . '/lib/setup.php');
$CFG->forum_post_tags = array (
'English001' => 'E001',
'English002' => 'E002',
'日本語001' => '日001',
'日本語002' => '日002',
);
// Some servers may need a special rewrite rule to work around internal path length limitations:
// RewriteRule (^.*/theme/yui_combo\.php)(/.*) $1?file=$2
// There is no php closing tag in this file,
// it is intentional because it prevents trailing whitespace problems!
------------------------------------------------
修正対象プログラム:
mod/forum/lib.php
修正箇所:
3110行目
[ 修正前 ]
function forum_add_new_post($post, $mform, $unused = null) {
global $USER, $DB;
[ 修正後 ]
function forum_add_new_post($post, $mform, $unused = null) {
global $USER, $CFG, $DB;
-------------
修正箇所:
3142行目
[ 修正前 ]
if (!isset($post->mailnow)) {
$post->mailnow = 0;
}
$post->id = $DB->insert_record("forum_posts", $post);
[ 修正後 ]
if (!isset($post->mailnow)) {
$post->mailnow = 0;
}
$default_tags = $CFG->forum_post_tags;
foreach ($default_tags as $key=>$val) {
$pos = 0;
if (function_exists('mb_strpos')) {
$pos = mb_strpos($post->message, $key);
} else {
$pos = strpos($post->message, $key);
}
if ($pos > 0) {
$post->tags[] = $val;
};
}
$post->id = $DB->insert_record("forum_posts", $post);
-------------
修正箇所:
3292行目
[ 修正前 ]
$discussion->firstpost = $post->id;
$discussion->timemodified = $timenow;
$discussion->usermodified = $post->userid;
$discussion->userid = $userid;
$discussion->assessed = 0;
$post->discussion = $DB->insert_record("forum_discussions", $discussion);
[ 修正後 ]
$discussion->firstpost = $post->id;
$discussion->timemodified = $timenow;
$discussion->usermodified = $post->userid;
$discussion->userid = $userid;
$discussion->assessed = 0;
$default_tags = $CFG->forum_post_tags;
foreach ($default_tags as $key=>$val) {
$pos = 0;
if (function_exists('mb_strpos')) {
$pos = mb_strpos($discussion->message, $key);
} else {
$pos = strpos($discussion->message, $key);
}
if ($pos > 0) {
$discussion->tags[] = $val;
};
}
$post->discussion = $DB->insert_record("forum_discussions", $discussion);
------------------------------------------------
ありがとうございます。
まず、Apacheのドキュメントルートを探してください。
例)
# grep -i 'DocumentRoot' /etc/httpd/conf/httpd.conf
# DocumentRoot: The directory out of which you will serve your
DocumentRoot "/var/www/html"
# access content that does not live under the DocumentRoot.
次に「find」コマンドを使って設定ファイル (config.php) およびフォーラムディレクトリ (/mod/forum) の場所を探してください。上のドキュメントルートの例の場合、以下のコマンドでファイルおよびディレクトリを探せます。
例)
# find /var/www/html -name config.php
/var/www/html/moodle/config.php
# find /var/www/html -name 'forum' -type d
/var/www/html/moodle/mod/forum
------------------------------------------------
Moodleバージョン:
3.7.3 (Build: 20191111)
修正対象プログラム:
config.php
修正箇所:
28行目
[ 修正前 ]
require_once(__DIR__ . '/lib/setup.php');
// Some servers may need a special rewrite rule to work around internal path length limitations:
// RewriteRule (^.*/theme/yui_combo\.php)(/.*) $1?file=$2
// There is no php closing tag in this file,
// it is intentional because it prevents trailing whitespace problems!
[ 修正後 (例) ]
require_once(__DIR__ . '/lib/setup.php');
$CFG->forum_post_tags = array (
'English001' => 'E001',
'English002' => 'E002',
'日本語001' => '日001',
'日本語002' => '日002',
);
// Some servers may need a special rewrite rule to work around internal path length limitations:
// RewriteRule (^.*/theme/yui_combo\.php)(/.*) $1?file=$2
// There is no php closing tag in this file,
// it is intentional because it prevents trailing whitespace problems!
------------------------------------------------
修正対象プログラム:
mod/forum/lib.php
修正箇所:
3110行目
[ 修正前 ]
function forum_add_new_post($post, $mform, $unused = null) {
global $USER, $DB;
[ 修正後 ]
function forum_add_new_post($post, $mform, $unused = null) {
global $USER, $CFG, $DB;
-------------
修正箇所:
3142行目
[ 修正前 ]
if (!isset($post->mailnow)) {
$post->mailnow = 0;
}
$post->id = $DB->insert_record("forum_posts", $post);
[ 修正後 ]
if (!isset($post->mailnow)) {
$post->mailnow = 0;
}
$default_tags = $CFG->forum_post_tags;
foreach ($default_tags as $key=>$val) {
$pos = 0;
if (function_exists('mb_strpos')) {
$pos = mb_strpos($post->message, $key);
} else {
$pos = strpos($post->message, $key);
}
if ($pos > 0) {
$post->tags[] = $val;
}
}
$post->id = $DB->insert_record("forum_posts", $post);
-------------
修正箇所:
3292行目
[ 修正前 ]
$discussion->firstpost = $post->id;
$discussion->timemodified = $timenow;
$discussion->usermodified = $post->userid;
$discussion->userid = $userid;
$discussion->assessed = 0;
$post->discussion = $DB->insert_record("forum_discussions", $discussion);
[ 修正後 ]
$discussion->firstpost = $post->id;
$discussion->timemodified = $timenow;
$discussion->usermodified = $post->userid;
$discussion->userid = $userid;
$discussion->assessed = 0;
$default_tags = $CFG->forum_post_tags;
foreach ($default_tags as $key=>$val) {
$pos = 0;
if (function_exists('mb_strpos')) {
$pos = mb_strpos($discussion->message, $key);
} else {
$pos = strpos($discussion->message, $key);
}
if ($pos > 0) {
$discussion->tags[] = $val;
}
}
$post->discussion = $DB->insert_record("forum_discussions", $discussion);
------------------------------------------------
大変失礼しました。
これはタグ付けの条件をフォーラム内のみに限定するため、データベースは使わずに代わりにMoodle設定ファイル (config.php) に条件を記述しております。
例えば、Moodle設定ファイル (config.php) の以下の記述例の場合、フォーラム投稿内に「English001」とい文字が入力された場合、タグ「E001」が自動的に付加されます。同じく「日本語001」という文字が入力された場合、タグ「日001」が自動的に付加されます。
$CFG->forum_post_tags = array (
'English001' => 'E001',
'English002' => 'E002',
'日本語001' => '日001',
'日本語002' => '日002',
);
大変お手数ですが、「サイト管理/アピアランス/タグを管理する/デフォルトコレクション」で標準タグを追加する代わりにMoodle設定ファイル (config.php) 内にタグ付けの条件を記述してください。記述にあたりまして、文字コードはUTF-8を指定してください。