public function take($what = " * ", $where = "") { if (!$this->is_ready_test()) { return; } if (!empty($where)) { $where = " WHERE " . $where . " "; } $result = EDatabase::sq("SELECT {$what} FROM " . $this->table . " {$where}"); return $result; }
public function ocs_content_list($searchstr, $sortmode = "new", $page = 1, $pagesize = 10, $user = "", $category = "") { $whereuser = ""; $wherecategory = ""; if (empty($page)) { $page = 1; } //setting dynamic page size $page = abs(($page - 1) * $pagesize); switch ($sortmode) { case "new": $where = "ORDER BY id DESC LIMIT {$page},{$pagesize}"; break; case "alpha": $where = "ORDER BY name ASC LIMIT {$page},{$pagesize}"; break; case "high": $where = "ORDER BY score DESC LIMIT {$page},{$pagesize}"; break; case "down": $where = "ORDER BY downloads DESC LIMIT {$page},{$pagesize}"; break; default: $where = "ORDER BY id DESC LIMIT {$page},{$pagesize}"; break; } //TODO: move this into parent class constructor // or better: inspect why datatable isn't initialized by constructor if (is_null($this->datatable)) { $this->datatable = new EModel("ocs_content"); } if (!empty($searchstr)) { $this->datatable->add_condition("name LIKE '%{$searchstr}%'"); } if (!empty($user)) { $this->datatable->add_condition("personid = '{$user}'"); } if (!empty($category)) { $this->datatable->add_condition("type = '{$category}'"); } $r = $this->datatable->find("id,owner,personid,description,changelog,preview1,votes,score,name,type,downloadname1,downloadlink1,version,summary,license", "{$where}"); // adjusting correct keys for ($i = 0; $i < count($r); $i++) { if (isset($r[$i]['preview1']) and !empty($r[$i]['preview1'])) { $r[$i]['previewpic1'] = $r[$i]['preview1']; $r[$i]['preview1'] = ''; } if (isset($r[$i]['type']) and !empty($r[$i]['type'])) { $r[$i]['typeid'] = $r[$i]['type']; unset($r[$i]['type']); } } $this->totalitems = EDatabase::sq("SELECT COUNT(*) FROM ocs_content WHERE name LIKE '%{$searchstr}%' {$whereuser} {$wherecategory}"); return $r; }
public static function last_insert_id() { $r = EDatabase::sq("SELECT LAST_INSERT_ID()"); return $r; }