本文整理匯總了PHP中MessageManager::returnMessage方法的典型用法代碼示例。如果您正苦於以下問題:PHP MessageManager::returnMessage方法的具體用法?PHP MessageManager::returnMessage怎麽用?PHP MessageManager::returnMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類MessageManager
的用法示例。
在下文中一共展示了MessageManager::returnMessage方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: process
public function process($parameters)
{
//iba prihlaseny uzivatelia
$this->checkUser();
$userManager = new UserManager();
$messageManager = new MessageManager();
$loggedUser = $userManager->returnUser();
//ak je zadane URL pre vytvorenie novej spravy
if (!empty($parameters[0]) && $parameters[0] == 'vytvorit') {
$users = $userManager->returnUsers();
//vytvorenie zdroja pre automaticke doplnovanie uzivatelov v poli 'prijemca'
$autocompleteSource = '';
foreach ($users as $user) {
$autocompleteSource = $autocompleteSource . "'" . $user['name'] . "'" . ', ';
}
$autocompleteSource = rtrim($autocompleteSource, ", ");
$this->data['autocompleteSource'] = $autocompleteSource;
//ak bol zadany prijemca v URL
if (!empty($parameters[1])) {
$this->data['recipient_url'] = strip_tags($parameters[1]);
} else {
$this->data['recipient_url'] = '';
}
$this->head['title'] = 'Nová správa';
$this->view = 'messageForm';
}
//ak je zadane URL na odstranenie spravy
if (!empty($parameters[1]) && $parameters[1] == 'odstranit') {
$message = $messageManager->returnMessage($parameters[0]);
if ($message) {
$messageManager->deleteMessage($parameters[0], $loggedUser);
$this->createMessage('Správa bola odstránená', 'success');
$this->redirect('panel');
} else {
$this->redirect('chyba');
}
}
//ak je zadane URL na zobrazenie spravy
if (!empty($parameters[1]) && $parameters[1] == 'zobrazit') {
$message = $messageManager->returnMessage($parameters[0]);
//ak sprava existuje a otvara ju prijimatel, alebo odosielatel
if ($message && ($message['sender'] == $loggedUser['name'] || $message['recipient'] == $loggedUser['name'])) {
//pri prvom otvoreni, oznac spravu ako precitanu
if ($message['unread'] == 1 && $message['recipient'] == $loggedUser['name']) {
$messageManager->readMessage($message['message_id']);
}
$this->head['title'] = 'Správa - ' . $message['subject'];
$this->data['message'] = $message;
$this->view = 'message';
} else {
$this->redirect('chyba');
}
}
//ak bol odoslany formular pre odoslanie spravy
if ($_POST) {
$sender = $userManager->returnUser();
$recipient = strip_tags($_POST['recipient']);
$subject = htmlspecialchars($_POST['subject']);
$message = htmlspecialchars($_POST['message']);
try {
$recipient = $userManager->returnUserInfo($recipient);
if (!$recipient) {
throw new UserError('Užívateľ neexistuje');
}
if ($sender['name'] == $recipient['name']) {
throw new UserError('Nemôžete poslať správu sám sebe');
}
//odoslanie spravy do databazy
$messageManager->sendMessage($sender['name'], $recipient['name'], $subject, $message);
$this->createMessage('Vaša správa bola úspešne odoslaná', 'success');
$this->redirect('panel');
} catch (UserError $error) {
$this->createMessage($error->getMessage(), 'warning');
}
}
//zadane URL bez parametrov
if (empty($parameters)) {
$this->redirect('chyba');
}
}