feedbackモジュールについて(item:multichoice/multichoicerated)

feedbackモジュールについて(item:multichoice/multichoicerated)

- Umeda Junichi の投稿
返信数: 0

少し用途に合せてfeedbackモジュールを編集していた所、下記の問題を発見しました。
1.9用のモジュールをダウンロードして編集しましたが、moodle 2.0で搭載のモジュールでも同じ様になっていました。

mod/feedback/item/multichocerated/lib.php 260行付近から
**************************************
function
get_info($item) {
    $presentation = empty($item->presentation) ? '' : $item->presentation;

    $info = new object();
    //check the subtype of the multichoice
    //it can be check(c), radio(r) or dropdown(d)

    $info->subtype = '';
    $info->presentation = '';
    $info->horizontal = false;
    @list($info->subtype, $info->presentation) = explode(FEEDBACK_MULTICHOICE_TYPE_SEP, $item->presentation);
    if(!isset($info->subtype)) {
        $info->subtype = 'r';
    }

    if($info->subtype != 'd') {
        @list($info->presentation, $info->horizontal) = explode(FEEDBACK_MULTICHOICE_ADJUST_SEP, $info->presentation);         
        if(isset($info->horizontal) AND $info->horizontal == 1) {
            $info->horizontal = true;
        }else {
     $info->horizontal = false;
        }
    }
    return $info;
}
**************************************
1.FEEDBACK_MULTICHOICE_TYPE_SEP/FEEDBACK_MULTICHOICE_ADJUST_SEP
はMultichoice用の定義の為、Multichoice Ratedの一部のみ変更すると動作しなくなる可能性があります。(変数の読込を追いかけきれてませんが、get_defined_constants()で確認した所、multichoice/lib.php、multichoicerated/lib.phpの両方で定義されている定数が読み込まれている為動作はしているようです・・・)

2.if(!isset($info->subtype))で$info->subtypeの初期値を設定している様にみえますが、実際のところその前で実行している@list~によって、変数が定義されていると見なされ、ifの中が実行されることはありません。(multichoice/lib.phpのget_info関数も同様)
(影響:subtype = d を標準とする様な変更が簡単に行えない)

変更後
**************************************
function
get_info($item) {
    $presentation =
empty($item->presentation) ? '' : $item->presentation;

    $info = new object();
    //check the subtype of the multichoice
    //it can be check(c), radio(r) or dropdown(d)

    $info->subtype = '';
    $info->presentation = '';
    $info->horizontal = false;
    @list($info->subtype, $info->presentation) = explode(FEEDBACK_MULTICHOICERATED_TYPE_SEP, $item->presentation);
    if(empty($info->subtype)) {
        $info->subtype = 'r';
    }

    if($info->subtype != 'd') {
        @list($info->presentation, $info->horizontal) = explode(FEEDBACK_MULTICHOICERATED_ADJUST_SEP, $info->presentation);         
        if(isset($info->horizontal) AND $info->horizontal == 1) {
            $info->horizontal = true;
        }else {
     $info->horizontal = false;
        }
    }
    return $info;
}
**************************************

その他(本当はこっちをやっていて、上の問題を発見したのですが・・・)

課題作成時、$info->horizontal=true(水平)をデフォルトにしようとしたところ、$info->horizontal=trueに設定されている場合以外は全てfalse(垂直)になる仕組みになっていました。
(垂直と設定した場合はパラメータも保存されていない)

multichoice/lib.php、multichoicerated/lib.php共通 get_presentation関数
(FEEDBACK_MULTICHOICERATED_ADJUST_SEPの部分は編集するlib.phpの定義にあわせる)
**************************************
function
get_presentation($data) {
  ・・・
    if(isset($data->horizontal) AND $data->horizontal == 1 AND $subtype != 'd')
        $present .= FEEDBACK_MULTICHOICERATED_ADJUST_SEP.'1';
   
}
    ・・・
}
**************************************

正しくパラメータを保存する為の変更
**************************************
function
get_presentation($data) {
  ・・・
    if(isset($data->horizontal) AND $data->horizontal == 1 AND $subtype != 'd')
        $present .= FEEDBACK_MULTICHOICERATED_ADJUST_SEP.'1';
   
}else{
        $present .= FEEDBACK_MULTICHOICERATED_ADJUST_SEP.'0';
    }
    ・・・
}

**************************************

上記の変更後、get_info関数で$info->horizontalの分岐を調整する事で垂直/水平の調整が可能になりました。