/**
  * Search items
  * 
  * @param string $qStr : Query String
  * @param string $catStr : Category Name/ Category ID
  * @param string $locStr : Location / Location ID
  * @return array
  */
 public function search($qStr, $catStr, $locStr, $userID)
 {
     global $db;
     $tradeCatIns = new BuckysTradeCategory();
     $tradeLocationIns = new BuckysCountry();
     //Get category data
     $catData = null;
     if (is_numeric($catStr)) {
         $catData = $tradeCatIns->getCategoryByID($catStr);
     } else {
         $catData = $tradeCatIns->getCategoryByName($catStr);
     }
     //Get Location data
     $locationData = null;
     if (is_numeric($locStr)) {
         $locationData = $tradeLocationIns->getCountryById($locStr);
     } else {
         $locationData = $tradeLocationIns->getCountryByName($locStr);
     }
     //Make Where condition
     $whereCondList = array();
     if (isset($qStr) && $qStr != '') {
         $qStr = addslashes($qStr);
         $whereCondList[] = sprintf(" MATCH (i.title, i.subtitle, i.description) AGAINST ('%s' IN BOOLEAN MODE)", $qStr);
     }
     if (isset($catData)) {
         $whereCondList[] = 'i.catID=' . $catData['catID'];
     } else {
         if ($catStr != '') {
             return null;
         }
     }
     if (isset($locationData)) {
         $whereCondList[] = 'i.locationID=' . $locationData['countryID'];
     }
     if (isset($userID) && is_numeric($userID)) {
         $whereCondList[] = 'i.userID=' . $userID;
     }
     //Valid items
     $avaiableTime = date('Y-m-d H:i:s', time() - TRADE_ITEM_LIFETIME * 3600 * 24);
     $whereCondList[] = "i.createdDate >='" . $avaiableTime . "'";
     $whereCondList[] = 'i.status=' . BuckysTradeItem::STATUS_ITEM_ACTIVE;
     $whereCond = ' WHERE ' . implode(' AND ', $whereCondList);
     $whereCond .= ' GROUP BY i.itemID ';
     $query = sprintf("SELECT i.*, (SELECT COUNT(*) FROM %s AS o WHERE i.itemID=o.targetItemID AND o.status=%d) AS offer, u.firstName, u.lastName, tu.totalRating, tu.positiveRating \n                            FROM %s AS i \n                            LEFT JOIN %s AS tu ON i.userID=tu.userID \n                            LEFT JOIN %s AS u ON i.userID=u.userID \n                            ", TABLE_TRADE_OFFERS, BuckysTradeOffer::STATUS_OFFER_ACTIVE, TABLE_TRADE_ITEMS, TABLE_TRADE_USERS, TABLE_USERS);
     $query = $db->prepare($query . $whereCond);
     $data = $db->getResultsArray($query);
     return $data;
 }
예제 #2
0
$tradeCatIns = new BuckysTradeCategory();
$countryIns = new BuckysCountry();
$userIns = new BuckysUser();
$tradeOfferIns = new BuckysTradeOffer();
$view['item'] = $tradeItemIns->getItemById($paramItemID);
$view['myID'] = $userID;
if (!isset($view['item']) || $view['item']['status'] == BuckysTradeItem::STATUS_ITEM_INACTIVE) {
    buckys_redirect('/trade/index.php', MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
}
//Check if the items owner is active one
$userData = $userIns->getUserData($view['item']['userID']);
if ($userData['status'] == BuckysUser::STATUS_USER_BANNED) {
    buckys_redirect('/trade/index.php', MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
}
//Read more info from DB
$catData = $tradeCatIns->getCategoryByID($view['item']['catID']);
$view['item']['categoryName'] = isset($catData) ? $catData['name'] : '';
$countryData = $countryIns->getCountryById($view['item']['locationID']);
$view['item']['locationName'] = isset($countryData) ? $countryData['country_title'] : '';
$view['item']['userInfo'] = $userIns->getUserBasicInfo($view['item']['userID']);
if (!isset($view['item']['userInfo'])) {
    buckys_redirect('/trade/index.php', MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
}
//Check if you can make an offer to this user. If this user decline your offer before for this item, then you can't send again
$view['offerDisabled'] = false;
if (!$userID || $userID == $view['item']['userID']) {
    $view['offerDisabled'] = true;
} else {
    /**
     * If it has been set, then it means you can't make an offer if one of your offer declined by this user.
     * When you enable this block, please note BuckysTradeOffer::addOffer() function, there are parts disabled