You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

106 lines
2.4 KiB

<?php
require_once('DAO.php');
class NewsDAO extends DAO {
private $newsTable = 'news';
private $newsCategoryTable = 'news_categories';
function __construct() {
$this->pdo = new DB_Access(ENUM::DBLocate, ENUM::DBName, ENUM::DBUser, ENUM::DBPassword);
}
/**
* 取得最新消息列表
*
* @param [int] $pages 第幾頁
* @param [int] $limit 每頁筆數
* @return array
*/
function getNewsList($pages, $limit){
$pagesStr = '';
// $start = ($pages-1)*$limit;
// $pagesStr.= ' LIMIT :pages , :limit';
$paramArr = array();
// $paramArr['pages'] = $start;
// $paramArr['limit'] = $limit;
$sqlStr = " SELECT n.uuid, n.title, n.news_source, n.publish_date, c.title as category FROM ".$this->newsTable." n LEFT JOIN ".$this->newsCategoryTable." c ON n.category_id = c.uuid WHERE n.status = 1 ORDER BY n.publish_date DESC ".$pagesStr." ; ";
return $this->pdo->execute($sqlStr, $paramArr);
}
/**
* 取得最新消息內容
*
* @param [int] $dataId 最新消息 id
* @return array
*/
function getNewsContent($dataId){
$sqlStr = " SELECT uuid, title, news_image, news_image_alt, news_image2, news_image_alt2, news_content, publish_date, news_source FROM ".$this->newsTable." WHERE uuid = :id ";
return $this->pdo->execute($sqlStr, array('id'=>$dataId));
}
/**
* 依名稱取得分類內容
*
* @param string $title
* @return array
*/
function getNewsCategoryByTitle($title){
$sqlStr = " SELECT uuid, title FROM ".$this->newsCategoryTable." WHERE title = :title ";
return $this->pdo->execute($sqlStr, array('title'=>$title));
}
/**
* 寫入分類資料
*
* @param array $dataArray
* @return boolean
*/
function addCategoryData($dataArray){
$this->pdo->insert($this->newsCategoryTable, $dataArray);
if ( !is_null($this->pdo->getLastId()) && $this->pdo->getLastId() != 0 ){
return $this->pdo->getLastId();
}
return false;
}
/**
* 寫入最新消息資料
*
* @param array $dataArray
* @return boolean
*/
function addNewsData($dataArray){
$this->pdo->insert($this->newsTable, $dataArray);
if ( !is_null($this->pdo->getLastId()) && $this->pdo->getLastId() != 0 ){
return $this->pdo->getLastId();
}
return false;
}
function transaction(){
$this->pdo->transaction();
}
function rollbackDB(){
$this->pdo->rollbackDB();
}
function commitDB(){
$this->pdo->commitDB();
}
function closeDB(){
$this->pdo->closeDB();
}
function getLastId(){
$this->pdo->getLastId();
}
}
?>