7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
9 * @package Magic3 Framework
10 * @author 平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11 * @copyright Copyright 2006-2009 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: m_quizkProgressWidgetContainer.php 1933 2009-05-28 10:54:45Z fishbone $
14 * @link http://www.magic3.org
16 require_once($gEnvManager->getCurrentWidgetContainerPath() . '/m_quizkBaseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() . '/quizkDb.php');
19 class m_quizkProgressWidgetContainer extends m_quizkBaseWidgetContainer
21 private $db; // DB接続オブジェクト
22 private $setId; // 定義セットID
23 const CFG_DEFAULT_SET_ID_KEY = 'current_set_id'; // 現在の選択中のセットID取得用キー
24 const CURRENT_TASK = 'progress'; // 現在の画面
25 const NEXT_TASK = 'complete'; // 次の画面
30 function __construct()
33 parent::__construct();
36 $this->db = new quizkDb();
41 * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
42 * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
44 * @param RequestManager $request HTTPリクエスト処理クラス
45 * @param object $param 任意使用パラメータ。そのまま_assign()に渡る
46 * @return string テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
48 function _setTemplate($request, &$param)
50 return 'progress.tmpl.html';
55 * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
57 * @param RequestManager $request HTTPリクエスト処理クラス
58 * @param object $param 任意使用パラメータ。_setTemplate()と共有。
61 function _assign($request, &$param)
63 $this->setId = $this->db->getConfig(self::CFG_DEFAULT_SET_ID_KEY); // パターンセットID
64 $act = $request->trimValueOf('act');
66 if ($act == 'answer'){ // 回答したとき
67 $postSetId = $request->trimValueOf('sid');
68 $questionId = $request->trimValueOf('qid');
69 $answer = $request->trimValueOf('answer');
72 $isErr = false; // エラー発生状況
73 $isRight = false; // 正解かどうか
74 $ret = $this->db->getItem($postSetId, $questionId, $row);
76 if ($row['qd_type'] != 0) $isErr = true; // エラー発生状況
77 $answerId = $row['qd_answer_id'];
79 $isErr = true; // エラー発生状況
82 if (strcmp($answerId, $answer) == 0) $isRight = true; // 正解かどうか
84 $logSerial = $this->gEnv->getCurrentAccessLogSerial();
85 $ret = $this->db->addPostData($this->mobileId, $postSetId, $questionId, $answer, $isRight, $logSerial);
86 if (!$ret) $isErr = true;
90 $ret = $this->db->getItem($postSetId, $answerId, $row);
97 $this->tmpl->setAttribute('result_msg', 'visibility', 'visible');
99 $this->tmpl->setAttribute('result_area', 'visibility', 'visible');
100 $this->tmpl->addVar("result_area", "result", $result);
101 $this->tmpl->addVar("result_area", "title", $row['qd_title']);
102 $this->tmpl->addVar("result_area", "content", $row['qd_content']);
109 $ret = $this->db->getNextQuestion($this->setId, $this->mobileId, $row);
110 if ($ret){ // 問題が残っているとき
111 $this->tmpl->addVar("result_area", "next_name", '次へ');
112 $this->tmpl->addVar('result_area', 'next_url', $this->gEnv->createCurrentPageUrlForMobile('task=' . self::CURRENT_TASK));
114 $this->tmpl->addVar("result_area", "next_name", '終了');
115 $this->tmpl->addVar('result_area', 'next_url', $this->gEnv->createCurrentPageUrlForMobile('task=' . self::NEXT_TASK));
120 $message = sprintf(self::ERR_MESSAGE_FORMAT, 'エラーが発生しました');
121 $this->tmpl->addVar("_widget", "message", $message);
125 $ret = $this->db->getNextQuestion($this->setId, $this->mobileId, $row);
126 if ($ret){ // 問題が残っているとき
127 $this->tmpl->setAttribute('question_area', 'visibility', 'visible');
130 $this->createQuestion($row);
131 } else { // 次の問題がないとき
132 $count = $this->db->getQuestionCount($this->setId);
134 $message = '問題が登録されていません';
136 $message = '全問回答しました';
138 $this->tmpl->addVar("_widget", "message", $message);
139 $this->tmpl->setAttribute('view_status_area', 'visibility', 'visible');
142 $this->tmpl->addVar('question_area', 'act', 'answer');
143 $this->tmpl->addVar('question_area', 'url', $this->gEnv->createCurrentPageUrlForMobile('task=' . self::CURRENT_TASK));
144 $this->tmpl->addVar('_widget', 'top_url', $this->gEnv->createCurrentPageUrlForMobile(''));
145 $this->tmpl->addVar('_widget', 'start_url', $this->gEnv->createCurrentPageUrlForMobile('task=' . self::NEXT_TASK));
150 * @param array $row クイズ問題項目レコード
153 function createQuestion($row)
155 $answer = $row['qd_select_answer_id']; // 回答ID
156 $answerArray = array();
157 if (!empty($answer)) $answerArray = explode(';', $answer);
160 $title = $this->convertToDispString($row['qd_title']);
161 $content = $this->convertToDispString($row['qd_content']);
162 $this->tmpl->addVar('question_area', 'title', $title);
163 $this->tmpl->addVar('question_area', 'content', $content);
164 $this->tmpl->addVar('question_area', 'sid', $this->setId);
165 $this->tmpl->addVar('question_area', 'qid', $this->convertToDispString($row['qd_id']));
167 if (count($answerArray) == 0) return;
170 $ret = $this->db->getAnswers($this->setId, $answerArray, $rows);
173 for ($i = 0; $i < count($rows); $i++){
174 $title = $this->convertToDispString($rows[$i]['qd_title']);
175 $value = $this->convertToDispString($rows[$i]['qd_id']);
176 $inputTag .= '<input type="radio" name="answer" value="' . $value . '" />' . $title . '<br />' . M3_NL;
178 $this->tmpl->addVar('question_area', 'answer', $inputTag);