diff --git a/htdocs/api/v2/index.php b/htdocs/api/v2/index.php index 91aa173..930761e 100644 --- a/htdocs/api/v2/index.php +++ b/htdocs/api/v2/index.php @@ -1191,7 +1191,9 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) { else { $result_recommand_total = $recommandTotal; } - + // 是否已經學完了 + if($recommandTotal <= 0) { $isEnd = true; } + else { $isEnd = false; } // 製作 $output_targets = array(); @@ -1207,6 +1209,7 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) { 'user_id' => $user_id, 'activity_id' => $sact->getId(), 'current_target_id' => $currentTId, + 'is_end' => $isEnd, 'recommand_total' => $result_recommand_total, 'recommand_target' => $output_targets, 'error' => false diff --git a/htdocs/lib/Database/DBStudy.php b/htdocs/lib/Database/DBStudy.php index ad10220..283d231 100644 --- a/htdocs/lib/Database/DBStudy.php +++ b/htdocs/lib/Database/DBStudy.php @@ -266,7 +266,7 @@ class DBStudy extends Database { * @param string $study_id 此記錄編號 * @since 2.0.0 */ - public function toOutTaeget($study_id) + public function toOutTarget($study_id) { // 寫入 @@ -285,7 +285,7 @@ class DBStudy extends Database { * @param string $activity_id 活動編號 * @since 2.0.0 */ - public function allToOutTaeget($activity_id) + public function alltoOutTarget($activity_id) { // 寫入 diff --git a/htdocs/lib/Study/Study.php b/htdocs/lib/Study/Study.php index 25405f2..34cceff 100644 --- a/htdocs/lib/Study/Study.php +++ b/htdocs/lib/Study/Study.php @@ -7,7 +7,9 @@ namespace UElearning\Study; require_once UELEARNING_LIB_ROOT.'/Database/DBStudy.php'; require_once UELEARNING_LIB_ROOT.'/Study/Exception.php'; +require_once UELEARNING_LIB_ROOT.'/Target/Target.php'; use UElearning\Database; +use UElearning\Target; use UElearning\Exception; /** @@ -173,7 +175,15 @@ class Study { * @since 2.0.0 */ public function toOut() { + + // 將資料庫內容標示已離開 $db = new Database\DBStudy(); - $db->toOutTaeget($this->id); + $db->toOutTarget($this->id); + + // 將標的目前人數-1 + if($this->isEntity()) { + $target = new Target\Target($this->getTargetId); + $target->addMj(-1); + } } } diff --git a/htdocs/lib/Study/StudyManager.php b/htdocs/lib/Study/StudyManager.php index a1051c1..dd12778 100644 --- a/htdocs/lib/Study/StudyManager.php +++ b/htdocs/lib/Study/StudyManager.php @@ -7,7 +7,10 @@ namespace UElearning\Study; require_once UELEARNING_LIB_ROOT.'/Database/DBStudy.php'; require_once UELEARNING_LIB_ROOT.'/Study/Exception.php'; +require_once UELEARNING_LIB_ROOT.'/Target/Target.php'; +require_once UELEARNING_LIB_ROOT.'/Target/Exception.php'; use UElearning\Database; +use UElearning\Target; use UElearning\Exception; /** @@ -68,14 +71,24 @@ class StudyManager { * @param int $activity_id 活動編號 * @param int $target_id 標的編號 * @param bool $is_entity 是否為現場學習 + * @throw UElearning\Exception\TargetNoFoundException * return int 進出紀錄編號 */ public function toInTarget($activity_id, $target_id, $is_entity) { // 若沒有任一個點正在學習中 if($this->getCurrentInTargetId($activity_id) == null) { + // 紀錄進資料庫 $db = new Database\DBStudy(); - return $db->toInTaeget($activity_id, $target_id, $is_entity); + $id = $db->toInTaeget($activity_id, $target_id, $is_entity); + + // 將標的目前人數+1 + if($is_entity) { + $target = new Target\Target($target_id); + $target->addMj(1); + } + + return $id; } else { throw new Exception\InLearningException(); @@ -93,12 +106,22 @@ class StudyManager { // 從資料庫取得此活動此標的學習中資料 $db = new Database\DBStudy(); $learning_array = $db->getInStudyIdByTargetId($activity_id, $target_id); + $target = new Target\Target($target_id); + // 找到正在學習中的資料 if(isset($learning_array)) { + // 將所有此標的的進入紀錄全部標示 foreach($learning_array as $thisArray) { - $db->toOutTaeget($thisArray['study_id']); + // 將此紀錄標示為已離開 + $db->toOutTarget($thisArray['study_id']); + + // 將標的目前人數-1 + if($thisArray['is_entity'] = true) { + $target = new Target\Target($target_id); + $target->addMj(-1); + } } } }