/**
  * Add feedback
  *
  * @param mixed $writerID
  * @param mixed $score
  * @param mixed $feedback
  * @param mixed $activityID
  * @param mixed $activityType
  * @return int|null|string|void
  */
 public function addFeedback($writerID, $score, $feedback, $activityID, $activityType = BuckysFeedback::ACTIVITY_TYPE_TRADE)
 {
     global $db;
     if (!is_numeric($activityID) || !is_numeric($writerID) || !is_numeric($score) || $feedback == '') {
         return;
     }
     // failed
     //If you left feedback already, then return
     if ($this->hasFeedback($writerID, $activityID, $activityType)) {
         return;
     }
     //exists
     $param = ['activityID' => $activityID, 'activityType' => $activityType, 'writerID' => $writerID, 'score' => $score, 'comment' => $feedback, 'createdDate' => date('Y-m-d H:i:s')];
     $otherUserID = null;
     switch ($activityType) {
         case BuckysFeedback::ACTIVITY_TYPE_TRADE:
             $tradeIns = new BuckysTrade();
             $tradeData = $tradeIns->getTradeByID($activityID);
             if (!$tradeData) {
                 return;
             }
             //no such trade
             if ($tradeData['sellerID'] == $writerID) {
                 $otherUserID = $param['receiverID'] = $tradeData['buyerID'];
                 $param['itemID'] = $tradeData['buyerItemID'];
             } else {
                 if ($tradeData['buyerID'] == $writerID) {
                     $otherUserID = $param['receiverID'] = $tradeData['sellerID'];
                     $param['itemID'] = $tradeData['sellerItemID'];
                 } else {
                     return;
                     //no rights
                 }
             }
             break;
         case BuckysFeedback::ACTIVITY_TYPE_SHOP:
             $shopOrderIns = new BuckysShopOrder();
             $orderData = $shopOrderIns->getOrderByID($activityID);
             if (!$orderData || $orderData['buyerID'] != $writerID) {
                 return;
             }
             //no such trade
             $otherUserID = $param['receiverID'] = $orderData['sellerID'];
             $param['itemID'] = $orderData['productID'];
             break;
         default:
             return;
             //no such cases
             break;
     }
     $newID = $db->insertFromArray(TABLE_FEEDBACK, $param);
     if ($newID && $otherUserID) {
         //Update TradeUser Table for rating calculation
         $this->_updateRanking($otherUserID);
     }
     //Create notification
     $tradeNotificationIns = new BuckysTradeNotification();
     $tradeNotificationIns->createNotification($otherUserID, $writerID, BuckysTradeNotification::ACTION_TYPE_FEEDBACK, $newID);
     return $newID;
 }
 /**
  * Update feedback;
  *
  * @param integer $feedbackID
  * @param integer $userID
  * @param integer $score
  * @param string  $feedback
  * @return int|void
  */
 public function updateFeedback($feedbackID, $userID, $score, $feedback)
 {
     global $db;
     if (!is_numeric($feedbackID) || !is_numeric($userID) || !is_numeric($score) || $feedback == '') {
         return;
     }
     $feedbackData = $this->getFeedbackByID($feedbackID);
     $otherUserID = null;
     if (!$feedbackData) {
         return;
     }
     if ($feedbackData['sellerID'] == $userID && $feedbackData['sellerToBuyerScore'] == 0) {
         $param = ['sellerToBuyerScore' => $score, 'sellerToBuyerFeedback' => $feedback, 'sellerToBuyerFeedbackCreatedAt' => date('Y-m-d H:i:s')];
         $otherUserID = $feedbackData['buyerID'];
     } else {
         if ($feedbackData['buyerID'] == $userID && $feedbackData['buyerToSellerScore'] == 0) {
             $param = ['buyerToSellerScore' => $score, 'buyerToSellerFeedback' => $feedback, 'buyerToSellerFeedbackCreatedAt' => date('Y-m-d H:i:s')];
             $otherUserID = $feedbackData['sellerID'];
         } else {
             return;
             //no rights
         }
     }
     $res = $db->updateFromArray(TABLE_TRADE_FEEDBACK, $param, ['feedbackID' => $feedbackID]);
     if ($otherUserID) {
         //Update TradeUser Table for rating calculation
         $this->_updateRanking($otherUserID);
         //Create notification
         $tradeNotificationIns = new BuckysTradeNotification();
         $tradeNotificationIns->createNotification($otherUserID, $userID, BuckysTradeNotification::ACTION_TYPE_FEEDBACK, $feedbackID);
     }
     return $feedbackID;
 }
 /**
  * Decline offer
  *
  * @param integer $offerID
  */
 public function declineOffer($offerID)
 {
     global $db;
     if (!is_numeric($offerID)) {
         return;
     }
     $dateTimeStamp = date('Y-m-d H:i:s');
     $query = sprintf("UPDATE %s SET STATUS=%d, lastUpdateDate='%s' WHERE offerID=%d", TABLE_TRADE_OFFERS, BuckysTradeOffer::STATUS_OFFER_DECLINED, $dateTimeStamp, $offerID);
     $db->query($query);
     //Notification
     $tradeItemIns = new BuckysTradeItem();
     $offerData = $this->getOfferByID($offerID);
     if ($offerData) {
         $buyerItemData = $tradeItemIns->getItemById($offerData['offeredItemID']);
         $sellerItemData = $tradeItemIns->getItemById($offerData['targetItemID']);
         if ($buyerItemData) {
             //Create notification
             $tradeNotificationIns = new BuckysTradeNotification();
             $tradeNotificationIns->createNotification($buyerItemData['userID'], $sellerItemData['userID'], BuckysTradeNotification::ACTION_TYPE_OFFER_DECLINED, $offerID);
         }
     }
 }