Please upgrade here. These earlier versions are no longer being updated and have security issues.

Issues with Using Override method on UserModel Search

SudoCatSudoCat Drowning under a Sea of Clients New
edited October 2014 in Vanilla 2.0 - 2.8

As part of this large ongoing project, I need to create a members list where you can search the members. I've got the basics of that all up and working, however there are quite a few extra fields in the user database (Such as Real Name) which will also need to be searched by.

Unfortunately, the UserModel Search method has no events I could hook into to include the extra fields in the array (line 1950), so I was attempting to use the override method to add it in to avoid editing core code, however it doesn't change anything.

Any ideas on how to approach this? I'd prefer not to just create a new method for it; That's a lot of duplicate code for 1 line, and also would mean that other parts of the site using the Search function still wouldn't be able to search by real name, which is really the most crucial one here.

Thanks

EDIT: Oh, and of course the same to the SearchCount method.

Best Answers

Answers

  • SudoCatSudoCat Drowning under a Sea of Clients New

    I have also just attempted to do it via creating a new method and for some reason it's not getting any of the variables passed to it... Totally confused now. Am I just going to have to create an extension of the user model to do this?

  • hgtonighthgtonight ∞ · New Moderator

    Just pass an array into the Search method for the $Keywords parameter. If that is an array, it gets passed into the Gdn_SQL->Where() method.

    Or am I being completely naive here?

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • SudoCatSudoCat Drowning under a Sea of Clients New

    Yeah I have thought of that as a last resort, and also probably what I shall do for some of the other fields. Would passing the array result in it still doing a like check, or would it try to do an equals search? For instance if searching for "Jon" would it find only "Jon" or "Jon Smith, Jon Paul" etc.

    Ideally, the best thing would be to have an event hook added into those two methods so that extra fields could be added to it. We want to make sure that any times the UserModel()->Search() is called in it's most basic method (ie passing it a simple keyword as a string) that it searches for the Real Name as well as the Username and Email.

    I hope that makes sense, I'm not sure if it does...

  • SudoCatSudoCat Drowning under a Sea of Clients New
    edited October 2014

    Yeah that's what I was thinking, unfortunately my custom search methods aren't receiving any of the variables I'm passing, they're just remaining as the defaults. Not sure if there's anything you can see wrong with this?

    $this->Members = $this->UserModel->SearchE($Filter, '', 'asc', $Limit, $Offset)->Result();

    I guess if it's not used more than once (and that one instance is on the admin section to my knowledge) then it shouldn't be much of a concern, however I would expect it to be used by the mentions plugin amongst others, so I guess I'll have to update them too.

    It looks like the only available method will be created a new model extending the standard user model. Is there a process for requesting events to be added to the core?

    Thanks for all the help.

    EDIT: Okay just checked, it isn't apparently used in any of the plugins, so looks like I'll have to edit the mentions plugin manually anyway. I've gone with simply extending the class for the time being.

  • SudoCatSudoCat Drowning under a Sea of Clients New

    Thankyou! That is exactly what I was looking for :) I've already started doing it in a model extension, so I'll probably stick with it for now, but that'll most likely save me in future. Most confused because I don't remember having used it on any of the previous methods I've created (And there are so damn many that I've ended up dividing them between files by now just so I know where to find what I'm looking for)

Sign In or Register to comment.