Fix & Finish 推薦一個學習點時,直接當成行進中,標的目前人數+1
This commit is contained in:
parent
36fe36391a
commit
acf7b7a811
@ -272,65 +272,6 @@ class DBStudy extends Database {
|
|||||||
return $resultId;
|
return $resultId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 行進中,準備進入的學習點
|
|
||||||
*
|
|
||||||
* @param string $activity_id 活動編號
|
|
||||||
* @param string $target_id 標的編號
|
|
||||||
* @param string $is_entity 是否為現場學習
|
|
||||||
* @return int 剛新增的記錄編號
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
public function enteringInTarget($activity_id, $target_id)
|
|
||||||
{
|
|
||||||
|
|
||||||
if(!isset($is_entity)) {
|
|
||||||
$is_entity = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 寫入
|
|
||||||
$sqlString = "INSERT INTO `".$this->table('Study').
|
|
||||||
"` (`SaID`, `TID`, `IsEnter`, `IsEntity`, `In_TargetTime`, `Out_TargetTime`)
|
|
||||||
VALUES ( :said , :tid , '0' , '1' , NOW() , NULL )";
|
|
||||||
|
|
||||||
$query = $this->connDB->prepare($sqlString);
|
|
||||||
$query->bindParam(":said", $activity_id);
|
|
||||||
$query->bindParam(":tid", $target_id);
|
|
||||||
$query->execute();
|
|
||||||
|
|
||||||
// 取得剛剛加入的ID
|
|
||||||
$sqlString = "SELECT LAST_INSERT_ID()";
|
|
||||||
$query = $this->connDB->query($sqlString);
|
|
||||||
$queryResult = $query->fetch();
|
|
||||||
$resultId = $queryResult[0];
|
|
||||||
|
|
||||||
return $resultId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 取消所有行進中準備進入的學習點的狀態
|
|
||||||
*
|
|
||||||
* @param string $activity_id 活動編號
|
|
||||||
* @return 影響數
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
public function allOutEnteringInTarget($activity_id)
|
|
||||||
{
|
|
||||||
|
|
||||||
// 寫入
|
|
||||||
$sqlString = "UPDATE `".$this->table('Study').
|
|
||||||
"` SET `Out_TargetTime` = NOW()
|
|
||||||
WHERE `SaID` = :id ".
|
|
||||||
"AND `IsEnter` = '0'".
|
|
||||||
" AND `Out_TargetTime` IS NULL";
|
|
||||||
|
|
||||||
$query = $this->connDB->prepare($sqlString);
|
|
||||||
$query->bindParam(":id", $activity_id);
|
|
||||||
$query->execute();
|
|
||||||
$count = $query->rowCount();
|
|
||||||
return $count;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 離開學習點
|
* 離開學習點
|
||||||
*
|
*
|
||||||
@ -369,6 +310,41 @@ class DBStudy extends Database {
|
|||||||
$query->execute();
|
$query->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 行進中,準備進入的學習點
|
||||||
|
*
|
||||||
|
* @param string $activity_id 活動編號
|
||||||
|
* @param string $target_id 標的編號
|
||||||
|
* @param string $is_entity 是否為現場學習
|
||||||
|
* @return int 剛新增的記錄編號
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function enteringInTarget($activity_id, $target_id)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(!isset($is_entity)) {
|
||||||
|
$is_entity = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 寫入
|
||||||
|
$sqlString = "INSERT INTO `".$this->table('Study').
|
||||||
|
"` (`SaID`, `TID`, `IsEnter`, `IsEntity`, `In_TargetTime`, `Out_TargetTime`)
|
||||||
|
VALUES ( :said , :tid , '0' , '1' , NOW() , NULL )";
|
||||||
|
|
||||||
|
$query = $this->connDB->prepare($sqlString);
|
||||||
|
$query->bindParam(":said", $activity_id);
|
||||||
|
$query->bindParam(":tid", $target_id);
|
||||||
|
$query->execute();
|
||||||
|
|
||||||
|
// 取得剛剛加入的ID
|
||||||
|
$sqlString = "SELECT LAST_INSERT_ID()";
|
||||||
|
$query = $this->connDB->query($sqlString);
|
||||||
|
$queryResult = $query->fetch();
|
||||||
|
$resultId = $queryResult[0];
|
||||||
|
|
||||||
|
return $resultId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 取得目前正在進行的標的編號
|
* 取得目前正在進行的標的編號
|
||||||
*
|
*
|
||||||
@ -396,6 +372,33 @@ class DBStudy extends Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取得目前正在進行的標的編號
|
||||||
|
*
|
||||||
|
* @param int $activity_id 活動編號
|
||||||
|
* @return int 標的編號
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public function getCurrentEnteringTargetId($activity_id) {
|
||||||
|
|
||||||
|
$sqlString = "SELECT `TID` FROM `".$this->table('Study')."` ".
|
||||||
|
"WHERE `Out_TargetTime` IS NULL AND `SaID` = :said ".
|
||||||
|
"AND `IsEnter` = '0'";
|
||||||
|
|
||||||
|
$query = $this->connDB->prepare($sqlString);
|
||||||
|
$query->bindParam(":said", $activity_id);
|
||||||
|
$query->execute();
|
||||||
|
|
||||||
|
$queryResult = $query->fetch();
|
||||||
|
// 如果有查到一筆以上
|
||||||
|
if( count($queryResult) >= 1 ) {
|
||||||
|
return (int)$queryResult[0];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 取得目前正在行進中標的編號
|
* 取得目前正在行進中標的編號
|
||||||
*
|
*
|
||||||
|
@ -46,6 +46,17 @@ class StudyManager {
|
|||||||
return $db->getCurrentInStudyId($activity_id);
|
return $db->getCurrentInStudyId($activity_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取得目前行進中的學習點
|
||||||
|
* @param int $activity_id 活動編號
|
||||||
|
* @return int 標的編號,若無則null
|
||||||
|
*/
|
||||||
|
public function getCurrentEnteringTargetId($activity_id) {
|
||||||
|
|
||||||
|
$db = new Database\DBStudy();
|
||||||
|
return $db->getCurrentEnteringTargetId($activity_id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 此標的是否已學習過
|
* 此標的是否已學習過
|
||||||
*
|
*
|
||||||
@ -90,6 +101,10 @@ class StudyManager {
|
|||||||
$target->addMj(1);
|
$target->addMj(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 取消行進中狀態
|
||||||
|
$enterTId = $this->getCurrentEnteringTargetId($activity_id);
|
||||||
|
$this->outEnteringInTarget($activity_id, $enterTId);
|
||||||
|
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -97,6 +112,45 @@ class StudyManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 離開標的
|
||||||
|
*
|
||||||
|
* @param int $activity_id 活動編號
|
||||||
|
* @param int $target_id 標的編號
|
||||||
|
* @throw UElearning\Exception\NoInLearningException
|
||||||
|
*/
|
||||||
|
public function toOutTarget($activity_id, $target_id) {
|
||||||
|
|
||||||
|
// 從資料庫取得此活動此標的學習中資料
|
||||||
|
$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->toOutTarget($thisArray['study_id']);
|
||||||
|
|
||||||
|
// 將標的目前人數-1
|
||||||
|
if($thisArray['is_entity'] = true) {
|
||||||
|
$target = new Target\Target($target_id);
|
||||||
|
$target->addMj(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取消行進中狀態
|
||||||
|
$enterTId = $this->getCurrentEnteringTargetId($activity_id);
|
||||||
|
$this->outEnteringInTarget($activity_id, $enterTId);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new Exception\NoInLearningException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 行進中,準備進入的學習點
|
* 行進中,準備進入的學習點
|
||||||
*
|
*
|
||||||
@ -111,6 +165,10 @@ class StudyManager {
|
|||||||
if($this->getCurrentInTargetId($activity_id) == null) {
|
if($this->getCurrentInTargetId($activity_id) == null) {
|
||||||
$db = new Database\DBStudy();
|
$db = new Database\DBStudy();
|
||||||
|
|
||||||
|
// 取消行進中狀態
|
||||||
|
$enterTId = $this->getCurrentEnteringTargetId($activity_id);
|
||||||
|
$this->outEnteringInTarget($activity_id, $enterTId);
|
||||||
|
|
||||||
// 紀錄進資料庫
|
// 紀錄進資料庫
|
||||||
$id = $db->enteringInTarget($activity_id, $target_id);
|
$id = $db->enteringInTarget($activity_id, $target_id);
|
||||||
|
|
||||||
@ -148,46 +206,9 @@ class StudyManager {
|
|||||||
$db->toOutTarget($thisArray['study_id']);
|
$db->toOutTarget($thisArray['study_id']);
|
||||||
|
|
||||||
// 將標的目前人數-1
|
// 將標的目前人數-1
|
||||||
if($thisArray['is_entity'] = true) {
|
$target = new Target\Target($target_id);
|
||||||
$target = new Target\Target($target_id);
|
$target->addMj(-1);
|
||||||
$target->addMj(-1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 離開標的
|
|
||||||
*
|
|
||||||
* @param int $activity_id 活動編號
|
|
||||||
* @param int $target_id 標的編號
|
|
||||||
* @throw UElearning\Exception\NoInLearningException
|
|
||||||
*/
|
|
||||||
public function toOutTarget($activity_id, $target_id) {
|
|
||||||
|
|
||||||
// 從資料庫取得此活動此標的學習中資料
|
|
||||||
$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->toOutTarget($thisArray['study_id']);
|
|
||||||
|
|
||||||
// 將標的目前人數-1
|
|
||||||
if($thisArray['is_entity'] = true) {
|
|
||||||
$target = new Target\Target($target_id);
|
|
||||||
$target->addMj(-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new Exception\NoInLearningException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user