Advertisement
johncarlson21

getcurrentdraft

Aug 12th, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. public function getCurrentDraft($ticketId, $userId, $text = false)
  2.     {
  3.         $collection = Mage::getModel('helpdesk/draft')->getCollection()
  4.                 ->addFieldToFilter('ticket_id', $ticketId);
  5.         if ($collection->count()) {
  6.             $draft = $collection->getFirstItem();
  7.         } else {
  8.             $draft = Mage::getModel('helpdesk/draft');
  9.             $draft->setTicketId($ticketId);
  10.         }
  11.         $usersOnline = $draft->getUsersOnline();
  12.         $timeNow = Mage::getSingleton('core/date')->gmtTimestamp();
  13.         $usersOnline[$userId] = $timeNow;
  14.         foreach ($usersOnline as $uId => $timestamp) {
  15.             if ($uId == $userId) {
  16.                 continue;
  17.             }
  18.             if ($timestamp + 20 < $timeNow) { //other user went offline from this page
  19.                 unset($usersOnline[$uId]);
  20.                 continue;
  21.             }
  22.         }
  23.         $draft->setUsersOnline($usersOnline);
  24.         if ($text !== false) {
  25.             $draft->setBody($text);
  26.             $draft->setUpdatedBy($userId);
  27.             $draft->setUpdatedAt(Mage::getSingleton('core/date')->gmtDate());
  28.         }
  29.         $draft->save();
  30.  
  31.         return $draft;
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement