application/models/User.php
/*
     * Insert / Update facebook profile data into the database
     * @param array the data for inserting into the table
     */
Insert / Update facebook profile data into the database
@param array the data for inserting into the table
Insert / Update facebook profile data into the database @param array the data for inserting into the table
public function checkUser($userData = array()){
        if(!empty($userData)){
            $this->db->select($this->primaryKey);
            $this->db->from($this->tableName);
            $this->db->where(array('oauth_provider'=>$userData['oauth_provider'], 'oauth_uid'=>$userData['oauth_uid']));
            $prevQuery = $this->db->get();
            $prevCheck = $prevQuery->num_rows();
            if($prevCheck > 0){
                $prevResult = $prevQuery->row_array();
                $userData['modified'] = date("Y-m-d H:i:s");
                $update = $this->db->update($this->tableName, $userData, array('id' => $prevResult['id']));
                $userID = $prevResult['id'];
            }else{
                $userData['created']  = date("Y-m-d H:i:s");
                $userData['modified'] = date("Y-m-d H:i:s");
                $insert = $this->db->insert($this->tableName, $userData);
                $userID = $this->db->insert_id();
            }
        }
        return $userID ? $userID:FALSE;
    }
public function checkUser ( $ userData = array ( ) ) { if ( ! empty ( $ userData ) ) { $ this -> db -> select ( $ this -> primaryKey ) ; $ this -> db -> from ( $ this -> tableName ) ; $ this -> db -> where ( array ( 'oauth_provider' => $ userData [ 'oauth_provider' ] , 'oauth_uid' => $ userData [ 'oauth_uid' ] ) ) ; $ prevQuery = $ this -> db -> get ( ) ; $ prevCheck = $ prevQuery -> num_rows ( ) ; if ( $ prevCheck > 0 ) { $ prevResult = $ prevQuery -> row_array ( ) ; $ userData [ 'modified' ] = date ( " Y-m-d H:i:s " ) ; $ update = $ this -> db -> update ( $ this -> tableName , $ userData , array ( 'id' => $ prevResult [ 'id' ] ) ) ; $ userID = $ prevResult [ 'id' ] ; } else { $ userData [ 'created' ] = date ( " Y-m-d H:i:s " ) ; $ userData [ 'modified' ] = date ( " Y-m-d H:i:s " ) ; $ insert = $ this -> db -> insert ( $ this -> tableName , $ userData ) ; $ userID = $ this -> db -> insert_id ( ) ; } } return $ userID ? $ userID : FALSE ; }
Insert / Update facebook profile data into the database
 @param array the data for inserting into the table
Insert / Update facebook profile data into the database @param array the data for inserting into the table
//check whether user data already exists in database with same oauth info //update user data //get user ID //insert user data //get user ID //return user ID