getQuery() 抓取資料表中所有資訊,並放在此陣列裡 * @type array */ protected $queryResultArray; /** * 從資料庫取得查詢 * * @throw \UElearning\Exception\ThemeNoFoundException * @since 2.0.0 */ protected function getQuery(){ // 從資料庫查詢 $db = new Database\DBStudy(); $info = $db->queryById($this->id); // 判斷有沒有這個 if( $info != null ) { $this->queryResultArray = $info; } else throw new Exception\StudyNoFoundException($this->id); } // ======================================================================== /** * 建構子 * * @param int $inputTID 主題ID * @since 2.0.0 */ public function __construct($inputID){ $this->id = $inputID; $this->getQuery(); } // ======================================================================== /** * 取得本進出記錄編號 * * @return int 進出記錄編號 * @since 2.0.0 */ public function getId(){ return $this->id; } /** * 取得本次活動編號 * * @return int 學習活動編號 * @since 2.0.0 */ public function getActivityId(){ return $this->queryResultArray['activity_id']; } /** * 取得標的編號 * * @return int 標的編號 * @since 2.0.0 */ public function getTargetId(){ return $this->queryResultArray['target_id']; } // /** // * 取得標的名稱 // * // * @return int 標的名稱 // * @since 2.0.0 // */ // public function getTargetName(){ // return $this->queryResultArray['target_id']; // } // /** // * 取得此紀錄的使用者ID // * // * @return string 使用者ID // * @since 2.0.0 // */ // public function getUserId(){ // return $this->queryResultArray['target_id']; // } /** * 是否為實體(實際抵達學習點) * * @return bool 是否為實體 * @since 2.0.0 */ public function isEntity(){ return $this->queryResultArray['is_entity']; } /** * 取得進入學習點時間 * * @return string 進入學習點時間 * @since 2.0.0 */ public function isIn(){ // TODO: 尚未測試 if($this->queryResultArray['out_target_time'] == null) { return true; } else { return false; } } /** * 取得進入學習點時間 * * @return string 進入學習點時間 * @since 2.0.0 */ public function getInTime(){ return $this->queryResultArray['in_target_time']; } /** * 取得離開學習點時間 * * @return string 離開學習點時間 * @since 2.0.0 */ public function getOutTime(){ return $this->queryResultArray['out_target_time']; } /** * 取得學習點時間 * * @return string 學習點時間 * @since 2.0.0 */ public function getElapsedSec(){ // 假如還在學習點內當中 if($this->isIn()) { // 現在時間-開始時間 = 已經過了多久 $nowDate = strtotime("now"); $startDate = strtotime($this->getInTime()); $elapsedDate = $nowDate - $startDate; $elapsedSec = (int)($elapsedDate); return $elapsedSec; } else { // 結束時間-開始時間 = 已經過了多久 $endDate = strtotime($this->getOutTime()); $startDate = strtotime($this->getInTime()); $elapsedDate = $endDate - $startDate; $elapsedSec = (int)($elapsedDate); return $elapsedSec; } } /** * 離開學習點 * * @since 2.0.0 */ public function toOut() { // 將資料庫內容標示已離開 $db = new Database\DBStudy(); $db->toOutTarget($this->id); // 將標的目前人數-1 if($this->isEntity()) { $target = new Target\Target($this->getTargetId); $target->addMj(-1); } } }