實作進出標的時加減標的目前人數
This commit is contained in:
parent
b239c28046
commit
8ba983a999
@ -1191,7 +1191,9 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) {
|
|||||||
else {
|
else {
|
||||||
$result_recommand_total = $recommandTotal;
|
$result_recommand_total = $recommandTotal;
|
||||||
}
|
}
|
||||||
|
// 是否已經學完了
|
||||||
|
if($recommandTotal <= 0) { $isEnd = true; }
|
||||||
|
else { $isEnd = false; }
|
||||||
|
|
||||||
// 製作
|
// 製作
|
||||||
$output_targets = array();
|
$output_targets = array();
|
||||||
@ -1207,6 +1209,7 @@ $app->group('/tokens', 'APIrequest', function () use ($app, $app_template) {
|
|||||||
'user_id' => $user_id,
|
'user_id' => $user_id,
|
||||||
'activity_id' => $sact->getId(),
|
'activity_id' => $sact->getId(),
|
||||||
'current_target_id' => $currentTId,
|
'current_target_id' => $currentTId,
|
||||||
|
'is_end' => $isEnd,
|
||||||
'recommand_total' => $result_recommand_total,
|
'recommand_total' => $result_recommand_total,
|
||||||
'recommand_target' => $output_targets,
|
'recommand_target' => $output_targets,
|
||||||
'error' => false
|
'error' => false
|
||||||
|
@ -266,7 +266,7 @@ class DBStudy extends Database {
|
|||||||
* @param string $study_id 此記錄編號
|
* @param string $study_id 此記錄編號
|
||||||
* @since 2.0.0
|
* @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 活動編號
|
* @param string $activity_id 活動編號
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public function allToOutTaeget($activity_id)
|
public function alltoOutTarget($activity_id)
|
||||||
{
|
{
|
||||||
|
|
||||||
// 寫入
|
// 寫入
|
||||||
|
@ -7,7 +7,9 @@ namespace UElearning\Study;
|
|||||||
|
|
||||||
require_once UELEARNING_LIB_ROOT.'/Database/DBStudy.php';
|
require_once UELEARNING_LIB_ROOT.'/Database/DBStudy.php';
|
||||||
require_once UELEARNING_LIB_ROOT.'/Study/Exception.php';
|
require_once UELEARNING_LIB_ROOT.'/Study/Exception.php';
|
||||||
|
require_once UELEARNING_LIB_ROOT.'/Target/Target.php';
|
||||||
use UElearning\Database;
|
use UElearning\Database;
|
||||||
|
use UElearning\Target;
|
||||||
use UElearning\Exception;
|
use UElearning\Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -173,7 +175,15 @@ class Study {
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public function toOut() {
|
public function toOut() {
|
||||||
|
|
||||||
|
// 將資料庫內容標示已離開
|
||||||
$db = new Database\DBStudy();
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,10 @@ namespace UElearning\Study;
|
|||||||
|
|
||||||
require_once UELEARNING_LIB_ROOT.'/Database/DBStudy.php';
|
require_once UELEARNING_LIB_ROOT.'/Database/DBStudy.php';
|
||||||
require_once UELEARNING_LIB_ROOT.'/Study/Exception.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\Database;
|
||||||
|
use UElearning\Target;
|
||||||
use UElearning\Exception;
|
use UElearning\Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,14 +71,24 @@ class StudyManager {
|
|||||||
* @param int $activity_id 活動編號
|
* @param int $activity_id 活動編號
|
||||||
* @param int $target_id 標的編號
|
* @param int $target_id 標的編號
|
||||||
* @param bool $is_entity 是否為現場學習
|
* @param bool $is_entity 是否為現場學習
|
||||||
|
* @throw UElearning\Exception\TargetNoFoundException
|
||||||
* return int 進出紀錄編號
|
* return int 進出紀錄編號
|
||||||
*/
|
*/
|
||||||
public function toInTarget($activity_id, $target_id, $is_entity) {
|
public function toInTarget($activity_id, $target_id, $is_entity) {
|
||||||
|
|
||||||
// 若沒有任一個點正在學習中
|
// 若沒有任一個點正在學習中
|
||||||
if($this->getCurrentInTargetId($activity_id) == null) {
|
if($this->getCurrentInTargetId($activity_id) == null) {
|
||||||
|
// 紀錄進資料庫
|
||||||
$db = new Database\DBStudy();
|
$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 {
|
else {
|
||||||
throw new Exception\InLearningException();
|
throw new Exception\InLearningException();
|
||||||
@ -93,12 +106,22 @@ class StudyManager {
|
|||||||
// 從資料庫取得此活動此標的學習中資料
|
// 從資料庫取得此活動此標的學習中資料
|
||||||
$db = new Database\DBStudy();
|
$db = new Database\DBStudy();
|
||||||
$learning_array = $db->getInStudyIdByTargetId($activity_id, $target_id);
|
$learning_array = $db->getInStudyIdByTargetId($activity_id, $target_id);
|
||||||
|
$target = new Target\Target($target_id);
|
||||||
|
|
||||||
|
// 找到正在學習中的資料
|
||||||
if(isset($learning_array)) {
|
if(isset($learning_array)) {
|
||||||
|
|
||||||
|
// 將所有此標的的進入紀錄全部標示
|
||||||
foreach($learning_array as $thisArray) {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user