Add Target: 取得教材路徑功能
This commit is contained in:
parent
fb0e41d0c1
commit
20bbd0c2bc
153
htdocs/lib/Database/DBMaterial.php
Normal file
153
htdocs/lib/Database/DBMaterial.php
Normal file
@ -0,0 +1,153 @@
|
||||
<?php
|
||||
/**
|
||||
* DBTarget.php
|
||||
*
|
||||
* 此檔案針對學習標的,以及學習標的的區域、廳等的資料庫查詢用。
|
||||
*/
|
||||
|
||||
namespace UElearning\Database;
|
||||
|
||||
use UElearning\Exception;
|
||||
|
||||
require_once UELEARNING_LIB_ROOT.'/Database/Database.php';
|
||||
require_once UELEARNING_LIB_ROOT.'/Database/Exception.php';
|
||||
|
||||
/**
|
||||
* 學習標的資料表
|
||||
*
|
||||
* 此檔案針對學習標的,以及學習標的的區域、廳等的資料表進行操作。
|
||||
*
|
||||
*
|
||||
* @author Yuan Chiu <chyuaner@gmail.com>
|
||||
* @version 2.0.0
|
||||
* @package UElearning
|
||||
* @subpackage Database
|
||||
*/
|
||||
class DBMaterial extends Database {
|
||||
|
||||
/**
|
||||
* 內部使用的查詢動作
|
||||
* @param string $where 查詢語法
|
||||
* @return array 查詢結果陣列
|
||||
*/
|
||||
protected function queryMaterialByWhere($where) {
|
||||
|
||||
$sqlString = "SELECT * FROM `".$this->table('Material')."` ".
|
||||
"WHERE ".$where;
|
||||
|
||||
$query = $this->connDB->prepare($sqlString);
|
||||
$query->execute();
|
||||
|
||||
$queryResultAll = $query->fetchAll();
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
// 製作回傳結果陣列
|
||||
$result = array();
|
||||
foreach($queryResultAll as $key => $thisResult) {
|
||||
|
||||
if($thisResult['MEntity'] != '0') {
|
||||
$output_entiry = true;
|
||||
}
|
||||
else { $output_entiry = false; }
|
||||
|
||||
array_push($result,
|
||||
array( 'material_id' => $thisResult['MID'],
|
||||
'target_id' => $thisResult['TID'],
|
||||
'is_entity' => $output_entiry,
|
||||
'mode' => $thisResult['MMode'],
|
||||
'url' => $thisResult['MUrl']
|
||||
));
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
// 若都沒查到的話
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查詢一個標的資料
|
||||
*
|
||||
*
|
||||
* 範例:
|
||||
*
|
||||
* require_once __DIR__.'/../config.php';
|
||||
* require_once UELEARNING_LIB_ROOT.'/Database/DBMaterial.php';
|
||||
* use UElearning\Database;
|
||||
*
|
||||
* $db = new Database\DBMaterial();
|
||||
* $materialInfo = $db->queryMaterial(1);
|
||||
* echo '<pre>'; print_r($materialInfo); echo '</pre>';
|
||||
*
|
||||
*
|
||||
* @param int $mId 教材ID
|
||||
* @return array 教材資料陣列,格式為:
|
||||
* array(
|
||||
* 'material_id' => <教材ID>,
|
||||
* 'target_id' => <標的ID>,
|
||||
* 'is_entity' => <是否為實體教材>,
|
||||
* 'mode' => <教材類型>,
|
||||
* 'url' => <此標的教材路徑>
|
||||
* );
|
||||
*
|
||||
*/
|
||||
public function queryMaterial($mId) {
|
||||
|
||||
$queryResultAll = $this->queryMaterialByWhere("`MID`=".$this->connDB->quote($mId));
|
||||
|
||||
// 如果有查到一筆以上
|
||||
if( count($queryResultAll) >= 1 ) {
|
||||
return $queryResultAll[0];
|
||||
}
|
||||
// 若都沒查到的話
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查詢此標的內所教材的資料
|
||||
*
|
||||
* @param int $tID 標的ID
|
||||
* @return array 教材資料陣列,格式為:
|
||||
*
|
||||
* array(
|
||||
* array(
|
||||
* 'material_id' => <教材ID>,
|
||||
* 'target_id' => <標的ID>,
|
||||
* 'is_entity' => <是否為實體教材>,
|
||||
* 'mode' => <教材類型>,
|
||||
* 'url' => <此標的教材路徑>
|
||||
* );
|
||||
* );
|
||||
*
|
||||
*/
|
||||
public function queryAllMaterialByTargetId($tID) {
|
||||
|
||||
return $this->queryMaterialByWhere("`TID`=".$this->connDB->quote($tID));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查詢所有教材資料
|
||||
*
|
||||
* @return array 教材資料陣列,格式為:
|
||||
*
|
||||
* array(
|
||||
* array(
|
||||
* 'material_id' => <教材ID>,
|
||||
* 'target_id' => <標的ID>,
|
||||
* 'is_entity' => <是否為實體教材>,
|
||||
* 'mode' => <教材類型>,
|
||||
* 'url' => <此標的教材路徑>
|
||||
* );
|
||||
* );
|
||||
*
|
||||
*/
|
||||
public function queryAllMaterial() {
|
||||
|
||||
return $this->queryMaterialByWhere("1");
|
||||
}
|
||||
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
namespace UElearning\Target;
|
||||
|
||||
require_once UELEARNING_LIB_ROOT.'/Database/DBTarget.php';
|
||||
require_once UELEARNING_LIB_ROOT.'/Database/DBMaterial.php';
|
||||
require_once UELEARNING_LIB_ROOT.'/Target/Exception.php';
|
||||
use UElearning\Database;
|
||||
use UElearning\Exception;
|
||||
@ -184,6 +185,37 @@ class Target {
|
||||
return $this->queryResultArray['map_url'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得標的的教材路徑
|
||||
*
|
||||
* @param bool $isEntity 是否為實體教材
|
||||
* @param string $mode 教材種類
|
||||
* @return string 教材檔案路徑
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function getMaterialUrl($isEntity, $mode){
|
||||
|
||||
$db = new Database\DBMaterial();
|
||||
$query = $db->queryAllMaterialByTargetId($this->tId);
|
||||
|
||||
foreach($query as $thisData) {
|
||||
|
||||
if($thisData['is_entity'] != 0) {
|
||||
$thisEntiry = true;
|
||||
}
|
||||
else { $thisEntiry = false; }
|
||||
|
||||
if($thisEntiry==$isEntity && $thisData['mode'] == $mode) {
|
||||
return $thisData['url'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* 取得預估的學習時間
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user