Ejemplo n.º 1
0
 public function populateDiscussionReplies($item_id, $discussion_id = 0)
 {
     $discussion_replies = array();
     $inc = 0;
     $return_fields = array();
     $q = Discussion::leftJoin('discussion_replies', 'discussion.discussion_id', '=', 'discussion_replies.discussion_id');
     if ($discussion_id) {
         $q->where('discussion_replies.discussion_id', '=', $discussion_id)->orderBy('discussion_replies.date_added', 'ASC');
         $return_fields = array('discussion_replies.notes', 'discussion_replies.is_main_thread', 'discussion_replies.added_by_user_id', DB::raw('DATE_FORMAT( discussion_replies.`DATE_ADDED` , \'%b %d, %Y\' ) AS date_added'));
     } else {
         $q->where('discussion_replies.added_by_user_id', '=', $this->logged_user_id)->where('item_id', '=', $item_id)->orderBy('date_added', 'ASC');
         $return_fields = array('discussion_replies.notes', 'discussion_replies.is_main_thread', 'discussion_replies.added_by_user_id', DB::raw('DATE_FORMAT( discussion_replies.`DATE_ADDED` , \'%b %d, %Y\' ) AS date_added', 'discussion.is_private', 'discussion.buyer_id', 'discussion.seller_id'));
     }
     $d_arr = $q->get($return_fields);
     $buyer_name = '';
     foreach ($d_arr as $row) {
         if ($row['is_main_thread']) {
             $user_details = CUtil::getUserDetails($row['added_by_user_id']);
             $discussion_replies['main_note'] = $row['notes'];
             $discussion_replies['buyer_name'] = $user_details['display_name'];
             $buyer_name = $discussion_replies['buyer_name'];
             $discussion_replies['icon'] = CUtil::getUserPersonalImage($row['added_by_user_id']);
             $discussion_replies['memberProfileUrl'] = $user_details['profile_url'];
             $discussion_replies['date_added'] = $row['date_added'];
             //Code to show private question and its replies only to buyer, seller and admin
             $discussion_replies['show_question_and_replies'] = true;
             if ($row['is_private'] == 1) {
                 $discussion_replies['show_question_and_replies'] = false;
                 if (CUtil::isStaff() || $this->logged_user_id == $row['buyer_id'] || $this->logged_user_id == $row['seller_id']) {
                     $discussion_replies['show_question_and_replies'] = true;
                 }
             }
         } else {
             $user_details = CUtil::getUserDetails($row['added_by_user_id']);
             $discussion_replies['replies'][$inc]['reply_note'] = $row['notes'];
             $discussion_replies['replies'][$inc]['seller_name'] = $user_details['display_name'];
             if ($discussion_replies['replies'][$inc]['seller_name'] == $buyer_name) {
                 $discussion_replies['replies'][$inc]['reply_label'] = trans("mp_product/viewProduct.add_product_query_buyer");
                 $discussion_replies['replies'][$inc]['replier_type'] = 'buyer';
             } else {
                 $discussion_replies['replies'][$inc]['reply_label'] = trans("mp_product/viewProduct.add_product_query_seller");
                 $discussion_replies['replies'][$inc]['replier_type'] = 'seller';
             }
             $discussion_replies['replies'][$inc]['icon'] = CUtil::getUserPersonalImage($row['added_by_user_id']);
             $discussion_replies['replies'][$inc]['memberProfileUrl'] = $user_details['profile_url'];
             $discussion_replies['replies'][$inc]['date_added'] = $row['date_added'];
             //Code to show private question and its replies only to buyer, seller and admin
             $discussion_replies['replies'][$inc]['show_question_and_replies'] = true;
             if ($row['is_private'] == 1) {
                 $discussion_replies['replies'][$inc]['show_question_and_replies'] = false;
                 if (CUtil::isStaff() || $this->logged_user_id == $row['buyer_id'] || $this->logged_user_id == $row['seller_id']) {
                     $discussion_replies['replies'][$inc]['show_question_and_replies'] = true;
                 }
             }
         }
         $inc++;
     }
     return $discussion_replies;
 }