106 lines
3.9 KiB
PHP
Raw Normal View History

2017-01-20 07:19:39 -05:00
<?php
namespace BusinessLogic\Security;
class UserContext {
2017-03-11 23:43:46 -05:00
/* @var $id int */
2017-01-20 07:19:39 -05:00
public $id;
2017-03-11 23:43:46 -05:00
/* @var $username string */
2017-01-20 07:19:39 -05:00
public $username;
2017-03-11 23:43:46 -05:00
/* @var $admin bool */
2017-01-20 07:19:39 -05:00
public $admin;
2017-03-11 23:43:46 -05:00
/* @var $name string */
2017-01-20 07:19:39 -05:00
public $name;
2017-03-11 23:43:46 -05:00
/* @var $email string */
2017-01-20 07:19:39 -05:00
public $email;
2017-03-11 23:43:46 -05:00
/* @var $signature string */
2017-01-20 07:19:39 -05:00
public $signature;
2017-03-11 23:43:46 -05:00
/* @var $language string|null */
2017-01-20 07:19:39 -05:00
public $language;
2017-03-11 23:43:46 -05:00
/* @var $categories int[] */
2017-01-20 07:19:39 -05:00
public $categories;
2017-03-11 23:43:46 -05:00
/* @var $permissions string[] */
2017-01-20 07:19:39 -05:00
public $permissions;
2017-03-11 23:43:46 -05:00
/* @var UserContextPreferences */
2017-01-20 07:19:39 -05:00
public $preferences;
2017-03-11 23:43:46 -05:00
/* @var UserContextNotifications */
2017-01-20 07:19:39 -05:00
public $notificationSettings;
2017-03-11 23:43:46 -05:00
/* @var $autoAssign bool */
2017-01-20 07:19:39 -05:00
public $autoAssign;
2017-03-11 23:43:46 -05:00
/* @var $ratingNegative int */
2017-01-20 07:19:39 -05:00
public $ratingNegative;
2017-03-11 23:43:46 -05:00
/* @var $ratingPositive int */
2017-01-20 07:19:39 -05:00
public $ratingPositive;
2017-03-11 23:43:46 -05:00
/* @var $rating float */
2017-01-20 07:19:39 -05:00
public $rating;
2017-03-11 23:43:46 -05:00
/* @var $totalNumberOfReplies int */
2017-01-20 07:19:39 -05:00
public $totalNumberOfReplies;
2017-03-11 23:43:46 -05:00
/* @var $active bool */
2017-01-20 07:19:39 -05:00
public $active;
2017-03-10 22:06:32 -05:00
/**
* Builds a user context based on the current session. **The session must be active!**
* @param $dataRow array the $_SESSION superglobal or the hesk_users result set
* @return UserContext the built user context
*/
static function fromDataRow($dataRow) {
$userContext = new UserContext();
$userContext->id = intval($dataRow['id']);
2017-03-10 22:06:32 -05:00
$userContext->username = $dataRow['user'];
$userContext->admin = boolval($dataRow['isadmin']);
2017-03-10 22:06:32 -05:00
$userContext->name = $dataRow['name'];
$userContext->email = $dataRow['email'];
$userContext->signature = $dataRow['signature'];
$userContext->language = $dataRow['language'];
$userContext->categories = explode(',', $dataRow['categories']);
$userContext->permissions = explode(',', $dataRow['heskprivileges']);
$userContext->autoAssign = boolval($dataRow['autoassign']);
$userContext->ratingNegative = intval($dataRow['ratingneg']);
$userContext->ratingPositive = intval($dataRow['ratingpos']);
$userContext->rating = floatval($dataRow['rating']);
$userContext->totalNumberOfReplies = intval($dataRow['replies']);
$userContext->active = boolval($dataRow['active']);
2017-03-10 22:06:32 -05:00
$preferences = new UserContextPreferences();
$preferences->afterReply = intval($dataRow['afterreply']);
$preferences->autoStartTimeWorked = boolval($dataRow['autostart']);
$preferences->autoreload = intval($dataRow['autoreload']);
$preferences->defaultNotifyCustomerNewTicket = boolval($dataRow['notify_customer_new']);
$preferences->defaultNotifyCustomerReply = boolval($dataRow['notify_customer_reply']);
$preferences->showSuggestedKnowledgebaseArticles = boolval($dataRow['show_suggested']);
$preferences->defaultCalendarView = intval($dataRow['default_calendar_view']);
2017-03-10 22:06:32 -05:00
$preferences->defaultTicketView = $dataRow['default_list'];
$userContext->preferences = $preferences;
$notifications = new UserContextNotifications();
$notifications->newUnassigned = boolval($dataRow['notify_new_unassigned']);
$notifications->newAssignedToMe = boolval($dataRow['notify_new_my']);
$notifications->replyUnassigned = boolval($dataRow['notify_reply_unassigned']);
$notifications->replyToMe = boolval($dataRow['notify_reply_my']);
$notifications->ticketAssignedToMe = boolval($dataRow['notify_assigned']);
$notifications->privateMessage = boolval($dataRow['notify_pm']);
$notifications->noteOnTicketAssignedToMe = boolval($dataRow['notify_note']);
$notifications->noteOnTicketNotAssignedToMe = boolval($dataRow['notify_note_unassigned']);
$notifications->overdueTicketUnassigned = boolval($dataRow['notify_overdue_unassigned']);
2017-03-10 22:06:32 -05:00
$userContext->notificationSettings = $notifications;
return $userContext;
}
2017-01-20 07:19:39 -05:00
}