Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Sort & filter query
- *
- * @sorts (array) $sorts - Array containing sort and filter options
- */
- public function sortFilter($sorts, $user_id) {
- $tab = "";
- $letter = "";
- $userIDS = array();
- $sort = "";
- $active = "";
- $setLetter = "";
- $setYear = "";
- $lett = "";
- $follow = "";
- $ref = "";
- $prep = "";
- $year = false;
- if(array_key_exists('tab', $sorts) && $sorts['tab'] === "follow")
- {
- $tab = "follow";
- $params = array();
- $prep = array();
- $ref = array();
- $userIDS = $this->userTools->userFollowing($user_id);
- foreach($userIDS as $id)
- {
- $ref[] = $id['followed'];
- }
- $params = implode(",", array_fill(0, count($userIDS), "?"));
- $prep = implode("", array_fill(0, count($userIDS), "i"));
- $follow = "i.user_id IN (".$params.") AND";
- $active = 1;
- $order = "i.id DESC";
- }
- else if(array_key_exists('tab', $sorts) && $sorts['tab'] === "expired")
- {
- $tab = "expire";
- $active = 0;
- $order = "i.id DESC";
- //echo "Expire tab";
- }else{
- $tab = "latest";
- $active = 1;
- $order = "i.id DESC";
- //echo "Latest tab";
- }
- if(array_key_exists('letter', $sorts))
- {
- $letter = $sorts['letter'];
- $let = array();
- $ref[] = $letter;
- $params = $letter;
- $prep = "s";
- $setLetter = "AND i.item_title LIKE CONCAT(?, '%')";
- }
- if(array_key_exists('publisher', $sorts))
- {
- $issue = $sorts['publisher'];
- $setIssue = "AND i.item_number = ?";
- }
- if(array_key_exists('year', $sorts))
- {
- $year = $sorts['year'];
- $yearArr = array();
- $yearArr[] = $sorts['year'];
- $ref = $this->helperClass->valRef($yearArr);
- $params = $year;
- $prep = "i";
- $setYear = "AND i.year = ?";
- }
- if(array_key_exists('number', $sorts))
- {
- $issue = $sorts['number'];
- $setIssue = "AND i.item_number = ?";
- }
- if(array_key_exists('cond', $sorts))
- {
- $cond = $sorts['cond'];
- $setCond = "AND i.item_condition = ?";
- }
- if(array_key_exists('option', $sorts) && $sorts['option'] === "low-shipping")
- {
- //echo "LOW SHIP";
- $sort = "low_shipping";
- $order = "c.ship_cost ASC";
- }
- if(array_key_exists('option', $sorts) && $sorts['option'] === "low-price")
- {
- //echo "LOW PRICE";
- $sort = "low_price";
- $order = "maxbid ASC, i.item_start ASC";
- }
- if(array_key_exists('option', $sorts) && $sorts['option'] === "high-price")
- {
- //echo "HIGH PRICE";
- $sort = "high-price";
- $order = "maxbid, i.item_start DESC";
- }
- if( !empty($userIDS) && $letter )
- {
- $ref = array();
- foreach($userIDS as $id)
- {
- $ref[] = $id['followed'];
- }
- $ref[] = $letter;
- $params = implode(",", array_fill(0, count($userIDS), "?"))."?";
- $prep = implode("", array_fill(0, count($userIDS), "i"))."s";
- }
- $q = $this->db->mysqli->prepare("SELECT c.ship_cost, c.item_id, i.id, i.user_id, i.item_title, i.item_number, i.item_year, i.item_condition, i.item_start, i.item_description, i.active, u.first_name, u.last_name, CAST(u.fb_id AS CHAR(50)) AS fb_id, u.user_pic, MAX(b.bid) AS maxbid, COUNT(b.bid) AS bids, p.publisher_name
- FROM countries_ship c
- JOIN items i
- ON c.item_id = i.id
- JOIN users u
- ON i.user_id = u.id
- LEFT JOIN bids b
- ON i.id = b.item_id
- LEFT JOIN publishers p
- ON i.item_publisher = p.id
- WHERE ".$follow." i.active = ".$active." ".$setLetter." ".$setYear."
- GROUP BY i.id
- ORDER BY ".$order." LIMIT 18");
- if( $tab === "follow" || $letter || $year)
- {
- call_user_func_array('mysqli_stmt_bind_param', array_merge ( array($q, $prep), $this->helperClass->valRef($ref) ) );
- }
- $q->execute();
- $rows = $this->helperClass->bindResults($q);
- $q->close();
- return $rows;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement