/**
  * 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;
 }
 /**
  * Sitetree getter, caches the whole sitetree per logged in user groups.
  * If a $partialChild is defined then the cache is bypassed and a partial sitetree is returned.
  *
  * @param  Int 			$id 				Optional id used to define the parent to kick off from.
  * @param  SiteTree  	$partialChild   	Optional partial child to get a site tree section from root.
  */
 public function getStructure($id = 0, $partialChild = null)
 {
     if (!Member::currentUserID()) {
         throw new Exception('SiteTreeOrigamiApi::getStructure Not logged in');
     }
     if ($partialChild) {
         $stack = array_reverse($partialChild->parentStack());
         $result = $this->_structure($id, $stack);
     } else {
         // Check the cache.
         SS_Cache::set_cache_lifetime('SiteTree_Groups', 60 * 60);
         //one hour
         $cache = SS_Cache::factory('SiteTree_Groups', 'Output', array('automatic_serialization' => true));
         // If there isn't a cached response call the API.
         if (!($result = $cache->load(SiteTreeOrigamiApi::get_cache_key()))) {
             $result = $this->_structure($id);
             $cache->save($result, SiteTreeOrigamiApi::get_cache_key());
         }
     }
     return $result;
 }
 /**
  * Wrapper for updating sitetree functionality,
  * it's called on almost every action of an edit page form
  */
 protected function updateSiteTree($record, $socketId = null)
 {
     // if it's a sitetree page then reset the sitetree cache
     // and re emit the sitetree refresh
     SiteTreeOrigamiApi::reset_cache();
     SiteTreeOrigamiApi::emit_structure($socketId, $record);
 }