本文整理匯總了PHP中models\User::cast方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::cast方法的具體用法?PHP User::cast怎麽用?PHP User::cast使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models\User
的用法示例。
在下文中一共展示了User::cast方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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');
}
示例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');
}
}