public static function getAllBidbyId($id) { $select = new SelectPDO(); $select->from("bid", ["bid.*", "lot.title", "user.first_name", "user.last_Name"])->where("`bid`.`lot_id` = ?", array($id))->join("lot", "lot_id", "id")->join("user", "user_id", "id"); $data = AbstractModel::getOnComplexQuery($select); return $data; }
/** * @param SelectPDO $select * @return string */ public function selectColumn(SelectPDO $select) { try { $doQuery = $this->db->prepare($select->query()); if ($doQuery) { $doQuery->execute($select->params); } return $doQuery->fetchColumn(); } catch (PDOException $e) { echo $e->getMessage(); } }
/** * this function shows us our all lots * */ public function actionMyLots() { if ($this->request->order == "") { $products = MyProduct::getMyProduct($this->user->id); if (!$products) { $products = []; } $countLots = $this->user->getQuantityLots(); $countBids = $this->user->getQuantityBids(); if ($countLots == "") { $countLots = 0; } if ($countBids == "") { $countBids = 0; } $this->view->lots = $countLots; $this->view->countBids = $countBids; $this->view->user = $this->name; $this->view->products = $products; $this->view->render('mylots'); $this->view->display(); } else { $id = (int) $_POST["order"]; $fields = ["title", "description", "current_price", "id", "front_img", "created"]; $where = "user_id = ? "; $user_id = $this->user->id; $select = new SelectPDO(); $select->from("lot", $fields)->where($where, array($user_id)); switch ($id) { case '0': $select->order("current_price", false); break; case '1': $select->order("current_price", true); break; case '2': $select->order("created"); break; default: $select->order("title"); break; } $data = AbstractModel::getOnComplexQuery($select); $data = json_encode($data); echo $data; exit; $products = MyProduct::getMyProduct($this->user->id); echo json_encode($products); } }
/** * created by Yosin */ public function actionSearch() { $request = new Request(); if ($request->searchGood != "") { $minLength = 2; $select = new SelectPDO(); $select->from("lot", ["lot.*", "user.email", "user.phone"])->join("bid", "id", "lot_id")->join("user", "user_id", "id"); $results = AbstractModel::search($select, ["title", "description"], $request->searchGood, $minLength, false, true); } else { $results = []; } if (!$results) { $results = []; } $this->view->lastGoods = $results; $this->view->render('search'); $this->view->display(); }
private function maxPrice() { /* $sql = "SELECT max(b.value) m , l.id FROM lot l JOIN bid b ON l.id=b.lot_id WHERE is_active=1 GROUP BY lot_id"; */ $select = new SelectPDO(); $select->from('lot', ['MAX(bid.value) maxBid', 'lot.id'])->join('bid', 'id', 'lot_id')->where('lot.is_active=1')->group('lot_id'); //exit($select->query()); return $this->getOnComplexQuery($select); }
/** * search product * * @param $request * @param $id * @return array|bool */ public static function searchProduct($request, $id) { $minLength = 2; $field = $request->field; if ($field == "lot") { $select = new SelectPDO(); $select->from($field, "*")->where("`user_id` = ?", [$id]); $results = AbstractModel::search($select, ["title", "description"], $request->searchText, $minLength = 2, false, true); } else { if ($field == "bid") { $select = new SelectPDO(); $select->from("lot", ["lot.*", "user.email", "user.phone"])->where("`bid`.`user_id` = ?", [$id])->join("bid", "id", "lot_id")->join("user", "user_id", "id"); $results = AbstractModel::search($select, ["title", "description"], $request->searchText, $minLength, false, true); } } return $results; }
/** * get all data from joined tables * * @param $class * @param $table * @param $join * @return array|bool */ public static function getAllWithJoin($class, $table, $fields, $join) { $select = new SelectPDO(); $select->from($table, $fields); if (count($join) > 0) { foreach ($join as $field) { $select->join($field[0], $field[1], $field[2]); } } $data = self::$db->select($select); return AbstractModel::createObjects($class, $data); }