What it is
A LiveSearch extension allows administrators to search through your application in the AdminCP using the global live search at the top of every page. This can be useful if your application has data which an administrator may be attempting to find (such as category names or department titles).
How to use
The extension will contain 4 methods you will define
/**
* Constructor
*
* @return void
*/
public function __construct()
{
/* Check Permissions */
}
Any setup you need to perform, such as checking permissions, can be done in the constructor.
/**
* Check we have access
*
* @return bool
*/
public function hasAccess()
{
/* Check Permissions */
return TRUE;
}
The hasAccess() method is called to determine if the user has access to use the live search extension. If administrator restrictions may prevent the admin from being able to access your application, for instance, those permissions should be checked here to ensure searches do not reveal data to an administrator they otherwise would not be able to access.
/**
* Is default for current page?
*
* @return bool
*/
public function isDefault()
{
return \IPS\Dispatcher::i()->application->directory == 'myapp';
}
The isDefault() method should return a boolean to indicate if your live search extension should be the default extension shown when a live search is performed on the current page. Most often this is done by checking the current application and module, if necessary, to determine if your application is currently being accessed (and thus, live search should show results from it first, if any are available).
/**
* Get the search results
*
* @param string Search Term
* @return array Array of results
*/
public function getResults( $searchTerm )
{
return array();
}
The getResults() method accepts a string search term, and should return an array of search results to display. The array keys are irrelevant, however the values should be fully formatted HTML list items. A generic template is available at \IPS\Theme::i()->getTemplate( 'livesearch', 'core', 'admin' )->generic(), however in most cases you will be best served by creating a custom template and using that instead. The generic template you will want to use is akin to the following:
<ips:template parameters="$url, $lang" />
<li class='ipsPad_half ipsClearfix' data-role='result'>
<a href='{$url}' class='ipsPos_left'>{lang="$lang"}</a>
</li>
Report Document