/** * On user login, get user info and sitetree */ public function login($message = array()) { $socketSession = null; $data = $this->getMessage($message); $userdata = array(); $response = array('success' => 1); try { $userdata = $this->getUserData(); } catch (Exception $e) { // return failure $response['success'] = 0; $response['body'] = $e->getMessage(); } if (count($userdata) > 0 && SocketSession::get()->filter('MemberID', $userdata['ID'])->count() > 0) { $socketSession = SocketSession::get()->filter('MemberID', $userdata['ID'])->First(); } else { $socketSession = new SocketSession(); } // setup SocketSession with relevant data $socketSession->MemberID = $userdata['ID']; $socketSession->SocketID = $this->getMessageSocketID($message); $socketSession->PageID = 0; $socketSession->write(); SiteTreeOrigamiApi::emit_structure($data->socketId); ZMQInterface::emit('userdata', $userdata, $data->socketId); return $response; }
/** * Let users know when another user leaves their page in the Origami CMS */ public function emitUserLeaving($socketId, $pageId, $member) { // check if there are any users that need to be notified $users = SocketSession::get()->filter('PageID', $pageId)->exclude('MemberID', $member->ID); if ($users->count() > 0) { foreach ($users as $user) { ZMQInterface::emit('editform/leave', array('MemberID' => $member->ID, 'MemberFirstName' => $member->FirstName), $user->SocketID); } } }
/** * Let users know when another user joins their page in the Origami CMS */ public function emitPageUsers($message, $pageId) { $socketId = $this->getMessageSocketID($message); // update current socket session $session = SocketSession::get()->filter('SocketID', $socketId)->first(); // failsafe if (!$session || !$session->exists()) { $session = new SocketSession(); $session->MemberID = Member::currentUserID(); $session->SocketID = $socketId; } $session->PageID = $pageId; $session->write(); // check if there are any users that need to be notified $users = SocketSession::get()->filter('PageID', $pageId); if ($users->count() > 0) { // getting data from member to display nicely $mapUsers = $users->column('MemberID'); $mapUsers = Member::get()->filter('ID', $mapUsers); $members = array(); foreach ($mapUsers as $user) { $members[$user->ID] = array('id' => $user->ID, 'firstname' => $user->FirstName, 'initials' => substr($user->FirstName, 0, 1) . substr($user->Surname, 0, 1)); } foreach ($users as $user) { $copy = $members; // remove user that the socket id belongs to from the list if (isset($copy[$user->MemberID])) { unset($copy[$user->MemberID]); } if (count($copy) > 0) { ZMQInterface::emit('editform/view', array('Members' => $copy), $user->SocketID); } } } }
/** * Emit the sitetree structure out to the ZMQInterface so the OrigamiAPI updates * all the correct things. * * @param Int $socketId Optional socketId if the emit only needs to be sent to a specific session. * @param SiteTree $partialChild Optional partial child to get a site tree section from root. */ public static function emit_structure($socketId = null, SiteTree $partialChild = null) { $siteTree = new SiteTreeOrigamiApi(); $siteTree = $siteTree->getStructure(0, $partialChild); ZMQInterface::emit('sitetree/structure', $siteTree, $socketId); }