本文整理汇总了PHP中Message::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Message::save方法的具体用法?PHP Message::save怎么用?PHP Message::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Message
的用法示例。
在下文中一共展示了Message::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a message if form has been submitted or renders the creation/update form
*/
public function actionCreate()
{
if (isset($_POST['Message'])) {
$resp = array('color' => '#FF6600', 'background_color' => '#FFFFCC', 'position' => 'top', 'removebutton' => 0);
$model = new Message();
$model->setAttributes($_POST['Message']);
if ($model->save()) {
$resp['message'] = Yii::t('translate', 'Message successfully saved');
$resp['id'] = $model->id;
} else {
$errors = $this->errors($model);
$resp['message'] = Yii::t('translate', '<p>Unable to save the message. Something went wrong!<p/>' . implode('<br/>', $errors));
}
echo $this->je($resp);
Yii::app()->end();
}
$id = (int) Yii::app()->request->getParam('id');
$lang = Yii::app()->request->getParam('lang');
if ($id && $lang) {
$model = MessageSource::model()->findByPk($id);
if ($model) {
$message = $model->loadMessage();
$message->id = $model->id;
$message->language = $lang;
$this->renderPartial('form', array('model' => $message));
} else {
throw new CHttpException(400);
}
} else {
throw new CHttpException(404, 'The requested page does not exist.');
}
}
示例2: create
public function create()
{
$uid = Auth::user()->id;
$message = new Message();
$message->title = Input::get('title');
$message->body = Input::get('body');
$message->mass_message = 0;
$message->author_id = $uid;
if (Input::get('recipient') != null) {
$recipient = DB::table('users')->where('email', '=', Input::get('recipient'))->first();
$message->recipient_id = $recipient->id;
} else {
$message->recipient_id = null;
}
$message->save();
if (Input::get('recipient') != null) {
$email = Input::get('recipient');
$username = $recipient->email;
$body = Input::get('body');
$data = ['username' => $username, 'body' => $body];
Mail::send('emails.adminmessage', $data, function ($message) {
$message->to(Input::get('recipient'), 'test')->subject(Input::get('title'));
});
}
return Redirect::to('/user/messages');
}
示例3: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Lecture();
if (isset($_POST['Lecture'])) {
$model->attributes = $_POST['Lecture'];
if (empty($model->owner_by)) {
$model->owner_by = Yii::app()->user->getId();
}
if ($model->save()) {
if (!Yii::app()->user->checkAccess('adminLecture')) {
$model->is_active = 0;
$adminUserIds = Yii::app()->db->createCommand()->select('userid')->from('authassignment')->where('itemname=:itemname', array(':itemname' => 'admin'))->queryColumn();
foreach ($adminUserIds as $id) {
$message = new Message();
$message->id_from = Yii::app()->user->getId();
$message->id_user = $id;
$message->subject = 'A new lecture is created';
$message->message = "User " . CHtml::link($this->viewer->username, $this->createUrl('account/view', array('id' => $this->viewer->getPrimaryKey()))) . " have just created the lecture " . CHtml::link($model->title, $this->createUrl('lecture/view', array('id' => $model->getPrimaryKey())));
$message->save();
}
}
$this->redirect(array('view', 'id' => $model->id));
}
// $model->fileIntro = $file = CUploadedFile::getInstance($model, 'fileIntro');
// if ($model->validate(array('fileIntro'))) {
// if ($file) {
// $fileName = Yii::app()->params['video'] . '/' . $file->getName();
// if (file_exists($fileName)) {
// $fileName = Yii::app()->params['video'] . '/'
// . time() . '_' . $file->getName();
// }
// if ($file->saveAs(strtolower($fileName), true)) {
// /* $videoHelper = new CVideo();
// $videoThumbnailName = $videoHelper->create_thumbnail($fileName,
// Yii::app()->params['videoWidth'],
// Yii::app()->params['videoHeight'],
// Yii::app()->params['videoThumbnail']
// );
// $convertVideoFileName = $videoHelper->convertVideo($fileName);
//
// $model->path_video_intro = $convertVideoFileName;
// $model->path_video_thumbnail = $videoThumbnailName; */
// $model->path_video_intro = $fileName;
// $model->path_video_thumbnail = Yii::app()->params['defaultLectureThumbnail'];
// }
// }
// if ($model->save()) {
// $this->redirect(array('view', 'id' => $model->id));
// }
// }
}
$params = $this->getActionParams();
if ($params && array_key_exists('idCategory', $params)) {
$model->id_category = (int) $params['idCategory'];
}
if (Yii::app()->user->checkAccess('adminLecture')) {
$model->is_active = 1;
}
$this->render('create', array('model' => $model));
}
示例4: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
//
$interactor = new CurlInteractor();
$interactor->setResponseFactory(new SlackResponseFactory());
$commander = new Commander($_ENV['SLACK_KEY'], $interactor);
$channels = Channel::where('is_member', true)->get();
foreach ($channels as $channel) {
$latest = $channel->latest ?: 0;
do {
$response = $commander->execute('channels.history', ['channel' => $channel->sid, 'oldest' => $latest, 'count' => 1000]);
$responseBody = $response->getBody();
foreach ($responseBody['messages'] as $msg) {
$latest = $msg['ts'] > $latest ? $msg['ts'] : $latest;
$message = new Message();
foreach ($msg as $k => $v) {
$message->{$k} = is_string($v) ? $v : (object) $v;
}
$message->channel = $channel->sid;
$message->save();
}
} while ($responseBody['has_more']);
$channel->latest = $latest;
$channel->save();
}
}
示例5: actionCompose
public function actionCompose($id = null)
{
$message = new Message();
if (Yii::app()->request->getPost('Message')) {
$receiverName = Yii::app()->request->getPost('receiver');
$message->attributes = Yii::app()->request->getPost('Message');
$message->sender_id = Yii::app()->user->getId();
if ($message->save()) {
Yii::app()->user->setFlash('messageModule', MessageModule::t('Message has been sent'));
$this->redirect($this->createUrl('inbox/'));
} else {
if ($message->hasErrors('receiver_id')) {
$message->receiver_id = null;
$receiverName = '';
}
}
} else {
if ($id) {
$receiver = call_user_func(array(call_user_func(array(Yii::app()->getModule('message')->userModel, 'model')), 'findByPk'), $id);
if ($receiver) {
$receiverName = call_user_func(array($receiver, Yii::app()->getModule('message')->getNameMethod));
$message->receiver_id = $receiver->id;
}
}
}
$this->render(Yii::app()->getModule('message')->viewPath . '/compose', array('model' => $message, 'receiverName' => isset($receiverName) ? $receiverName : null));
}
示例6: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
if (isset($_POST['Message'])) {
$toUsers = explode(',', $_POST['toUsers']);
$arrUserIds = array();
foreach ($toUsers as $toUser) {
$username = trim(strtok(trim($toUser), '-'));
$user = Account::model()->findByAttributes(array('username' => $username));
if ($user && $user->getPrimaryKey() != $this->viewer->getPrimaryKey()) {
$arrUserIds = array_merge($arrUserIds, array($user->getPrimaryKey()));
}
}
if (!empty($arrUserIds)) {
foreach ($arrUserIds as $userId) {
$model = new Message();
$model->subject = $_POST['Message']['subject'];
$model->message = $_POST['Message']['message'];
$model->id_from = $this->viewer->getPrimaryKey();
$model->id_user = $userId;
$model->save();
}
}
Yii::app()->user->setFlash('message', Yii::t('flexiblearn', 'Your message is sent successfully !!!'));
$this->redirect(array('manage'));
}
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/jquery.autocomplete-min.js');
Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl . '/stylesheet/autocomplete.css');
$this->render('create', array('model' => new Message()));
}
示例7: sendMessage
/**
* Send a Message populated with at least the following required fields:
* recipientId
* subject
* body
* The following fields are optional:
* senderId may be null to indicate that it is a message from the system
* petListingId should be populated if the message pertains to a
* particular PetListing.
* The other data fields of the message will be initialized automatically.
*
* @param Message $message the Message to send
*/
public function sendMessage($message)
{
$message->dateSent = Message::$objects->formatDateTime(new DateTime());
$message->read = false;
$message->save();
// FIXME: If the user is subscribed to email notifications,
// call emailMessage($message)
}
示例8: addMessage
public function addMessage($message, $type = Message::TYPE_INFO, $senderId = null)
{
$model = new Message();
$model->text = $message;
$model->type = $type;
$model->date = time();
$model->sender = $senderId;
$model->save(false);
}
示例9: actionSend
public function actionSend($username = null, $reply = null, $selfReply = null)
{
$user = new User();
$model = new Message();
$message = null;
$users = array();
$models = User::model()->findAll(array('condition' => 'FK_usertype = 1'));
foreach ($models as $aUser) {
$users[] = array('label' => CHtml::image($aUser->image_url, '', array('width' => '20px')) . ' ' . $aUser->first_name . ' ' . $aUser->last_name, 'value' => "\"" . $aUser->first_name . " " . $aUser->last_name . "\" <" . $aUser->username . ">");
}
if (isset($_POST['Message'])) {
$model->attributes = $_POST['Message'];
$model->FK_sender = Yii::app()->user->name;
date_default_timezone_set('America/New_York');
$model->date = date('Y-m-d H:i:s');
$model->userImage = $model->fKSender->image_url;
$model->subject = $_POST['Message']['subject'];
$receivers = $this->getReceivers($_POST["receiver"]);
$receiverCount = count($receivers);
for ($i = 0; $i < $receiverCount; $i++) {
$model->FK_receiver = $receivers[$i];
if (User::model()->find("username=:username", array(':username' => $model->FK_receiver)) != null) {
$model->save();
}
$model = new Message();
$model->attributes = $_POST['Message'];
$model->FK_sender = Yii::app()->user->name;
$model->date = date('Y-m-d H:i:s');
$model->userImage = $model->fKSender->image_url;
$model->subject = $_POST['Message']['subject'];
}
User::sendUserNotificationMessageAlart(Yii::app()->user->id, $model->FK_receiver, 'http://' . Yii::app()->request->getServerName() . '/JobFair/index.php/message', 3);
$link = CHtml::link('here', 'http://' . Yii::app()->request->getServerName() . '/JobFair/index.php/message');
$recive = User::model()->find("username=:username", array(':username' => $model->FK_receiver));
if ($recive != NULL) {
$message = "You just got a message from {$model->FK_sender}<br/> '{$model->message}'<br/> Access the message {$link}";
//$html = User::replaceMessage($recive->username, $message);
User::sendEmail($recive->email, "Virtual Job Fair Message", "Message from Virtual Job Fair", $message);
//User::sendEmailMessageNotificationAlart($recive->email, $recive->username, $model->FK_sender, $message);
}
$this->redirect("/JobFair/index.php/message");
return;
}
if ($reply != null) {
$message = Message::model()->findByPK($reply);
if (Yii::app()->user->name == $message->FK_sender) {
$username = $message->FK_receiver;
} else {
$username = $message->FK_sender;
}
$model->subject = $message->subject;
$model->message = "\n\n\nOn " . $message->date . ", " . $message->FK_sender . " wrote:\n" . $message->message;
}
$this->render('send', array('user' => $user, 'users' => $users, 'model' => $model, 'username' => $username));
}
示例10: createAdmin
public function createAdmin(Request $request)
{
$this->validate($request, ['recipient' => 'required', 'content' => 'required']);
$message = new Message();
$message->sender_id = 1;
$message->recipient_id = $request->input('recipient');
$message->content = $request->input('content');
$message->read = 0;
$message->save();
return $this->response();
}
示例11: add_message
function add_message()
{
global $CONF;
$user = $_SESSION['user'];
if ($user->getBanned()>0){
return array('ok'=>false, 'error'=>'banned '.$user->getBanned());
}
if (isset($_SESSION['message_last_flood_time'])){
if ((time() - $_SESSION['message_last_flood_time']) < $CONF['message_time_to_wait_flood']){
$time_to_wait = $CONF['message_time_to_wait_flood'] - (time() - $_SESSION['message_last_flood_time']);
return array('ok'=>false, 'error'=>'flood '.$time_to_wait);
}
}
$_SESSION['message_last_flood_time']=time();
$user = $_SESSION['user'];
$userto=new RegUser();
if (isset($_POST['user_to_id'])) $userto->setId($_POST['user_to_id']);
elseif (isset($_POST['user_to_email'])) $userto->setEmail($_POST['user_to_email']);
elseif (isset($_POST['user_to_nickname'])) $userto->setNickname($_POST['user_to_nickname']);
else return array('ok'=>false, 'error'=>'undefined user to send');
$message = new Message();
$message->setUserFrom($user);
$message->setUserTo($userto);
$subject = strip_tags($_POST['subject']);
if (strlen(str_replace(' ', '', $subject)) < $CONF['min_msg_chars'])
return array('ok'=>false, 'error'=>'too short subject');
$message->setSubject($subject);
$msg = unescape_ampersand($_POST['msg']);
if (strlen(str_replace(' ', '', strip_tags($msg))) < $CONF['min_msg_chars'])
return array('ok'=>false, 'error'=>'too short message');
$msg = strip_tags($msg, $CONF['permitted_tags_msg']);
//$msg = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a target=\"_BLANK\" href=\"\\0\">\\0</a>", $msg); //detectando URLs
$msg = text_linkify($msg);
$msg = str_replace(' ',' ',$msg);
$message->setMsg($msg);
$result = $message->save();
if ($result=='ok'){
return array('ok'=>true, 'error'=>'');
}
else
return array('ok'=>false, 'error'=>'problems with this message: '.$result);
}
示例12: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
//
$input = Input::all();
$message = new Message();
$message->from = $input['fromuser'];
$message->to = $input['touser'];
$message->message = $input['message'];
$message->save();
return Redirect::action('MessageController@show', array('id' => Input::get('touser')));
}
示例13: actionNewmessage
public function actionNewmessage()
{
$message = new Message();
if (isset($_POST['Message'])) {
$message->attributes = $_POST['Message'];
if ($message->save()) {
$this->redirect(array('messages', 'id' => $message->id));
}
}
$this->render('Newmessage', array('message' => $message));
}
示例14: add
public function add()
{
$user = $this->getUser();
if (RequestMethods::post("share")) {
$message = new Message(array("body" => RequestMethods::post("body"), "message" => RequestMethods::post("message"), "user" => $user['id']));
if ($message->validate()) {
$message->save();
$this->redirect('/');
}
}
}
示例15: insertDummyData
public function insertDummyData()
{
for ($i = 0; $i < 100; $i++) {
$new_mess = new Message();
$new_mess->from = "huy" . $i;
$new_mess->to = "dummy" . $i;
$new_mess->message = "test" . $i;
$new_mess->sent_date = date('m/d/Y h:i:s');
$new_mess->save(FALSE);
}
}