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(); } }