Stud.IP  5.4
QuickSearch Class Reference

Public Member Functions

 __construct ($name, $search=NULL)
 
 withButton ($design=[])
 
 withoutButton ()
 
 defaultValue ($valueID, $valueName)
 
 setInputClass ($class)
 
 setInputStyle ($style)
 
 setMinLength (int $minLength)
 
 noSelectbox ($set=true)
 
 disableAutocomplete ($disable=true)
 
 fireJSFunctionOnSelect ($function_name)
 
 setAttributes ($attr_array)
 
 hasExtendedLayout ()
 
 render ()
 
 __toString ()
 
 getId ()
 

Static Public Member Functions

static garbageCollect ()
 
static getFromSession ($query_id)
 
static get ($name, $search=NULL)
 

Data Fields

const GC_LIFETIME = 10800
 

Static Public Attributes

static $count_QS = 0
 

Protected Member Functions

 storeSearchInSession ()
 

Detailed Description

This class provides a small and intuitive GUI-element for an instant search of courses, persons, institutes or other items. Mainly the structure to include a QuickSearch-field is the following: //code-begin $sf = new QuickSearch("username"); $sf->withButton(); $sf->specialSQL("SELECT username, CONCAT(Vorname, \" ", Nachname) " . "FROM auth_user_md5 " . "WHERE CONCAT(Vorname, " ", Nachname) LIKE :input " . "AND perms = 'dozent'", _("Dozenten suchen")); print $sf->render(); //code-end This code should be included into an html <form>-tag. It will provide a nice looking input-field with a button (this is the $sf->withButton() command for), a javascript instant-search for your items (in this case 'Dozenten') and also a non-javascript oldschool version of a searchfield with a select-box in step 2 of the search (first write what you search, click on the button and then select in the select-box what you wanted to have). You can handle the searchfield in your form-tag as if you have written an '<input type="text" name="username">'.

For most cases you may only want to search for persons, courses or institutes. Thus a shortcut is implemented in this class. You may write //code-begin $sf = new QuickSearch("username", "username"); $sf->withButton(); print $sf->render(); //code-end to receive a searchfield that is automatically searching for users and inserts the selected users's username in the searchfield. The first parameter of the constructor 'new Quicksearch' is the name of the variable in your form and is completely free to name. The (optional) second parameter describes what you are searching for: username, user_id, Seminar_id or Institut_id.

Also you can do method-chaining with this class, so you can press everything you need infront of your semicolon. Watch this example: //code-begin print QuickSearch::get("username", "username")->withButton->render(); //code-end

Lastly you can replace the second argument of the constructor (or get-method) by an object whose class extends the SearchType-class. This might be useful to create your own searches and handle them with oop-style or even use a totally different search-engine like lucene-index! All you need to do so is implement your searchclass and follow this example: //code-begin class TeacherSearch extends SearchType { ... } $searcher = new TeacherSearch(); print QuickSearch::get("username", $searcher)->withButton->render(); //code-end Watch the SearchType class in lib/classes/searchtypes/SearchType.class.php for details. Enjoy!

Constructor & Destructor Documentation

◆ __construct()

__construct (   $name,
  $search = NULL 
)
final

constructor which prepares a searchfield for persons, courses, institutes or special items you may want to search for. This is a GUI-class, see QuickSearch.class.php for further documentation.

Parameters
string$namethe name of the destinated variable in your html-form. Handle it as if it was an '<input type="text" name="yourname">' input.
string$searchif set to user_id, username, Seminar_id, Arbeitsgruppe_id or Institute_id the searchfield will automatically search for persons, courses, workgroups, institutes and you don't need to call the specialSearch-method.
Returns
void

Member Function Documentation

◆ __toString()

__toString ( )

Convert quicksearch to string by rendering it

Returns
string rendered html

◆ defaultValue()

defaultValue (   $valueID,
  $valueName 
)

Here you can set a default-value for the searchfield

Parameters
string$valueIDthe default-ID that should be stored
string$valueNamethe default value, that should be displayed
  • remember that these may not be the same, they may be something like "ae2b1fca515949e5d54fb22b8ed95575", "test_dozent"
Returns
QuickSearch

◆ disableAutocomplete()

disableAutocomplete (   $disable = true)

disables the ajax autocomplete for this searchfield If you want to disable all QuickSearches, you better use the config variable global -> AJAX_AUTOCOMPLETE_DISABLED

Parameters
disableboolean: true (default) to disable, false to enable autocomplete via ajax.
Returns
QuickSearch

◆ fireJSFunctionOnSelect()

fireJSFunctionOnSelect (   $function_name)

set a JavaScript-function to be fired after the user has selected a value in the QuickSearch field. Arguments are: function fireme(id_of_item, text_of_item) example setting: QS->fireJSFunctionOnSelect('fireme');

Parameters
string$function_namethe name of the javascript function
Returns
QuickSearch

◆ garbageCollect()

static garbageCollect ( )
static

Deletes all older requests that have not been used for three hours from the session

Returns
int Number of removed searches

◆ get()

static get (   $name,
  $search = NULL 
)
static

returns an instance of QuickSearch so you can use it as singleton

Parameters
string$namethe name of the destinated variable in your html-form. Handle it as if it was an '<input type="text" name="yourname">' input.
string$searchif set to user_id, username, Seminar_id, Arbeitsgruppe_id or Institute_id the searchfield will automatically search for persons, courses, workgroups, institutes and you don't need to call the specialSearch-method.
Returns
object of type QuickSearch

◆ getFromSession()

static getFromSession (   $query_id)
static

Retrieves the search object for the given id previously stored in the session.

Parameters
String$query_idId of the quicksearch object
Returns
SearchType Quicksearch object
Exceptions
RuntimeExceptionwhen the given query does not exist in session

◆ getId()

getId ( )

returns the id string used for the input field

Returns
string

◆ hasExtendedLayout()

hasExtendedLayout ( )

Returns whether the underlying search type requires an extended layout.

Returns
bool indicating whether an extended layout is required

◆ noSelectbox()

noSelectbox (   $set = true)

disables the select-box, which is displayed for non-JS users who will choose with this box, which item they want to have.

Parameters
bool$setfalse if we DO want a select-box, false otherwise
Returns
QuickSearch

◆ render()

render ( )

last step: display everything and be happy! comment: the Ajax-Result (for the javascript-instant-search) will be also displayed here, but that does not need to concern you.

Returns
string

◆ setAttributes()

setAttributes (   $attr_array)

assigns special attributes to the html-element of the searchfield

Parameters
array$ttr_arraylike array("title" => "hello world")
Returns
QuickSearch

◆ setInputClass()

setInputClass (   $class)

defines a css class for the searchfield

Parameters
string$classany css class name for the "input type=text" tag
Returns
QuickSearch

◆ setInputStyle()

setInputStyle (   $style)

defines css-proporties for searchfield that will be included as 'style="$style"'

Parameters
string$styleone or more css-proporties separated with ";"
Returns
QuickSearch

◆ setMinLength()

setMinLength ( int  $minLength)

Set the minimum length to start searching

Parameters
int$minLength
Returns
QuickSearch

◆ storeSearchInSession()

storeSearchInSession ( )
protected

Abfrage in der Session speichern

Returns
string

◆ withButton()

withButton (   $design = [])

if set to true, the searchfield will be a nice-looking grey searchfield with a magnifier-symbol as a submit-button. Set this to false to create your own submit-button and style of the form.

Parameters
mixed$designassociative array of params.
Returns
QuickSearch

◆ withoutButton()

withoutButton ( )

this will disable a submit button for the searchfield

Returns
QuickSearch

Field Documentation

◆ $count_QS

$count_QS = 0
static

◆ GC_LIFETIME

const GC_LIFETIME = 10800

The documentation for this class was generated from the following file: