Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function getCurrentDraft($ticketId, $userId, $text = false)
- {
- $collection = Mage::getModel('helpdesk/draft')->getCollection()
- ->addFieldToFilter('ticket_id', $ticketId);
- if ($collection->count()) {
- $draft = $collection->getFirstItem();
- } else {
- $draft = Mage::getModel('helpdesk/draft');
- $draft->setTicketId($ticketId);
- }
- $usersOnline = $draft->getUsersOnline();
- $timeNow = Mage::getSingleton('core/date')->gmtTimestamp();
- $usersOnline[$userId] = $timeNow;
- foreach ($usersOnline as $uId => $timestamp) {
- if ($uId == $userId) {
- continue;
- }
- if ($timestamp + 20 < $timeNow) { //other user went offline from this page
- unset($usersOnline[$uId]);
- continue;
- }
- }
- $draft->setUsersOnline($usersOnline);
- if ($text !== false) {
- $draft->setBody($text);
- $draft->setUpdatedBy($userId);
- $draft->setUpdatedAt(Mage::getSingleton('core/date')->gmtDate());
- }
- $draft->save();
- return $draft;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement