mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-27 07:49:27 +00:00
Updated DB library
This commit is contained in:
parent
6c35764f48
commit
5e03191c3d
@ -5,7 +5,7 @@
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
class userController
|
||||
class searchController
|
||||
{
|
||||
/**
|
||||
* Peform a research on the database
|
||||
@ -18,13 +18,17 @@ class userController
|
||||
Rest_fatal_error(400, "Please specify search terms");
|
||||
|
||||
//Check for search limit
|
||||
$seachLimit = (isset($_POST['searchLimit']) ? $_POST['searchLimit']*1 : 5);
|
||||
$searchLimit = (isset($_POST['searchLimit']) ? $_POST['searchLimit']*1 : 5);
|
||||
|
||||
//Check the limit
|
||||
if($seachLimit < 1 || $seachLimit > 25)
|
||||
if($searchLimit < 1 || $searchLimit > 25)
|
||||
Rest_fatal_error(401, "Invalid search limit !");
|
||||
|
||||
//Perform research on the database and return results
|
||||
if(!$results = CS::get()->components->searchUser->search($_POST['query'], $searchLimit))
|
||||
Rest_fatal_error(500, "An error occured while trying to perform a research in user list !");
|
||||
|
||||
//Return results
|
||||
return $results;
|
||||
}
|
||||
}
|
@ -317,9 +317,10 @@ class DBLibrary {
|
||||
* @param String $tableName The name of the table
|
||||
* @param String $conditions The conditions
|
||||
* @param Array $datasCond The values of condition
|
||||
* @param Array $fieldsList Optionnal, specify the fields to select during the request.
|
||||
* @return Array The result
|
||||
*/
|
||||
public function select($tableName, $conditions = "", array $datasCond = array()){
|
||||
public function select($tableName, $conditions = "", array $datasCond = array(), array $fieldsList = array()){
|
||||
//We try to perform the task
|
||||
try{
|
||||
//We check if any database is opened
|
||||
@ -327,8 +328,17 @@ class DBLibrary {
|
||||
throw new Exception("There isn't any opened DataBase !");
|
||||
}
|
||||
|
||||
//Process fields to select
|
||||
if(count($fieldsList) == 0)
|
||||
$fields = "*";
|
||||
else {
|
||||
$fields = "";
|
||||
foreach($fieldsList as $processField)
|
||||
$fields .= $processField.", ";
|
||||
}
|
||||
|
||||
//Generating SQL
|
||||
$sql = "SELECT * FROM ".$tableName." ".$conditions;
|
||||
$sql = "SELECT ".$fields." FROM ".$tableName." ".$conditions;
|
||||
$selectOBJ = $this->db->prepare($sql);
|
||||
$selectOBJ->execute($datasCond);
|
||||
|
||||
|
23
classes/components/searchUser.php
Normal file
23
classes/components/searchUser.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Search user controller
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
class searchUser {
|
||||
|
||||
/**
|
||||
* Search for user in the database
|
||||
*
|
||||
* @param Sting $query The query to research on the database
|
||||
* @param Integer $limit The number of results to return on the screen
|
||||
* @return Array the result of the result
|
||||
*/
|
||||
public function search($query, $limit){
|
||||
return array(1, 2);
|
||||
}
|
||||
}
|
||||
|
||||
//Register class
|
||||
Components::register("searchUser", new searchUser());
|
Loading…
Reference in New Issue
Block a user