| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace ZfcUser\Mapper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use ZfcBase\Mapper\AbstractDbMapper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use ZfcUser\Entity\UserInterface as UserEntityInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Zend\Stdlib\Hydrator\HydratorInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | class User extends AbstractDbMapper implements UserInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     protected $tableName  = 'user'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     public function findByEmail($email) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |         $select = $this->getSelect() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |                        ->where(array('email' => $email)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         $entity = $this->select($select)->current(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         $this->getEventManager()->trigger('find', $this, array('entity' => $entity)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         return $entity; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |     public function findByUsername($username) | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |         $select = $this->getSelect() | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |                        ->where(array('username' => $username)); | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |         $entity = $this->select($select)->current(); | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |         $this->getEventManager()->trigger('find', $this, array('entity' => $entity)); | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         return $entity; | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     public function findById($id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $select = $this->getSelect() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |                        ->where(array('user_id' => $id)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $entity = $this->select($select)->current(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $this->getEventManager()->trigger('find', $this, array('entity' => $entity)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         return $entity; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     public function getTableName() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         return $this->tableName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     public function setTableName($tableName) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $this->tableName=$tableName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     public function insert($entity, $tableName = null, HydratorInterface $hydrator = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $result = parent::insert($entity, $tableName, $hydrator); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $entity->setId($result->getGeneratedValue()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     public function update($entity, $where = null, $tableName = null, HydratorInterface $hydrator = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         if (!$where) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             $where = array('user_id' => $entity->getId()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         return parent::update($entity, $where, $tableName, $hydrator); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 68 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |  |