第四章 結論及網站程式碼
第二節 數學素養評量網站程式碼
此節附上網站程式碼,網站主要分層為:「model」、「controls」、
「views」,「views」顯示部分分為:
「categories」:章節列表。
「category」:單元題組列表。
「detail」:進入單一題組資訊。
「exam」:題目作答的主頁面。
「results」:整體答題紀錄。
「result」:單次評量的詳細統計紀錄及參考答案。
「user」:針對該位使用者答過題組的紀錄。
網頁撰寫內容常用文字用””COM_EXAMS_XXXXX”存取在 Server 端,以語 言覆蓋的方式使用,可以在網站想要整體改某個敘述時,可以至後端網站直接
修改「語言覆蓋」,達到統一修改的結果,對於網站管理者非常便利與迅速,而
以下簡單介紹的原始程式碼,以利有興趣的讀者參考。
一、 categories
主要有兩個檔案,分別為 default.php、default_items.php,前者主要為
「章節」分類的框架,後者為由資料庫內容抓出來「章節」顯示在前者框架中 的資料。
1. default.php 程式碼
47
<div class="exams_wrapper">
<div id="exams_header">
<!—是否要顯示 head—>
<?php if ($this->params->get('show_page_heading', 1)) : ?>
<!—判斷是否有抓到 head—>
<?php if (!is_null($this->params->get('page_heading'))):?>
<h2>
<!—如果有抓到 head,顯示 head—>
<?php echo $this->escape($this->params->get('page_heading')); ?>
</h2>
<?php else:?>
<h2>
<!—如果沒抓到,抓此頁標題—>
<?php echo $this->escape($this->params->get('page_title')); ?>
</h2>
<?php endif;?>
<?php endif; ?>
</div>
<!—嵌入式網頁(default_item) —>
<?php echo $this->loadTemplate('items');?>
</div>
2. default_item.php 程式碼
<div style="display:table;border-collapse:collapse">
48
<div style="width:100$;display:row;border:solid 1px #99F ">
<div style="width:300px;display:table-cell;text-align:left">
<h3>章節</h3>
</div>
<div style="width:600px;display:table-cell;text-align:left">
<h3>章節內容</h3>
</div>
<div style="width:250px;display:table-cell;text-align:left">
<h3>題目數量</h3>
</div>
</div>
<!—迴圈抓所有的章節—>
<?php foreach ($this->category_list as $category):?>
<!—抓使用者權限是否可以瀏覽—>
<?php $user_access_levels = JFactory::getUser()->
getAuthorisedViewLevels();?>
<!—如果權限可以瀏覽則顯示—>
<?php if (in_array($category->access, $user_access_levels)):?>
<div style="width:100$;display:row;border:solid 1px #99F ">
<div style="width:300px;display:table-cell;text-align:left">
<h3>
<!—顯示該章節所有單元的連結 (超連結至下一層網頁,並傳送點選的 category id 至下一頁)—>
49
<a href="<?php echo
JRoute::_(examsHelper_exams::getCategoryLink($category->
id));?>" rel="nofollow"><?php echo $category->title?></a>
</h3>
</div>
<div style="width:600px;display:table-cell;text-align:left">
<!—顯示章節內容—>
<h4><?php $clean_text = JHtml::_('string.truncate', strip_tags($category->description),400);?>
<?php echo $clean_text;?></h4>
</div>
<div style="width:250px;display:table-cell;text-align:left">
<!—顯示題目數量—>
<p><?php /*?><?php echo
JText::_('COM_EXAMS_NUMBER_OF_EXAMS');?><?php */?><?php echo
$category->exam_count;?></p>
</div>
</div>
<?php endif;?>
<?php endforeach;?> </div>
二、 category
主要有兩個檔案,分別為 default.php、default_items.php,前者主要為 主選單「主題」的框架,後者為由資料庫內容抓出來「主題」顯示在前者框架 中的資料。
50
1. default.php 程式碼:
<div class="exams_wrapper">
<div id="exams_header">
<!—是否要顯示 head—>
<?php if ($this->params->get('show_page_heading', 1)) : ?>
<!—判斷是否有抓到 head—>
<?php if (!is_null($this->params->get('page_heading'))):?>
<h2>
<!—如果有抓到 head,顯示 head—>
<h2>
<?php echo $this->escape($this->params->get('page_heading')); ?>
</h2>
<?php else:?>
<h2>
<!—顯示主標題—>
<?php echo $this->category->title;?>
</h2>
<?php endif;?>
<?php endif; ?>
</div>
<div style="clear:both;"></div>
<!--<div class="exams_main_description">
<!—於第一格顯是章節主題敘述-->
<?php echo $this->category->description;?>
51
</div>-->
<div style="clear:both;"></div>
<?php if($this->exam_list != null):?>
<!—讀取嵌入式網頁 -->
<?php echo $this->loadTemplate('items');?>
<?php else:?>
<!—偵錯,如沒有任何資料時顯示網頁-->
<div><?php echo JText::_('COM_
EXAMS_NO_RECORDS_FOUND');?></div>
<?php endif;?>
</div>
2. default_items.php 程式碼
<div style="width:100%;display:table;border-collapse:collapse">
<div style="width:100$;display:row;border:solid 1px #99F ">
<div style="width:250px;display:table-cell;
text-align:left">
<h5>主題</h5>
</div>
<div style="width:600px;display:table-cell;
text-align:left">
<h5>評量目標</h5>
</div>
</div>
52
<!—抓該章節所有的題組出來—>
<?php foreach ($this->exam_list as $exam):?>
<div style="width:100$;display:row;border:solid 1px #99F ">
<div style="width:250px;display:table-cell;text-align:left">
<h3>
<!—顯示題組標題—>
<a href="<?php echo
JRoute::_(examsHelper_exams::getDetailsLink($exam->id));?>"
rel="nofollow"><?php echo $exam->title?></a>
</h3>
</div>
<div style="width:600px;display:table-cell;text-align:left">
<!—顯示題組內容敘述—>
<h4><?php $clean_text = JHtml::_('string.truncate', strip_tags($exam->description),400);?>
<?php echo $clean_text;?></h4>
</div>
</div>
<a href="<?php echo
JRoute::_( examsHelperexams::getDetailsLink($exam->
id));?>" class="button" rel="nofollow"><?php echo JText::_('COM_EXAMS_READ_MORE');?></a>
<?php endforeach;?>
三、 detail
53
主要有四個檔案,,此四個檔案分別為:
default.php:主頁框架顯示題組名稱
default_details.php:顯示該題組的相關規定,如:作答時間、重複作 答、是否電腦閱卷等。
default_error.php:如果資料錯誤,則顯示此頁。
default_navigation.php:產生可以作答的連結、作答記錄等。
此類檔案為作答前顯示給使用者的資訊,按下確定後開始作答。
1. default.php 程式碼
<div class="exams_wrapper">
<!—如果沒有抓到對應的題組,則顯示錯誤網頁—>
<?php if (!$this->exam->hasSettings()):?>
<?php echo $this->loadTemplate('error');?>
<?php else:?>
<div id="exams_header">
<?php if ($this->params->get('show_page_heading', 1)) : ?>
<?php if (!is_null($this->params->get('page_heading'))):?>
<h2>
<?php echo $this->escape($this->params->
get('page_heading')); ?>
</h2>
<?php else:?>
<h2>
<?php echo $this->exam->getSetting('title');?>
54
</h2>
<?php endif;?>
<?php endif; ?>
</div>
<!—如果設定有顯示此題組設定的細節內容,則顯示,若無則不顯示—>
<?php if($this->params->get('showDetails')):?>
<?php echo $this->loadTemplate('details');?>
<?php endif;?>
<div class="exams_main_description">
<h2>
<!—顯示此題組敘述及標題—>
<?php /*?><?php echo $this->exam->
getSetting('description');?><?php */?>
<?php echo $this->exam->getSetting('title');?>
</h2>
</div>
<!—讀入 navigation —>
<?php echo $this->loadTemplate('navigation');?>
<!—結束—> </div>
2. default_details.php 程式碼
<div class=" exams_details">
<ul>
<li class="<?php echo $this->params->get('showLevel');?>">
<!—顯示到達等級才可以做此題組 —>
55
<strong><?php echo JText::_('COM_ EXAMS_DETAIL_LEVEL');?></strong> :
<?php echo $this-> exam->getSetting('level');?>
</li>
<!—顯示此題組時間限制 —>
<li class="<?php echo $this->params-> get('showTimeLimit');?>">
<strong><?php echo
JText::_('COM_EXAMS_DETAIL_TIME_LIMIT_LABEL');?></strong> :
<?php echo $this->exam->getTimeLimit();?>
</li>
<!—顯示此題組同一個人可以重新作答幾次 —>
<li class="<?php echo $this->params->
get('showRetakeLimit');?>">
<strong><?php echo JText::_('COM_
EXAMS_DETAIL_RETAKE_LIMIT_LABEL');?></strong> :
<?php
$retakeLimit = $this->exam->
getSetting('retake_limit');
if ($retakeLimit == 0)
{$retakeLimit = JText::_('COM_ EXAMS_UNLIMITED');}
echo $retakeLimit;
?>
</li>
<!—顯示此題組同一個多久可重新作答幾次 —>
<li class="<?php echo $this->params-> get('showRetakeDelay');?>">
56
<strong><?php echo JText::_('COM_
EXAMS_DETAIL_RETAKE_DELAY_LABEL');?></strong> :
<?php $delay_text = examsHelper_exams::formatDelay($this ->exam-> getSetting('retake_delay')); echo $delay_text;?>
</li>
<!—顯示此題組的及格分數 —>
<li class="<?php echo $this->params-> get('showPassLine');?>">
<strong><?php echo
JText::_('COM_EXAMS_DETAIL_PASS_LINE_LABEL');?></strong>
: <?php echo ($this->exam->getSetting('pass_per').'%');?>
</li>
<!—顯示此題組的計分方式為電腦閱卷或人工閱卷—>
<li class="<?php echo $this->params-> get('showGradingOption');?>">
<strong><?php echo
JText::_('COM_EXAMS_DETAIL_GRADING_OPTION_LABEL');?></str ong> :
<?php
$gradingOption = $this->exam-> getSetting('grading_option');
switch ($gradingOption) {
case 0:
echo JText::_('COM_EXAMS_DETAILS_GRADING_OPTION_COMPUTERIZED');
break;
case 1:
echo JText::_('COM_EXAMS_DETAILS_GRADING_OPTION_MANUAL');
57
break;
default:
break;
} ?>
</li>
<!—顯示此題組是否可以儲存,下次登入再作答 —>
<li class="<?php echo $this->params-> get('showSavable');?>">
<strong><?php echo
JText::_('COM_EXAMS_DETAIL_SAVEABLE_LABEL');?></strong> :
<?php if($this->exam->getSetting('savable')){ echo JText::_('JYES');} else{ echo JText::_('JNO');}?>
</li>
</ul>
</div>
3. default_error.php 程式碼
<div>
<h2>
<?php echo JText::_('COM_EXAMS_ERROR_NO_EXAM_FOUND_TITLE')?>
</h2>
<p><?php echo JText::_('COM_EXAMS_EXAM_NOT_FOUND')?></p>
</div>
4. default_navigation.php 程式碼
58
<div class="exams_sub_navi">
<ul>
<!—產生本題組的網頁連結(連結到 Exam 網頁) —>
<?php if($this->exam->getSetting('state') == 1):?>
<li>
<span class="button-wrap"><a href="<?php echo
JRoute::_(examsHelper_exams::getNewExamLink($exam_id));?>"
class="button button-rounded button-action" rel="nofollow">
<?php echo JText::_('COM_EXAMS_TAKE_EXAM');?></a></span>
</li>
<?php endif;?>
<!—此題組是否有過去有作答的紀錄,如有則顯示紀錄連結 —>
<?php if (!is_null($result_id)):?>
<li>
<span class="button-wrap"><a href="<?php echo
JRoute::_(examsHelper_exams::getResultsLink($exam_id));?>"
class="button button-rounded button-highlight"
rel="nofollow">
<?php echo JText::_('COM_EXAMS_REVIEW');?></a></span>
</li>
<?php endif;?>
<!—此題組是否有作答到一半的紀錄,若有並允許暫停,則產生繼續的連結—>
<?php if($this->exam->isSavable() && !is_null($save_id) && $this ->exam->getSetting('state') == 1):?>
59
<li>
<a href="<?php echo
JRoute::_(examsHelper_exams::getResumeExamLink($exam_id));?>"
class="button" rel="nofollow"><?php echo JText::_('COM_EXAMS_RESUME');?></a>
</li>
<?php endif;?>
</ul>
</div>
四、 exam
主要有八個檔案,分別為
default.php: 題組主框架頁面。
default_progress_bar.php: 顯示進度條。
default_timer.php:顯示左下角小時鐘。
default_problem.php:顯示題目。
default_review.php:最後面讓作答者可以回顧整分卷紙作答情形的網 頁。
default_maq.php:多重選擇題的網頁。
default_mcq.php:單一選擇題的網頁。
default_saq.php:填充題的網頁。
此類檔案為使用者在作答題組時,顯示的所有題組資訊及答案的網頁,以下僅 提供主要三個網頁程式碼:default.php、default_problem.php、
default_review.php。
60
1. default.php 程式碼
<div class="exams_wrapper">
<div id="exams_header" class="page-header">
<h2 class="componentheading">
<?php echo $this->exam->getSetting('title');?></h2>
</div>
<!—讀取進度條網頁-->
<div class="progress_bar_wrapper">
<?php echo $this->loadTemplate('progress_bar');?>
</div>
<!—讀取記時網頁 -->
<div style="clear:both;"></div>
<?php echo $this->loadTemplate('timer');?>
<div style="clear:both;"></div>
<form action="<?php echo JRoute::_('index.php');?>" method="post"
name="examForm" id="examForm">
<?php $prevSectionEnd = 0; ?>
<?php $this->isFirst = true;?>
<!—抓此題組所有的 Sections-->
<?php foreach ($this->exam->getSections() as $section):?>
<?php $this->section = $section;?>
<?php $boxId = 'js-box'.$boxNumber;?>
<div id="<?php echo('js-box'.$boxNumber); ?>" class="open">
<!—首先顯示 navi 網頁-->
61
<div class="exams_section_navi">
<?php echo $this->loadTemplate('navi');?>
</div>
<div style="clear:both;"></div>
<!—顯示題組 Section 標題-->
<h3 id="section<?php echo $boxNumber; $boxNumber++;?>"
class="exams_section_head">
<?php echo $this->escape($section-> getSetting('title'));?>
</h3>
<div style="clear:both;"></div>
<!—顯示題組 Section 內容-->
<div class="exams_section_desc">
<?php echo $section->
getDescription($prevSectionEnd);?>
<?php $prevSectionEnd = $section->
getEndOfSection($prevSectionEnd);?>
</div>
<div style="clear:both;"></div>
<!—如果沒有抓到任何一個題目,則顯示錯誤網頁-->
<?php if ($section->getProblemCount() == 0): ?>
<h3><?php echo
JText::_('COM_EXAMS_ERROR_NO_PROBLEMS_FOUND_HEADER');?></h3>
<!—錯誤時顯示的網頁-->
<p><?php echo
JText::_('COM_EXAMS_ERROR_NO_PROBLEMS_FOUND_PARA_ONE');?></p>
62
<ol>
<li><?php echo
JText::_('COM_EXAMS_ERROR_NO_PROBLEMS_FOUND_ONE');?></li>
<li><?php echo
JText::_('COM_EXAMS_ERROR_NO_PROBLEMS_FOUND_TWO');?></li>
<li><?php echo
JText::_('COM_EXAMS_ERROR_NO_PROBLEMS_FOUND_THREE');?></li>
</ol>
<p><?php echo
JText::_('COM_EXAMS_ERROR_NO_PROBLEMS_FOUND_FOUR');?></p>
<?php $this->exam->setSetting('hasError', 1);?>
<?php else:?>
<!—讀取該 Section 下的所有 problem 並顯示 problem 子網頁 -->
<?php foreach ($section->getProblems() as $problem):?>
<?php $this->problem = $problem; ?>
<?php if ($savecode == ''):?>
<?php $savecode = $problem-> getSetting('pid');?>
<?php else:?>
<?php $savecode .= '|'.$problem->getSetting('pid');?>
<?php endif;?>
<?php echo $this->loadTemplate('problem');?>
<?php endforeach;?>
<?php endif;?>
</div>
<?php endforeach;?>
63
<!—過去有作答情況的顯示-->
<div id="<?php echo 'js-box'.$this->boxCount;?>" class="open">
<div style="clear:both;"></div>
<?php echo $this->loadTemplate('review');?>
<div style="clear:both;"></div>
<div style="float:right;">
<input type="submit" id="submit" value="<?php echo JText::_("COM_EXAMS_BUTTONS_SUBMIT");?>" />
</div>
</div>
<!—可暫停作答的部分 -->
<?php if ($this->exam->isSavable()):?>
<?php $user = JFactory::getUser();?>
<?php endif;?>
<div style="clear:both;"></div>
<!—此網頁所需的隱藏資訊-->
<input type="hidden" name="task" id='form_task' value="exam.submit" />
<input type="hidden" name="savecode" id="savecode" value="<?php echo $savecode;?>"/>
<input type="hidden" name="time_spent" id="time_spent" value="no-js" />
<input type="hidden" name="time_spent" id="time_spent" value="no-js" />