mirror of
https://github.com/pierre42100/ComunicAPI
synced 2025-06-19 00:25:18 +00:00
Can search for users and groups from the API
This commit is contained in:
@ -37,6 +37,34 @@ class search {
|
||||
//Return result
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for groups in the database
|
||||
*
|
||||
* @param string $query
|
||||
* @param int $limit (default = 10)
|
||||
* @return array List of results
|
||||
*/
|
||||
public function search_group(string $query, int $limit = 10){
|
||||
|
||||
//Query string
|
||||
$query = "%".$query."%";
|
||||
|
||||
//Request
|
||||
$results = db()->select(
|
||||
GroupsComponent::GROUPS_LIST_TABLE,
|
||||
"WHERE name LIKE ?",
|
||||
array($query),
|
||||
array("id")
|
||||
);
|
||||
|
||||
//Parse and return results
|
||||
$list = array();
|
||||
foreach($results as $el)
|
||||
$list[] = $el["id"];
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
|
||||
//Register class
|
||||
|
@ -15,6 +15,17 @@ class SearchResult {
|
||||
private $kind;
|
||||
private $kind_id;
|
||||
|
||||
/**
|
||||
* Constructor of the object
|
||||
*
|
||||
* @param int $kind The kind of result (group, user...)
|
||||
* @param int $kind_id The ID of the result
|
||||
*/
|
||||
public function SearchResult(int $kind, int $kind_id){
|
||||
$this->set_kind($kind);
|
||||
$this->set_kind_id($kind_id);
|
||||
}
|
||||
|
||||
//Set and get the kind of object
|
||||
public function set_kind(int $kind){
|
||||
$this->kind = $kind;
|
||||
|
Reference in New Issue
Block a user