OSDN Git Service

DB更新スクリプト更新。
[magic3/magic3.git] / widgets / m / quizk / include / container / m_quizkCompleteWidgetContainer.php
1 <?php
2 /**
3  * index.php用コンテナクラス
4  *
5  * PHP versions 5
6  *
7  * LICENSE: This source file is licensed under the terms of the GNU General Public License.
8  *
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_quizkCompleteWidgetContainer.php 1933 2009-05-28 10:54:45Z fishbone $
14  * @link       http://www.magic3.org
15  */
16 require_once($gEnvManager->getCurrentWidgetContainerPath() .    '/m_quizkBaseWidgetContainer.php');
17 require_once($gEnvManager->getCurrentWidgetDbPath() .   '/quizkDb.php');
18
19 class m_quizkCompleteWidgetContainer extends m_quizkBaseWidgetContainer
20 {
21         private $db;    // DB接続オブジェクト
22         private $setId;                         // 定義セットID
23         const CFG_DEFAULT_SET_ID_KEY = 'current_set_id';                // 現在の選択中のセットID取得用キー
24         
25         /**
26          * コンストラクタ
27          */
28         function __construct()
29         {
30                 // 親クラスを呼び出す
31                 parent::__construct();
32                 
33                 // DBオブジェクト作成
34                 $this->db = new quizkDb();
35         }
36         /**
37          * テンプレートファイルを設定
38          *
39          * _assign()でデータを埋め込むテンプレートファイルのファイル名を返す。
40          * 読み込むディレクトリは、「自ウィジェットディレクトリ/include/template」に固定。
41          *
42          * @param RequestManager $request               HTTPリクエスト処理クラス
43          * @param object         $param                 任意使用パラメータ。そのまま_assign()に渡る
44          * @return string                                               テンプレートファイル名。テンプレートライブラリを使用しない場合は空文字列「''」を返す。
45          */
46         function _setTemplate($request, &$param)
47         {       
48                 return 'complete.tmpl.html';
49         }
50         /**
51          * テンプレートにデータ埋め込む
52          *
53          * _setTemplate()で指定したテンプレートファイルにデータを埋め込む。
54          *
55          * @param RequestManager $request               HTTPリクエスト処理クラス
56          * @param object         $param                 任意使用パラメータ。_setTemplate()と共有。
57          * @param                                                               なし
58          */
59         function _assign($request, &$param)
60         {
61                 $this->setId = $this->db->getConfig(self::CFG_DEFAULT_SET_ID_KEY);              // パターンセットID
62                 $ret = $this->db->getAnswerResult($this->setId, $this->mobileId, $rows);
63                 if ($ret){
64                         $totalCount = count($rows);
65                         $rightCount = 0;
66                         for ($i = 0; $i < $totalCount; $i++){
67                                 if ($rows[$i]['qp_result']) $rightCount++;
68                         }
69                         $resutlStr = $totalCount . '問中&nbsp;' . $rightCount . '問正解';
70                         $resutlRatioStr = '正解率&nbsp;0%';
71                         if ($totalCount > 0) $resutlRatioStr = '正解率&nbsp;' . sprintf("%01.1f", round($rightCount / $totalCount * 100, 1)) . '%';
72                         $this->tmpl->addVar('_widget', 'result', $resutlStr);
73                         $this->tmpl->addVar('_widget', 'result_ratio', $resutlRatioStr);
74                 }
75                 $this->tmpl->addVar('_widget', 'top_url', $this->gEnv->createCurrentPageUrlForMobile(''));
76         }
77 }
78 ?>