public function defaultAction() { if (!$this->manager->hasLeaveFeedbackPermission()) { trigger_error($this->user->lang('E_CANNOT_LEAVE_FEEDBACK')); } $topic_id = $this->request->variable('topic_id', 0); $feedback_reply_id = $this->request->variable('reply_id', 0); $rating = $this->request->variable('trader_rating', 0); $short_comment = utf8_normalize_nfc(trim($this->request->variable('short_comment', '', true))); $long_comment = utf8_normalize_nfc(trim($this->request->variable('long_comment', '', true))); if ($feedback_reply_id) { $feedback_row = $this->manager->getAllFeedbackInfo($feedback_reply_id); } $topic_id = $topic_id ? $topic_id : $feedback_row['topic_id']; $topic_row = $this->getTopic($topic_id); $user_id = $feedback_reply_id ? $feedback_row['from_user_id'] : $topic_row['topic_poster']; $err_comments = array(); $feedback_route = $this->helper->route('rfd_trader_view', array('u' => $user_id)); $back_url = '<a href=' . append_sid(generate_board_url() . "/viewtopic.php?t=" . $topic_id) . '>« ' . $this->user->lang['BACK_TO_PREV'] . '</a>'; $submit = $this->request->is_set_post('submit'); $to_user_row = $this->getUser($user_id); if ($feedback_reply_id && !$feedback_row) { trigger_error($this->user->lang('E_FEEDBACK_NOT_FOUND')); } if ($feedback_reply_id && $this->user->data['user_id'] != $feedback_row['to_user_id']) { trigger_error($this->user->lang('E_CANNOT_RETURN_FEEDBACK')); } if (!$topic_row) { trigger_error($this->user->lang('TOPIC_NOT_FOUND')); } if (!$to_user_row) { trigger_error($this->user->lang('USER_NOT_FOUND')); } if ($to_user_row['user_id'] == $this->user->data['user_id']) { trigger_error($this->user->lang('CANNOT_RATE_SELF') . '</br></br>' . $back_url); } if ($this->user->data['user_id'] == ANONYMOUS) { trigger_error($this->user->lang('LOG_IN')); } if (!$this->manager->canGiveFeedback($user_id, $this->user->data['user_id'], $topic_id)) { trigger_error($this->user->lang('ALREADY_GIVEN_FEEDBACK') . '<br /><br />' . $back_url); } if ($submit && (strlen($short_comment) < self::MIN_SHORT_LENGTH || strlen($short_comment) > self::MAX_SHORT_LENGTH)) { $err_comments['short'] = '* Required 10-200 Characters'; } if ($submit && strlen($long_comment) > self::MAX_LONG_LENGTH) { $err_comments['long'] = true; } if ($submit && !$err_comments['short'] && !$err_comments['long']) { if (!check_form_key('give_feedback_form')) { trigger_error('FORM_INVALID'); } $feedback_result = $this->manager->giveFeedback($user_id, $this->user->data['user_id'], $feedback_reply_id, $rating, $topic_id, $topic_row['topic_title'], $topic_row['topic_trader_type'], $short_comment, $long_comment); $trader_profile_url = '<a href=' . $this->helper->route('rfd_trader_view', array('u' => $to_user_row['user_id'])) . '>' . $this->user->lang['VIEW_PROFILE'] . ' ' . $to_user_row['username'] . '</a>'; trigger_error($this->user->lang('FEEDBACK_SUCCESS') . '<br /><br />' . $trader_profile_url); } add_form_key('give_feedback_form'); $this->template->assign_vars(array('ERROR' => $err_comments, 'RATING' => $rating, 'SHORT' => $short_comment, 'LONG' => $long_comment, 'USERNAME' => $to_user_row['username'], 'TOPIC_TITLE' => $topic_row['topic_title'], 'TOPIC_TYPE' => $topic_row['topic_trader_type'], 'TRADER_USERNAME' => $to_user_row['username'], 'U_TRADER_FEEDBACK' => $feedback_route, 'U_TRADER_PROFILE' => append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", 'mode=viewprofile&u=' . $to_user_row['user_id']))); return $this->helper->render('TraderFeedback.html', $this->user->lang['FEEDBACK_TITLE'] . $to_user_row['username']); }
/** * Event: core.viewtopic_modify_post_row * * Send the BST Feedback rating of a particular user * to the template for a user's post. Note that this fires after core.viewtopic_post_rowset_data * * @param phpbbEvent $event * @return bool */ public function viewtopic_modify_post_row(phpbbEvent $event) { $data = $event->get_data(); // if trader is not enabled, don't show the rating if (!$data['topic_data']['enabled_trader_types']) { return false; } if (!$this->manager->showTrader($data['row']['post_id'], $data['row']['topic_id'])) { return false; } $feedback_url = $this->helper->route('rfd_trader_feedback', array('topic_id' => $data['row']['topic_id'])); // Set U_GIVE_FEEDBACK variable iff user has leave feedback permission if ($this->manager->hasLeaveFeedbackPermission()) { $data['post_row']['U_GIVE_FEEDBACK'] = $feedback_url; } $view_feedback_url = $this->helper->route('rfd_trader_view', array('u' => $data['row']['user_id'])); $data['post_row']['U_VIEW_FEEDBACK'] = $view_feedback_url; $positive = $data['row']['user_trader_positive']; $neutral = $data['row']['user_trader_neutral']; $negative = $data['row']['user_trader_negative']; $data['post_row']['user_trader_positive'] = $positive; $data['post_row']['user_trader_neutral'] = $neutral; $data['post_row']['user_trader_negative'] = $negative; $data['post_row']['user_trader_percentage'] = $this->manager->getPositivePercent($positive, $negative); $data['post_row']['user_trader_rating'] = $positive - $negative; $data['post_row']['title'] = "{$positive} " . $this->user->lang['POSITIVE'] . "\n{$neutral} " . $this->user->lang['NEUTRAL'] . "\n{$negative} " . $this->user->lang['NEGATIVE'] . ""; $event->set_data($data); }