本文整理汇总了PHP中Messages类的典型用法代码示例。如果您正苦于以下问题:PHP Messages类的具体用法?PHP Messages怎么用?PHP Messages使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Messages类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
public function create($content, Users $user)
{
$message = new Messages();
$valid = $message->setContent($content);
if ($valid === true) {
$valid = $message->setUser($user);
if ($valid === true) {
$content = mysqli_real_escape_string($this->database, $message->getContent());
$id_user = $message->getUser();
$query = "INSERT INTO messages (content, id_user) \n\t\t\t\t\tVALUES ('" . $content . "', '" . $id_user . "')";
$result = mysqli_query($this->database, $query);
if ($result) {
$id = mysqli_insert_id($this->database);
if ($id) {
return $this->findById($id);
} else {
return "Erreur serveur.";
}
} else {
return mysqli_error();
}
} else {
return $valid;
}
} else {
return $valid;
}
}
示例2: 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);
}
}
示例3: actionIndex
/** Responsible for presenting a collection back to the user. */
public function actionIndex($p)
{
$this->bag->q = $query = strtolower($this->request->getQuery('q'));
$messages = new Messages();
$this->bag->nodes = $messages->findNodes()->orderBy('created_at DESC')->where(array('text' => "*{$query}*"));
$this->renderAction('index');
}
示例4: actionSavemessage
public function actionSavemessage()
{
$subject = Yii::app()->Ini->v('subject');
$message = Yii::app()->Ini->v('message');
$to_usertype = Yii::app()->Ini->v('to_usertype');
$from_id = Yii::app()->user->getId();
$from_user_type = Yii::app()->user->role;
$to_id = Yii::app()->Ini->v('receiver_id');
$sent_date = date("Y-m-d H:i:s");
$messages = new Messages();
$messages->subject = $subject;
$messages->message = $message;
$messages->from_id = $from_id;
$messages->to_id = $to_id;
$messages->to_user_type = 'to_usertype';
$messages->from_user_type = $from_user_type;
$messages->date_sent = $sent_date;
$this->sendEmailNotification($subject, $message, $to_id, Yii::app()->name);
if ($messages->save()) {
$status = array('success' => true);
} else {
$status = array('success' => false, 'error_message' => print_r($messages->getErrors()));
}
$this->renderJSON($status);
}
示例5: actionCreate
/** Receives the form submission from the new action and creates the new object. */
public function actionCreate()
{
// create a new message
$messages = new Messages();
$name = $messages->generateNewName($this->request->getPost());
if (empty($name)) {
$this->flashFail = 'The message cannot be blank';
$this->redirectTo('topics/new');
}
$stamp = date("Y-m-d H:i:s", mktime());
$save['name'] = $this->userRow['name'];
// create new topic
$save['name'] = $this->request->getPost('name');
$save['created_at'] = $save['updated_at'] = $stamp;
$save['created_by'] = $this->userRow['name'];
$save['is_archived'] = 0;
$topicId = $this->topics->save($save);
// create new message... read by us
$newId = $messages->save(array('topics_id' => $topicId, 'created_at' => $stamp, 'name' => $name, 'user' => $this->userRow['name'], 'read_by' => "!{$this->userRow['id']}!"));
// create new mailer
//$mailer = new Mailer();
// save the text
$nodes = new Nodes();
$nodes->saveMessage(0, $this->request->getPost(0), $topicId, $newId, $this->userRow['name'], $mailer);
// send email to all recipients
//$users = new Users();
//foreach ($users->select('email')->findAll() as $user) $recipients[] = $user['email'];
//$mailer->sendMessage($recipients, $newId, $topicId, $this->topics);
// redirect to the new message
$this->redirectTo("messages/show/{$topicId}/{$newId}");
}
示例6: viewInbox
/**
* View your inbox
* @return void
*/
private function viewInbox()
{
require_once FRAMEWORK_PATH . 'models/messages.php';
$messages = new Messages($this->registry);
$cache = $messages->getInbox($this->registry->getObject('authenticate')->getUser()->getUserID());
$this->registry->getObject('template')->buildFromTemplates('header.tpl.php', 'messages/inbox.tpl.php', 'footer.tpl.php');
$this->registry->getObject('template')->getPage()->addTag('messages', array('SQL', $cache));
}
示例7: 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);
}
}
示例8: save
public function save()
{
$message = new Messages();
$message->sender_id = Yii::app()->user->id;
$message->receiver_id = $this->receiver_id;
$message->text = $this->text;
$message->is_new = TRUE;
$message->save();
}
示例9: 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);
}
}
示例10: 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;
}
示例11: __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);
}
示例12: 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);
}
}
示例13: __construct
public function __construct()
{
parent::__construct('Fireside');
// latest messages
$messages = new Messages();
$latestMessages = $messages->find()->orderBy('id DESC')->limit(20)->where(array('id' => '>0'));
foreach ($latestMessages as $message) {
$item = array('http://' . $_SERVER['HTTP_HOST'] . WWW_DIR . "/messages/show/{$message['topics_id']}/{$message['id']}" => array('title' => $message['name'], 'content' => 'Message by ' . $message['user'] . ' on ' . $message['created_at']));
$this->atomise($item);
}
$this->generate();
}
示例14: render
function render()
{
$message = new Messages($this->db);
$message->key = 'Second message';
$message->message = 'This is the second message inserted from code';
$message->save();
$messages = new Messages($this->db);
$msg = $messages->all()[0];
$this->f3->set('msg', $msg);
$template = new Template();
echo $template->render('template.htm');
}
示例15: inbox
/**
* List latest messages
*
* @return Response
*/
public function inbox()
{
if (!empty($this->app['auth']['id'])) {
$msg = new Messages();
$offset = $this->app->request->getQuery("offset");
$limit = $this->app->request->getQuery("limit");
$this->app->response->setJsonContent($msg->getInbox($this->app['auth']['id'], $offset, $limit));
return $this->app->response;
} else {
$this->app->response->setStatusCode(401, "Unauthorized")->setJsonContent(array('status' => 'ERROR', 'data' => 'Access is not authorized'));
}
return $this->app->response;
}