From 7707cdc84d8deca19a21eda7de23d11e55250ef1 Mon Sep 17 00:00:00 2001 From: Yuan Chiu Date: Tue, 28 Oct 2014 20:39:38 +0800 Subject: [PATCH] =?UTF-8?q?StudyActivity:=20Add=20=E5=AD=B8=E9=81=8E?= =?UTF-8?q?=E7=9A=84=E6=A8=99=E7=9A=84=E6=95=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/lib/Database/DBStudyActivity.php | 26 +++++++++++++++++-------- htdocs/lib/Database/DBTheme.php | 2 ++ htdocs/lib/Study/StudyActivity.php | 19 +++++++++++++++--- htdocs/lib/Study/ThemeManager.php | 2 +- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/htdocs/lib/Database/DBStudyActivity.php b/htdocs/lib/Database/DBStudyActivity.php index 4737f94..abd67f8 100644 --- a/htdocs/lib/Database/DBStudyActivity.php +++ b/htdocs/lib/Database/DBStudyActivity.php @@ -102,6 +102,7 @@ class DBStudyActivity extends Database { else $to_materialMode = "'".MMODE."'"; + // 寫入學習活動資料 $sqlString = "INSERT INTO `".$this->table('StudyActivity'). "` (`UID`, `ThID`, @@ -111,8 +112,6 @@ class DBStudyActivity extends Database { ".$to_startTime.", ".$to_endTime.", ".$to_learnTime." , :delay , :timeforce , ".$to_learnStyle.", :lstyle_force , ".$to_materialMode.")"; - - $query = $this->connDB->prepare($sqlString); $query->bindParam(":uid", $userId); $query->bindParam(":thid", $themeId); @@ -155,10 +154,18 @@ class DBStudyActivity extends Database { $sqlString = "SELECT `SaID`, `UID`, `ThID`, ". "`StartTime`, `EndTime`, ". "`LearnTime`, `Delay`, `TimeForce`, ". - "`LMode`, `LModeForce`, `MMode` ". - "FROM `".$this->table('StudyActivity')."` AS Act ". - //"LEFT JOIN `".$this->table('Area')."` AS Area ". - //"ON Area.`AID` = Target.`AID` ". + "`LMode`, `LModeForce`, `MMode`, ". + + "(SELECT count(`TID`) + FROM `chu__TBelong` AS `belong` + WHERE `belong`.`ThID` = `sa`.`ThID`) AS `TargetTotal`, ". + + "(SELECT count(DISTINCT `TID`) + FROM `chu__Study` AS `study` + WHERE `Out_TargetTime` IS NOT NULL + AND `study`.`SaID` = `sa`.`SaID`) AS `LearnedTotal`". + + "FROM `".$this->table('StudyActivity')."` AS sa ". "WHERE ".$where; $query = $this->connDB->prepare($sqlString); @@ -192,7 +199,10 @@ class DBStudyActivity extends Database { 'time_force' => $output_time_force, 'learnStyle_mode' => $thisResult['LMode'], 'learnStyle_force' => $output_learnStyleForce, - 'material_mode' => $thisResult['MMode']) + 'material_mode' => $thisResult['MMode'], + 'target_total' => $thisResult['TargetTotal'], + 'learned_total' => $thisResult['LearnedTotal'] + ) ); } return $result; @@ -234,7 +244,7 @@ class DBStudyActivity extends Database { * 'learnStyle_force' => <拒絕前往非推薦的學習點>, * 'material_mode' => <教材模式> * ); - * + * @param int $id 活動編號 */ public function queryActivity($id) { diff --git a/htdocs/lib/Database/DBTheme.php b/htdocs/lib/Database/DBTheme.php index 2ceefc4..d1b6e3b 100644 --- a/htdocs/lib/Database/DBTheme.php +++ b/htdocs/lib/Database/DBTheme.php @@ -87,6 +87,7 @@ class DBTheme extends Database { * 'name' => <主題名稱>, * 'learn_time' => <預估的學習時間>, * 'introduction' => <主題介紹>, + * 'target_total' => <此主題內有多少標的>, * 'build_time' => <主題建立時間>, * 'modify_time' => <主題資料修改時間> * ); @@ -118,6 +119,7 @@ class DBTheme extends Database { * 'name' => <主題名稱>, * 'learn_time' => <預估的學習時間>, * 'introduction' => <主題介紹>, + * 'target_total' => <此主題內有多少標的>, * 'build_time' => <主題建立時間>, * 'modify_time' => <主題資料修改時間> * ) diff --git a/htdocs/lib/Study/StudyActivity.php b/htdocs/lib/Study/StudyActivity.php index 7ab5943..301a5ef 100644 --- a/htdocs/lib/Study/StudyActivity.php +++ b/htdocs/lib/Study/StudyActivity.php @@ -139,24 +139,37 @@ class StudyActivity { // ======================================================================== + /** + * 總共要學幾個學習點 + * + * @return int 有幾個學習點 + * @since 2.0.0 + */ + public function getPointTotal() { + return $this->queryResultArray['target_total']; + } + /** * 取得已經學過幾個學習點 * - * @return ing 已學過幾個學習點 + * @return int 已學過幾個學習點 * @since 2.0.0 */ public function getLearnedPointTotal() { - + return $this->queryResultArray['learned_total']; } /** * 取得還剩下幾個學習點還沒學 * - * @return ing 還剩下幾個學習點 + * @return int 還剩下幾個學習點 * @since 2.0.0 */ public function getRemainingPointTotal() { + $total = $this->getPointTotal(); + $learned = $this->getLearnedPointTotal(); + return $total - $learned; } // ======================================================================== diff --git a/htdocs/lib/Study/ThemeManager.php b/htdocs/lib/Study/ThemeManager.php index f8e1088..c1327d0 100644 --- a/htdocs/lib/Study/ThemeManager.php +++ b/htdocs/lib/Study/ThemeManager.php @@ -3,7 +3,7 @@ * ThemeManager.php */ -namespace UElearning\User; +namespace UElearning\Study; require_once UELEARNING_LIB_ROOT.'/Database/DBTheme.php'; require_once UELEARNING_LIB_ROOT.'/Study/Exception.php';