本文整理汇总了PHP中Messages::_方法的典型用法代码示例。如果您正苦于以下问题:PHP Messages::_方法的具体用法?PHP Messages::_怎么用?PHP Messages::_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Messages
的用法示例。
在下文中一共展示了Messages::_方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_auto_marking_sc
function test_auto_marking_sc($request)
{
Authenticator::assert_manager_or_professor($request->cookies['authToken']);
$msg = new Messages($GLOBALS['locale'], '/new-question/errors');
try {
$model = new Model();
$raw_input = $request->getBody();
$content_type = explode(';', $request->type)[0];
if ($content_type !== 'application/json') {
Util::output_errors_and_die($msg->_('invalid-format'), 415);
}
$input_data = json_decode($raw_input, true);
if (empty($input_data) || !isset($input_data['question']) || !isset($input_data['source-code']) || !is_string($input_data['source-code'])) {
Util::output_errors_and_die($msg->_('invalid-format'), 400);
}
$extra = !empty($input_data['extra']) ? $input_data['extra'] : [];
$qd = $input_data['question'];
set_empty_if_undefined($qd['type']);
if ($qd['type'] != 'source-code') {
Util::output_errors_and_die('', 400);
}
$q = new QuestionSC($qd, Question::FROM_USER, $extra);
$q->mark_automatically(array('source-code' => $input_data['source-code']), $log, $result);
http_response_code(200);
header('Content-Type: application/json');
echo my_json_encode($result);
} catch (DatabaseException $e) {
Util::output_errors_and_die($e->getMessage(), 503);
} catch (Exception $e) {
Util::output_errors_and_die($e->getMessage(), 400);
}
}
示例2: test_auto_marking
function test_auto_marking($request)
{
Authenticator::assert_manager_or_professor($request->cookies['authToken']);
$msg = new Messages($GLOBALS['locale'], '/new-question/errors');
try {
$model = new Model();
$raw_input = $request->getBody();
$content_type = explode(';', $request->type)[0];
if ($content_type !== 'application/json') {
Util::output_errors_and_die($msg->_('invalid-format'), 415);
}
$input_data = json_decode($raw_input, true);
if (empty($input_data) || !isset($input_data['question']) || !isset($input_data['studentAnswer'])) {
Util::output_errors_and_die($msg->_('invalid-format'), 400);
}
$extra = !empty($input_data['extra']) ? $input_data['extra'] : [];
$qd = $input_data['question'];
set_empty_if_undefined($qd['type']);
if (!Validator::validate_question_type($qd['type'])) {
Util::output_errors_and_die($msg->_('invalid-type'), 400);
}
switch ($qd['type']) {
case 'short-answer':
$q = new QuestionSA($qd, Question::FROM_USER, $extra);
break;
case 'essay':
$q = new QuestionES($qd, Question::FROM_USER, $extra);
break;
case 'multiple-choice':
$q = new QuestionMC($qd, Question::FROM_USER, $extra);
break;
case 'matching':
$q = new QuestionMA($qd, Question::FROM_USER, $extra);
break;
case 'fitb-type':
$q = new QuestionFT($qd, Question::FROM_USER, $extra);
break;
case 'fitb-select':
$q = new QuestionFS($qd, Question::FROM_USER, $extra);
break;
case 'source-code':
$q = new QuestionSC($qd, Question::FROM_USER, $extra);
break;
}
http_response_code(200);
header('Content-Type: application/json');
$mark = $q->mark_automatically($input_data['studentAnswer'], $log);
foreach ($log as $i => $line) {
$log[$i] = $msg->_('/auto-marking/' . $line[0], $line[1]);
}
$log = implode('<br/>', $log);
echo my_json_encode(array('log' => $log, 'mark' => $mark));
} catch (DatabaseException $e) {
Util::output_errors_and_die($e->getMessage(), 503);
} catch (Exception $e) {
Util::output_errors_and_die($e->getMessage(), 400);
}
}
示例3: create_session
function create_session($request)
{
$raw_input = $request->getBody();
$content_type = explode(';', $request->type)[0];
switch ($content_type) {
case 'application/json':
$input_data = json_decode($raw_input, true);
break;
case 'application/x-www-form-urlencoded':
$input_data = array();
parse_str($raw_input, $input_data);
break;
default:
Util::output_errors_and_die('', 415);
}
if ($input_data === null) {
Util::output_errors_and_die('', 400);
}
set_empty_if_undefined($input_data['username_or_email']);
set_empty_if_undefined($input_data['password']);
$msg = new Messages($GLOBALS['locale'], '/signin');
try {
$model = new Model();
$user_data = $model->is_valid_user($input_data['username_or_email'], $input_data['password']);
if (!$user_data) {
Util::output_errors_and_die($msg->_('invalid-username-pw'), 403);
}
switch ($user_data['status']) {
case 'pending-activation':
Util::output_errors_and_die($msg->_('pending-activation'), 403);
break;
case 'pending-approval':
Util::output_errors_and_die($msg->_('pending-approval'), 403);
break;
case 'banned':
Util::output_errors_and_die($msg->_('banned'), 403);
break;
case 'active':
$token = generate_token($user_data);
$now = new DateTime('now');
$expires_at = clone $now;
$expires_at->add(new DateInterval('P7D'));
$model->insert_auth_token($user_data['user_id'], $token, $now, $expires_at);
http_response_code(201);
$output = array('token' => $token, 'expires_at' => $expires_at->format('Y-m-d H:i:s'));
setcookie('authToken', $token, $expires_at->getTimestamp(), '/', '', $secure = true, $httponly = true);
header('Content-Type: application/json');
echo my_json_encode($output);
die;
break;
}
} catch (DatabaseException $e) {
Util::output_errors_and_die($e->getMessage(), 503);
} catch (Exception $e) {
Util::output_errors_and_die($e->getMessage(), 400);
}
}
示例4: test_question
function test_question($request)
{
Authenticator::assert_manager_or_professor($request->cookies['authToken']);
$msg = new Messages($GLOBALS['locale'], '/new-question/errors');
try {
$model = new Model();
$raw_input = $request->getBody();
$content_type = explode(';', $request->type)[0];
if ($content_type !== 'application/json') {
Util::output_errors_and_die($msg->_('invalid-format'), 415);
}
$input_data = json_decode($raw_input, true);
if (empty($input_data)) {
Util::output_errors_and_die($msg->_('invalid-format'), 400);
}
set_empty_if_undefined($input_data['type']);
if (!Validator::validate_question_type($input_data['type'])) {
Util::output_errors_and_die($msg->_('invalid-type'), 400);
}
switch ($input_data['type']) {
case 'short-answer':
$q = new QuestionSA($input_data, Question::FROM_USER);
break;
case 'essay':
$q = new QuestionES($input_data, Question::FROM_USER);
break;
case 'multiple-choice':
$q = new QuestionMC($input_data, Question::FROM_USER);
break;
case 'matching':
$q = new QuestionMA($input_data, Question::FROM_USER);
break;
case 'fitb-type':
$q = new QuestionFT($input_data, Question::FROM_USER);
break;
case 'fitb-select':
$q = new QuestionFS($input_data, Question::FROM_USER);
break;
case 'source-code':
$q = new QuestionSC($input_data, Question::FROM_USER);
break;
}
http_response_code(200);
header('Content-Type: application/json');
echo my_json_encode($q->to_auto_marking_test(true, true));
} catch (DatabaseException $e) {
Util::output_errors_and_die($e->getMessage(), 503);
} catch (Exception $e) {
Util::output_errors_and_die($e->getMessage(), 400);
}
}
示例5: assert_manager
public static function assert_manager($token)
{
$user_data = self::assert_user($token);
if ($user_data['role'] !== 'manager') {
$msg = new Messages($GLOBALS['locale']);
Util::output_errors_and_die($msg->_('/authentication/only-managers'), 403);
}
return $user_data;
}
示例6: __construct
public function __construct($message = null, $code = 0)
{
if ($message) {
$msg = new Messages($GLOBALS['locale']);
$err = array('DATABASE-ERROR' => $msg->_('/showmsg/database-error'));
// discard original message
$message = my_json_encode($err);
}
parent::__construct($message, $code);
}
示例7: create_question
function create_question($request, $assignment_id = null)
{
Authenticator::assert_manager_or_professor($request->cookies['authToken']);
$msg = new Messages($GLOBALS['locale']);
try {
$model = new Model();
$raw_input = $request->getBody();
$content_type = explode(';', $request->type)[0];
if ($content_type !== 'application/json') {
Util::output_errors_and_die('', 415);
}
$input_data = json_decode($raw_input, true);
if (empty($input_data)) {
Util::output_errors_and_die('', 400);
}
set_empty_if_undefined($input_data['type']);
if (!Validator::validate_question_type($input_data['type'])) {
Util::output_errors_and_die($msg->_('invalid-type'), 400);
}
switch ($input_data['type']) {
case 'short-answer':
$q = new QuestionSA($input_data, Question::FROM_USER);
break;
case 'essay':
$q = new QuestionES($input_data, Question::FROM_USER);
break;
case 'multiple-choice':
$q = new QuestionMC($input_data, Question::FROM_USER);
break;
case 'matching':
$q = new QuestionMA($input_data, Question::FROM_USER);
break;
case 'fitb-type':
$q = new QuestionFT($input_data, Question::FROM_USER);
break;
case 'fitb-select':
$q = new QuestionFS($input_data, Question::FROM_USER);
break;
case 'source-code':
$q = new QuestionSC($input_data, Question::FROM_USER);
break;
}
$qid = $model->create_question($q);
header('Content-Type: text/plain');
echo '/question_bank/questions/' . $qid;
http_response_code(201);
die;
} catch (ConflictException $e) {
Util::output_errors_and_die($e->getMessage(), 409);
} catch (DatabaseException $e) {
Util::output_errors_and_die($e->getMessage(), 503);
} catch (Exception $e) {
Util::output_errors_and_die($e->getMessage(), 400);
}
}
示例8: Messages
htmlout($GLOBALS['system-name']);
?>
</h1>
</div>
<?php
$msg = new Messages($GLOBALS['locale'], 'signin');
include 'login-form.html.php';
?>
<div class="container">
<form action="signup" method="post">
<div class="form-group centre">
<input type="submit" class="btn btn-primary"
value="<?php
htmlout($msg->_('new-user'));
?>
"
/>
<input type="hidden" name="action" value="newuser"/>
</div>
</form>
<form action="forgotpw" method="get">
<div class="form-group centre">
<input type="submit" class="btn btn-secondary"
value="<?php
htmlout($msg->_('forgot-password'));
?>
示例9: Messages
<?php
$msg = new Messages($GLOBALS['locale']);
Authenticator::assert_manager($_COOKIE['authToken']);
try {
$model = new Model();
$q = array('fields' => 'username,email,full_name,role,created_at', 'status' => 'pending-approval');
$pending_users = $model->get_users($q);
} catch (DatabaseException $e) {
Util::output_errors_and_die($msg->_('/showmsg/database-error'), 503);
}
include 'page.html.php';
示例10: Messages
<?php
$msg = new Messages($GLOBALS['locale'], '/question-student');
?>
<div class="qSt-fs-field-container hidden-template"></div>
<div class="qSt-fs-answers-container">
<div>
<label>
<?php
htmlout($msg->_('/question-student/fs-choose'));
?>
</label>
<div class="help-block qSt-fs-dummy-help" style="display: none">
<?php
htmlout($msg->_('/question-student/fs-dummy'));
?>
</div>
</div>
<div class="qSt-fs-field hidden-template">
<span class="qSt-fs-answer-text">
</span>
<span class="qSt-fs-answer-remove"
title="<?php
htmlout($msg->_('/question-student/fs-remove'));
?>
"
>
示例11: Messages
<?php
$msg = new Messages($GLOBALS['locale'], '/question-student');
?>
<div class="form-group">
<label>
<?php
htmlout($msg->_('sa-answer'));
?>
</label>
<input type="text" class="form-control qSt-sa-answer"
maxlength="1048576"
/>
</div>
示例12: Messages
<?php
$msg = new Messages($GLOBALS['locale']);
$db_created = file_exists(get_config_dir() . '/dbsettings.ini');
try {
$model = new Model($first_run = !$db_created);
} catch (DatabaseException $e) {
exit_with_message($msg->_('/showmsg/database-error'));
die;
}
$has_manager = ($db_created and $model->has_manager());
if (!$has_manager) {
header('Location: firstrun');
die;
}
if (isset($_COOKIE['authToken'])) {
$user_data = $model->is_valid_auth_token($_COOKIE['authToken']);
if ($user_data) {
include 'home.html.php';
die;
}
}
// not logged in
include 'login.html.php';
示例13: Messages
<!DOCTYPE html>
<?php
$msg = new Messages($GLOBALS['locale'], 'signup');
?>
<html lang="<?php
htmlout($msg->get_short_language_code());
?>
">
<head>
<meta charset="utf-8">
<title><?php
htmlout($msg->_('signup'));
?>
</title>
<?php
include_headers();
?>
<link href="/static/css/main.css" rel="stylesheet" />
<link href="/static/css/signup.css" rel="stylesheet" />
</head>
<body>
<div class="container">
<p class="text-center">
<?php
htmlout($msg->_('pleasefillform'));
?>
</p>
<p class="text-center">
<?php
htmlout($msg->_('asterisk-required'));
示例14: Messages
<!DOCTYPE html>
<?php
$msg = new Messages($GLOBALS['locale'], 'home');
$user_data;
$role = $user_data['role'];
$show_courses = true;
$show_question_bank = ($role === 'professor' or $role === 'manager');
$show_users = $role === 'manager';
$show_programming_languages = ($role === 'professor' or $role === 'manager');
$msg = new Messages($GLOBALS['locale'], 'home');
$greeting = $msg->_('greetings/hello');
?>
<html lang="<?php
htmlout($msg->get_short_language_code());
?>
">
<head>
<meta charset="utf-8">
<title><?php
htmlout($GLOBALS['system-name']);
?>
</title>
<?php
include_headers();
?>
<link rel="stylesheet" type="text/css" href="/static/css/main.css" />
<link rel="stylesheet" type="text/css" href="/static/css/navbar.css" />
<?php
echo '<script> var acceptLanguages = ' . json_encode(accept_languages());
echo '; </script>';
?>
示例15: Messages
<?php
$msg = new Messages($GLOBALS['locale']);
?>
<div class="qSt-container">
<div class="qSt-title-wrapper">
<h3 class="qSt-title">
</h3>
<span class="label label-primary qSt-level"
data-msg-easy = "<?php
htmlout($msg->_('/levels/easy'));
?>
"
data-msg-intermediate = "<?php
htmlout($msg->_('/levels/intermediate'));
?>
"
data-msg-hard = "<?php
htmlout($msg->_('/levels/hard'));
?>
"
data-msg-very-hard = "<?php
htmlout($msg->_('/levels/very-hard'));
?>
"
>
</span>
<span class="label label-default qSt-pl">