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 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 = "m.id"; } $sql = "SELECT m.*,md.viewed, ds.id as datasetid FROM {$this->table->metadata} m LEFT join {$this->table->metadata_stat} md on m.uuid=md.uuid LEFT JOIN mdstatus st ON md.uuid=st.uuid left join dataset ds on m.uuid=ds.uuid $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 fetch($id) { if(is_numeric($id)) { $sql = "SELECT * FROM {$this->table->metadata} WHERE id=$id"; }else if(\Sookon\Helpers\Uuid::test($id)){ $sql = "SELECT * FROM {$this->table->metadata} WHERE uuid='$id'"; }else{ return false; } $rs = $this->db->query($sql); return $rs->fetch(); } }