db = $db; $this->config = $config; $this->collection = $collection; $this->collectionEntryClassName = $this->collection->getEntryClassName(); $this->tableName = $this->config->getTableName(); $this->altPrimary = $this->config->getAltPrimary(); $this->mappedFields = $this->config->getMappedFields(); } /** * @param $sessionID * @return \DynCom\mysyde\common\interfaces\Entity */ public function findBySessionID( $sessionID ) { $visitor = $this->getNullObject(); if($this->cacheAll) { $this->_cacheAll(); } //Try from collection foreach($this->collection as $instance) { if(isset($instance->session_id) && ($instance->session_id == $sessionID)) { return $instance; } } //Else try from db $query = "SELECT * FROM `" . $this->tableName . "` WHERE `session_id` = :sessionID"; if ($this->db->setQuery($query) && $this->db->prepareQuery() && $this->db->bindParameters(array(array(':sessionID', $sessionID, \PDO::PARAM_STR))) && $this->db->executePreparedStatement() && ($resArr = $this->db->getResultArray()) && (count($resArr) == 1)) { $visitor->mapFromArray($resArr[0]); return $visitor; } return $visitor; } /** * @return Visitor */ public function getFromSession() { return $this->findBySessionID(session_id()); } /** * @param UserRepository $userRepository * @return mixed */ public function getUserFromSession(UserRepository $userRepository) { $currVisitor = $this->getFromSession(); return $userRepository->findByID($currVisitor->main_user_id); } }