Don't use global environment in "setup_chatview_for_operator" func

This commit is contained in:
Dmitriy Simushev 2014-08-28 09:39:14 +00:00
parent ee492a0c23
commit 1c1d479474
3 changed files with 53 additions and 18 deletions

View File

@ -23,6 +23,8 @@ use Mibew\Settings;
use Mibew\Thread; use Mibew\Thread;
use Mibew\Style\ChatStyle; use Mibew\Style\ChatStyle;
use Mibew\Style\PageStyle; use Mibew\Style\PageStyle;
use Mibew\Routing\Generator\SecureUrlGeneratorInterface as UrlGeneratorInterface;
use Symfony\Component\HttpFoundation\Request;
/** /**
* Convert messages to formated text * Convert messages to formated text
@ -525,11 +527,18 @@ function setup_chatview_for_user(Thread $thread)
/** /**
* Prepare some data for chat for operator * Prepare some data for chat for operator
* *
* @param Thread $thread thread object * @param UrlGeneratorInterface $url_generator A URL generator object.
* @param Request $request The current request.
* @param Thread $thread thread object.
* @param array $operator Operator's data.
* @return array Array of chat view data * @return array Array of chat view data
*/ */
function setup_chatview_for_operator(Thread $thread, $operator) function setup_chatview_for_operator(
{ UrlGeneratorInterface $url_generator,
Request $request,
Thread $thread,
$operator
) {
$data = setup_chatview($thread); $data = setup_chatview($thread);
// Load JavaScript plugins and JavaScripts, CSS files required by them // Load JavaScript plugins and JavaScripts, CSS files required by them
@ -549,23 +558,29 @@ function setup_chatview_for_operator(Thread $thread, $operator)
); );
// Set SSL link // Set SSL link
if (Settings::get('enablessl') == "1" && !is_secure_request()) { if (Settings::get('enablessl') == "1" && !$request->isSecure()) {
$data['chat']['links']['ssl'] = get_app_location(true, true) $data['chat']['links']['ssl'] = $url_generator->generateSecure(
. "/operator/chat/" . $thread->id . '/' . $thread->lastToken; 'chat_operator',
array(
'thread_id' => $thread->id,
'token' => $thread->lastToken,
),
UrlGeneratorInterface::ABSOLUTE_URL
);
} }
// Set history window params // Set history window params
$data['chat']['links']['history'] = MIBEW_WEB_ROOT $data['chat']['links']['history'] = $url_generator->generate(
. '/operator/history/user/' 'history_user',
. ((string) $thread->userId); array('user_id' => $thread->userId)
);
// Set tracking params // Set tracking params
if (Settings::get('enabletracking')) { if (Settings::get('enabletracking')) {
$visitor = track_get_visitor_by_thread_id($thread->id); $visitor = track_get_visitor_by_thread_id($thread->id);
$tracked_link_params = array("visitor" => "" . $visitor['visitorid']); $data['chat']['links']['tracked'] = $url_generator->generate(
$data['chat']['links']['tracked'] = add_params( 'history_user_track',
MIBEW_WEB_ROOT . "/operator/history/user-track", array('visitor' => $visitor['visitorid'])
$tracked_link_params
); );
} }
@ -592,8 +607,13 @@ function setup_chatview_for_operator(Thread $thread, $operator)
$data['chat']['messageForm']['predefinedAnswers'] = $predefined_answers; $data['chat']['messageForm']['predefinedAnswers'] = $predefined_answers;
} }
// Set link to user redirection page // Set link to user redirection page
$data['chat']['links']['redirect'] = MIBEW_WEB_ROOT . "/operator/chat/" $data['chat']['links']['redirect'] = $url_generator->generate(
. $thread->id . '/' . $thread->lastToken . '/redirection-links'; 'chat_operator_redirection_links',
array(
'thread_id' => $thread->id,
'token' => $thread->lastToken,
)
);
$data['namePostfix'] = ""; $data['namePostfix'] = "";

View File

@ -61,7 +61,12 @@ class OperatorChatController extends AbstractController
return $this->showErrors(array('Cannot view threads')); return $this->showErrors(array('Cannot view threads'));
} }
$page = setup_chatview_for_operator($thread, $operator); $page = setup_chatview_for_operator(
$this->getRouter(),
$request,
$thread,
$operator
);
// Build js application options // Build js application options
$page['chatOptions'] = json_encode($page['chat']); $page['chatOptions'] = json_encode($page['chat']);

View File

@ -63,8 +63,18 @@ class RedirectController extends AbstractController
} }
$page = array_merge_recursive( $page = array_merge_recursive(
setup_chatview_for_operator($thread, $operator), setup_chatview_for_operator(
setup_redirect_links($this->getRouter()->getGenerator(), $thread_id, $operator, $token) $this->getRouter(),
$request,
$thread,
$operator
),
setup_redirect_links(
$this->getRouter()->getGenerator(),
$thread_id,
$operator,
$token
)
); );
// Render the page with redirection links. // Render the page with redirection links.