本文整理匯總了PHP中models\User::load方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::load方法的具體用法?PHP User::load怎麽用?PHP User::load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models\User
的用法示例。
在下文中一共展示了User::load方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: index
public function index()
{
$f3 = \Base::instance();
$this->_requireLogin();
$user = $f3->get('user');
$user_obj = $f3->get('user_obj');
$user_org_links = $f3->get('user_org_links');
$db = $f3->get('db.instance');
$tickets = $db->exec('SELECT * FROM support_tickets WHERE memberId = ? ORDER BY id DESC', $user['id']);
foreach ($tickets as $id => $ticket) {
$result = $db->exec('SELECT COUNT(*) AS `count` FROM support_tickets_msg WHERE ticketId = ?', $ticket['id']);
$tickets[$id]['messages_count'] = $result[0]['count'];
// Assigned or not ?
if ($ticket['assignedUserId'] != 0) {
$assignedUser = new User();
$assignedUser->load($ticket['assignedUserId']);
$tickets[$id]['assignedUser'] = $assignedUser->cast();
}
}
$f3->set('tickets', $tickets);
$active_tickets = $db->exec("SELECT * FROM support_tickets WHERE memberId = ? AND status != 'closed'", $user['id']);
$f3->set('active_tickets', $active_tickets);
$closed_tickets = $db->exec("SELECT * FROM support_tickets WHERE memberId = ? AND status = 'closed'", $user['id']);
$f3->set('closed_tickets', $closed_tickets);
$f3->set('target', 'support/index.html');
$this->_render('base.html');
}
示例2: index
public function index()
{
$f3 = \Base::instance();
$this->_requireLogin();
$this->_requireRank('support');
$user = $f3->get('user');
$user_obj = $f3->get('user_obj');
$user_org_links = $f3->get('user_org_links');
$db = $f3->get('db.instance');
$tickets = $db->exec('SELECT * FROM support_tickets ORDER BY id DESC');
foreach ($tickets as $id => $ticket) {
$result = $db->exec('SELECT COUNT(*) AS `count` FROM support_tickets_msg WHERE ticketId = ?', $ticket['id']);
$tickets[$id]['messages_count'] = $result[0]['count'];
// Assigned or not ?
if ($ticket['assignedUserId'] != 0) {
$assignedUser = new User();
$assignedUser->load($ticket['assignedUserId']);
$tickets[$id]['assignedUser'] = $assignedUser->cast();
}
// From who ?
$ticketCreator = new User();
$ticketCreator->load($ticket['memberId']);
$tickets[$id]['member'] = $ticketCreator->cast();
}
$f3->set('tickets', $tickets);
$active_tickets = $db->exec("SELECT * FROM support_tickets WHERE status != 'closed'");
$f3->set('active_tickets', $active_tickets);
$closed_tickets = $db->exec("SELECT * FROM support_tickets WHERE status = 'closed'");
$f3->set('closed_tickets', $closed_tickets);
// Very high priority tickets
$prio_tickets = $db->exec("SELECT * FROM support_tickets WHERE status != 'closed' AND priority = 4 ORDER BY id DESC");
foreach ($prio_tickets as $id => $ticket) {
$result = $db->exec('SELECT COUNT(*) AS `count` FROM support_tickets_msg WHERE ticketId = ?', $ticket['id']);
$prio_tickets[$id]['messages_count'] = $result[0]['count'];
// Assigned or not ?
if ($ticket['assignedUserId'] != 0) {
$assignedUser = new User();
$assignedUser->load($ticket['assignedUserId']);
$prio_tickets[$id]['assignedUser'] = $assignedUser->cast();
}
// From who ?
$ticketCreator = new User();
$ticketCreator->load($ticket['memberId']);
$prio_tickets[$id]['member'] = $ticketCreator->cast();
}
$f3->set('priority_tickets', $prio_tickets);
// Some side-bar stats
$result = $db->exec('SELECT count(*) AS `count` FROM users');
$f3->set('users_count', $result[0]['count']);
$f3->set('tickets_count', count($active_tickets));
$f3->set('target', 'dashboard/admin/support/index.html');
$this->_render('base.html');
}
示例3: actionLogin
public function actionLogin()
{
if (!App::instance()->isGuest()) {
$this->redirect('/site/index/');
}
$user = new User();
if (isset($_POST['User']) && $user->load($_POST['User']) && $user->login()) {
$_SESSION['loggedUserId'] = App::instance()->user->id;
$this->redirect('/site/index/');
}
$this->render('login', ['user' => $user]);
}
示例4: detailspost
public function detailspost()
{
$f3 = \Base::instance();
$this->_requireLogin();
$this->_requireRank('support');
$user = $f3->get('user');
$user_obj = $f3->get('user_obj');
$user_org_links = $f3->get('user_org_links');
$db = $f3->get('db.instance');
// Target user
$tuser_id = $f3->get('PARAMS.id');
$tuser = new User();
$tuser->load($tuser_id);
if ($tuser->rank > $user['rank']) {
$f3->reroute($f3->get('PATH'));
}
// Update one by one
$name = $f3->get('POST.tname');
$username = $f3->get('POST.tusername');
$email = $f3->get('POST.temail');
$age = (int) $f3->get('POST.tage');
$rank = $f3->get('POST.trank');
$errors = [];
if (empty($name)) {
$errors[] = "Name is required";
}
if (!preg_match("/^[0-9a-z]{4,}\$/i", $username)) {
$errors[] = "Usernames must be at least 4 characters and can only contain letters and numbers.";
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = "A valid email address is required.";
}
// Prevent setting the users rank to a rank higher then the user's one
if ($rank > $user['rank']) {
$errors[] = 'You can not set the users rank to a rank higher then yours';
}
if (empty($errors)) {
$tuser->name = $name;
$tuser->username = $username;
$tuser->email = $email;
$tuser->age = $age;
$tuser->rank = $rank;
$tuser->save();
new Notification('Updated users profile successfully !', 'success', true);
$f3->reroute($f3->get('PATH'));
} else {
$f3->set('errors', $errors);
$f3->set('tuser', $tuser->cast());
$f3->set('target', 'dashboard/admin/users/details.html');
$this->_render('base.html');
}
}
示例5: invitepost
public function invitepost()
{
$f3 = \Base::instance();
$this->_requireLogin();
$db = $f3->get('db.instance');
$user = $f3->get('user');
$user_obj = $f3->get('user_obj');
$user_org = $f3->get('user_org');
$user_org_links = $f3->get('user_org_links');
$orgId = (int) $f3->get('PARAMS.id');
// Check if user is part of the organisation
$result = $db->exec('SELECT * FROM organisation_members WHERE orgId = :orgId AND memberId = :memberId', array('orgId' => $orgId, 'memberId' => $user['id']));
if (empty($result)) {
// Not member
new Notification('You are not member of this organisation', 'danger', true);
$f3->reroute('/organisations');
return;
} else {
$orgMap = new Organisation();
$orgMap->load($orgId);
$f3->set('user_org_selected', $orgMap->cast());
if ($f3->exists('POST.name') and !empty($f3->get('POST.name'))) {
$invitedUser = new User();
$invitedUser->load(array('(email = :email OR username = :email) AND deleted_date IS NULL', 'email' => $f3->get('POST.name')));
if (!$invitedUser->loaded()) {
// No user with this email or username
$f3->set('error', 'No user with this email or password');
} else {
// Generate new invitation entry
$security = new Security();
$accept_key = sha1($security->rand_bytes(32));
$db->exec('INSERT INTO organisations_invites(targetId, fromId, orgId, create_time, accept_key) VALUES(:targetId, :fromId, :orgId, :createTime, :acceptKey)', array('targetId' => $invitedUser->id, 'fromId' => $user['id'], 'orgId' => $orgId, 'createTime' => date("Y-m-d H:i:s"), 'acceptKey' => $accept_key));
new Notification("Invited <b>{$invitedUser->name}</b> to join this organisation", 'success', true);
$f3->reroute($f3->get('PATH'));
}
}
$f3->set('target', 'dashboard/organisations/invite.html');
}
$this->_render('base.html');
}
示例6: view
public function view()
{
$f3 = \Base::instance();
$this->_requireLogin();
$this->_requireRank('support');
$user = $f3->get('user');
$user_obj = $f3->get('user_obj');
$user_org_links = $f3->get('user_org_links');
$db = $f3->get('db.instance');
$ticketId = $f3->get('PARAMS.id');
$ticket = new Ticket();
$ticket->load($ticketId);
if ($ticket->loaded()) {
if ($f3->exists('GET.action') and $f3->get('GET.action') == 'close') {
$ticket->status = 'closed';
$ticket->save();
$f3->reroute($f3->get('PATH'));
}
$f3->set('ticket', $ticket->cast());
// Load ticket messages
$result = $db->exec('SELECT * FROM support_tickets_msg WHERE ticketId = ? ORDER BY id DESC', $ticket->id);
foreach ($result as $id => $resp) {
if ($resp['senderId'] == $user['id']) {
// The sender is the actual user, no need to load
$result[$id]['sender'] = $user;
} else {
// Load the message senders information
$sender = new User();
$sender->load($resp['senderId']);
$result[$id]['sender'] = $sender->cast();
}
}
$f3->set('ticket_msg', $result);
$f3->set('target', 'dashboard/admin/support/view.html');
} else {
$f3->set('target', '404.html');
}
$this->_render('base.html');
}
示例7: resumepost
public function resumepost()
{
$f3 = \Base::instance();
$this->_requireLogin();
$user = $f3->get('user');
$user_obj = $f3->get('user_obj');
$user_org = $f3->get('user_org');
$user_org_links = $f3->get('user_org_links');
$errors = [];
if ($f3->exists('POST.username')) {
$username = $f3->get('POST.username');
$username = $f3->scrub($username);
if (preg_match('/^[a-z0-9]{5,}$/', $username)) {
// Filter any already existing username
if ($username != $user['username']) {
$user = new User();
$user->load(array('username = ?', $username));
if ($user->loaded()) {
$errors[] = 'This username is taken.';
} else {
$user_obj->username = $username;
}
}
} else {
$errors[] = 'Username must be at least 5 characters long, with only numbers and lowercase letters in it.';
}
}
if ($f3->exists('POST.fullName')) {
$fullName = $f3->get('POST.fullName');
$fullName = $f3->scrub($fullName);
if (strlen($fullName) > 4) {
$user_obj->name = htmlspecialchars($fullName);
} else {
$errors[] = 'Full name must be at least 5 characters long';
}
}
if ($f3->exists('POST.email')) {
$email = $f3->get('POST.email');
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
// Filter any already existing email
if ($email != $user['email']) {
$user = new User();
$user->load(array('email = ?', $email));
if ($user->loaded()) {
$errors[] = 'This email is taken.';
} else {
$user_obj->email = $email;
}
}
} else {
$errors[] = 'Incorrect email';
}
}
if ($f3->exists('POST.age')) {
$age = (int) $f3->get('POST.age');
if ($age > 12) {
$user_obj->age = $age;
} else {
$errors[] = 'You need to be at least 13 years old to use this service.';
}
}
// Saving if no errors
if (empty($errors)) {
$user_obj->save();
new Notification('Profile saved', 'success', true);
$f3->reroute($f3->get('PATH'));
return;
} else {
$f3->set('errors', $errors);
}
// Display a notification to masquerading administrators
if ($f3->exists('SESSION.mask')) {
new Notification('You are currently masquerading as a client, <a href="/dashboard/admin/masquerade/reveal">back to your admin account</a>', 'danger', true);
}
$f3->set('target', 'account/resume.html');
$this->_render('base.html');
}