114 lines
2.4 KiB
PHP
114 lines
2.4 KiB
PHP
<?php
|
|
namespace Sookon\Article;
|
|
|
|
use Sookon\Helpers\View as view;
|
|
use Sookon\Helpers\Dbh as dbh;
|
|
use Sookon\Helpers\PDO;
|
|
use Sookon\Helpers\Config;
|
|
use Sookon\Helpers\Table;
|
|
use Zend\Http\PhpEnvironment\Request;
|
|
use Zend\EventManager\EventManagerInterface;
|
|
use Zend\EventManager\EventManager;
|
|
use Zend\EventManager\EventManagerAwareInterface;
|
|
|
|
class Lists
|
|
{
|
|
private $db; //传入PDO对象
|
|
private $config; //站点设置
|
|
private $table;
|
|
|
|
public $opt;
|
|
|
|
protected $events = NULL;
|
|
|
|
function __construct()
|
|
{
|
|
$this->db = new PDO;
|
|
$this->config = Config::get();
|
|
$this->table = new Table;
|
|
|
|
$this->opt = new \stdClass();
|
|
|
|
$this->opt->sort = "DESC";
|
|
$this->opt->logic = "AND";
|
|
}
|
|
|
|
public function setEventManager(EventManagerInterface $events)
|
|
{
|
|
$events->setIdentifiers(array(
|
|
__CLASS__,
|
|
get_called_class(),
|
|
));
|
|
$this->events = $events;
|
|
return $this;
|
|
}
|
|
|
|
public function getEventManager()
|
|
{
|
|
if (NULL === $this->events) {
|
|
$this->setEventManager(new EventManager());
|
|
}
|
|
return $this->events;
|
|
}
|
|
|
|
public function fetchAll()
|
|
{
|
|
$wheresql = array();
|
|
|
|
if(isset($this->opt->where) && !empty($this->opt->where))
|
|
$wheresql = array_merge($wheresql,$this->opt->where);
|
|
|
|
if(count($wheresql)>0)
|
|
{
|
|
$wheresql = " WHERE ".join($wheresql," ".$this->opt->logic." ");
|
|
}else{
|
|
$wheresql = '';
|
|
}
|
|
|
|
if(!empty($this->opt->order))
|
|
{
|
|
$order = $this->opt->order;
|
|
}else{
|
|
$order = "ar.id";
|
|
}
|
|
|
|
$sql = "SELECT
|
|
ar.*,cate.code
|
|
FROM {$this->table->arc_article} ar
|
|
LEFT JOIN (select aid,min(cid) as cid from {$this->table->arc_catelog} group by aid) as log ON ar.id = log.aid
|
|
LEFT JOIN {$this->table->arc_category} cate ON log.cid = cate.id
|
|
$wheresql
|
|
ORDER BY $order {$this->opt->sort}
|
|
";
|
|
|
|
if(!empty($this->opt->start))
|
|
{
|
|
$sql .= " START {$this->opt->start} ";
|
|
}
|
|
|
|
if(!empty($this->opt->limit)){
|
|
$sql .= " LIMIT {$this->opt->limit} ";
|
|
}
|
|
//view::Dump($sql);
|
|
$rs = $this->db->query($sql);
|
|
return $rs->fetchAll();
|
|
}
|
|
|
|
public function getByCode($code)
|
|
{
|
|
if(empty($code))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//$category = new \Sookon\Article\Category;
|
|
//$category->fetch($code);
|
|
|
|
$this->opt->where = array(
|
|
" cate.code = '$code' "
|
|
);
|
|
|
|
return $this->fetchAll();
|
|
}
|
|
|
|
} |