fix StudyActivity.php
This commit is contained in:
parent
dd3b9b3958
commit
7952511d72
@ -8,7 +8,7 @@ namespace UElearning\Exception;
|
|||||||
// TODO: 將以下類別濃縮
|
// TODO: 將以下類別濃縮
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 沒有找到此標的
|
* 沒有找到此活動
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
* @package UElearning
|
* @package UElearning
|
||||||
* @subpackage Target
|
* @subpackage Target
|
||||||
@ -37,3 +37,34 @@ class StudyActivityNoFoundException extends \UnexpectedValueException {
|
|||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 此活動已結束
|
||||||
|
* @since 2.0.0
|
||||||
|
* @package UElearning
|
||||||
|
* @subpackage Target
|
||||||
|
*/
|
||||||
|
class StudyActivityFinishedException extends \UnexpectedValueException {
|
||||||
|
/**
|
||||||
|
* 指定的學習活動ID
|
||||||
|
* @type int
|
||||||
|
*/
|
||||||
|
private $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用者帳號例外
|
||||||
|
* @param int $id 輸入的標的ID
|
||||||
|
*/
|
||||||
|
public function __construct($id) {
|
||||||
|
$this->id = $id;
|
||||||
|
parent::__construct('No Activity: '.$this->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取得輸入的標的ID
|
||||||
|
* @return int 標的ID
|
||||||
|
*/
|
||||||
|
public function getId() {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
}
|
@ -15,7 +15,36 @@ use UElearning\User;
|
|||||||
/**
|
/**
|
||||||
* 學習階段類別
|
* 學習階段類別
|
||||||
*
|
*
|
||||||
* 一個物件即代表這一個主題
|
* 一個物件即代表這一個學習活動
|
||||||
|
*
|
||||||
|
* 使用範例:
|
||||||
|
*
|
||||||
|
* require_once __DIR__.'/../config.php';
|
||||||
|
* require_once UELEARNING_LIB_ROOT.'/Study/StudyActivity.php';
|
||||||
|
* use UElearning\Study;
|
||||||
|
* use UElearning\Exception;
|
||||||
|
*
|
||||||
|
* try{
|
||||||
|
* $sact = new Study\StudyActivity(8);
|
||||||
|
*
|
||||||
|
* echo $sact->getId();
|
||||||
|
* echo $sact->getUserId();
|
||||||
|
* echo $sact->getThemeId();
|
||||||
|
* echo $sact->getLearnStyle();
|
||||||
|
* echo $sact->isForceLearnStyle();
|
||||||
|
* echo $sact->getMaterialStyle();
|
||||||
|
* $sact->setDelay(23);
|
||||||
|
* echo $sact->getDelay();
|
||||||
|
* echo $sact->isLearning();
|
||||||
|
*
|
||||||
|
* $sact->finishActivity();
|
||||||
|
* }
|
||||||
|
* catch (Exception\StudyActivityNoFoundException $e) {
|
||||||
|
* echo 'No Found learnActivity: '. $e->getId();
|
||||||
|
* }
|
||||||
|
* catch (Exception\StudyActivityFinishedException $e) {
|
||||||
|
* echo 'The learnActivity is over: '. $e->getId();
|
||||||
|
* }
|
||||||
*
|
*
|
||||||
* @version 2.0.0
|
* @version 2.0.0
|
||||||
* @package UElearning
|
* @package UElearning
|
||||||
@ -41,7 +70,7 @@ class StudyActivity {
|
|||||||
/**
|
/**
|
||||||
* 從資料庫取得查詢
|
* 從資料庫取得查詢
|
||||||
*
|
*
|
||||||
* @throw UElearning\Exception\AreaNoFoundException
|
* @throw \UElearning\Exception\StudyActivityNoFoundException
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
protected function getQuery() {
|
protected function getQuery() {
|
||||||
@ -75,14 +104,20 @@ class StudyActivity {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 結束這次學習
|
* 結束這次學習
|
||||||
*
|
* *
|
||||||
|
* @throw \UElearning\Exception\StudyActivityNoFoundException
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public function finishActivity() {
|
public function finishActivity() {
|
||||||
|
|
||||||
|
// 此活動還在進行中
|
||||||
|
if($this->isLearning()) {
|
||||||
$db = new Database\DBStudyActivity();
|
$db = new Database\DBStudyActivity();
|
||||||
$db->setEndTimeNow($this->id);
|
$db->setEndTimeNow($this->id);
|
||||||
}
|
}
|
||||||
|
// 此活動已結束
|
||||||
|
else throw new Exception\StudyActivityFinishedException($this->id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 撤銷這次學習
|
* 撤銷這次學習
|
||||||
@ -259,23 +294,35 @@ class StudyActivity {
|
|||||||
* 設定這次學習時間要延長多久
|
* 設定這次學習時間要延長多久
|
||||||
*
|
*
|
||||||
* @param int $minute 延長時間(分)
|
* @param int $minute 延長時間(分)
|
||||||
|
* @throw \UElearning\Exception\StudyActivityNoFoundException
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public function setDelay($minute) {
|
public function setDelay($minute) {
|
||||||
|
|
||||||
|
// 此活動還在進行中
|
||||||
|
if($this->isLearning()) {
|
||||||
|
|
||||||
$db = new Database\DBStudyActivity();
|
$db = new Database\DBStudyActivity();
|
||||||
$db->setDelay($this->id, $minute);
|
$db->setDelay($this->id, $minute);
|
||||||
|
|
||||||
$this->getQuery();
|
$this->getQuery();
|
||||||
}
|
}
|
||||||
|
// 此活動已結束
|
||||||
|
else throw new Exception\StudyActivityFinishedException($this->id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 設定累加這次學習時間要延長多久
|
* 設定累加這次學習時間要延長多久
|
||||||
*
|
*
|
||||||
* @param int $minute 延長時間(分)
|
* @param int $minute 延長時間(分)
|
||||||
|
* @throw \UElearning\Exception\StudyActivityNoFoundException
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public function addDelay($minute) {
|
public function addDelay($minute) {
|
||||||
|
|
||||||
|
// 此活動還在進行中
|
||||||
|
if($this->isLearning()) {
|
||||||
|
|
||||||
$setMinute = $this->queryResultArray['delay'] + $minute;
|
$setMinute = $this->queryResultArray['delay'] + $minute;
|
||||||
|
|
||||||
$db = new Database\DBStudyActivity();
|
$db = new Database\DBStudyActivity();
|
||||||
@ -285,6 +332,9 @@ class StudyActivity {
|
|||||||
|
|
||||||
$this->getQuery();
|
$this->getQuery();
|
||||||
}
|
}
|
||||||
|
// 此活動已結束
|
||||||
|
else throw new Exception\StudyActivityFinishedException($this->id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在這次學習時間已過,是否強制結束學習
|
* 在這次學習時間已過,是否強制結束學習
|
||||||
|
Loading…
x
Reference in New Issue
Block a user