mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-12-25 13:08:58 +00:00
Parse user entry into GeneralSettings object.
This commit is contained in:
parent
bb752d6fb1
commit
5ab89ec6d8
@ -16,7 +16,14 @@ class SettingsController {
|
||||
|
||||
user_login_required(); //Login needed
|
||||
|
||||
|
||||
//Fetch user settings
|
||||
$user_settings = components()->settings->get_general(userID);
|
||||
|
||||
//Check for error
|
||||
if(!$user_settings->isValid())
|
||||
Rest_fatal_error(500, "Could not get user settings !");
|
||||
|
||||
print_r($user_settings);
|
||||
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,77 @@
|
||||
|
||||
class SettingsComponents {
|
||||
|
||||
|
||||
/**
|
||||
* Get and return general settings of a user
|
||||
*
|
||||
* @param int $userID The ID of the target user
|
||||
* @return GeneralSettings General settings about the user / invalid object in case
|
||||
* of failure
|
||||
*/
|
||||
public function get_general(int $userID) : GeneralSettings {
|
||||
|
||||
//Get user database entry
|
||||
$entry = $this->getDBUserInfo($userID);
|
||||
|
||||
//Check for error
|
||||
if(count($entry) == 0)
|
||||
return new GeneralSettings(); //Return invalid object
|
||||
|
||||
//Parse database entry into GeneralSettings entry
|
||||
return $this->dbToGeneralSettings($entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Single User Infos from database and return its information as an array
|
||||
*
|
||||
* @param int $userID The user ID
|
||||
* @return array Information about the user (empty array in case of failure)
|
||||
*/
|
||||
private function getDBUserInfo(int $userID) : array {
|
||||
//Prepare database request
|
||||
$tablesName = AccountComponent::USER_TABLE;
|
||||
$conditions = "WHERE utilisateurs.ID = ?";
|
||||
$conditionsValues = array(
|
||||
$userID*1,
|
||||
);
|
||||
|
||||
//Perform request
|
||||
$userInfos = CS::get()->db->select($tablesName, $conditions, $conditionsValues);
|
||||
|
||||
//Check if result is correct or not
|
||||
if(count($userInfos) == 0)
|
||||
return array(); //No result
|
||||
|
||||
//Return parsed result
|
||||
return($userInfos[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a user information entry into GeneralSettings object
|
||||
*
|
||||
* @param array $entry The database entry to process
|
||||
* @return GeneralSettings Generated GeneralSettings entry
|
||||
*/
|
||||
private function dbToGeneralSettings(array $entry) : GeneralSettings {
|
||||
|
||||
$obj = new GeneralSettings();
|
||||
|
||||
$obj->set_id($entry['ID']);
|
||||
$obj->set_email($entry['mail']);
|
||||
$obj->set_firstName($entry['prenom']);
|
||||
$obj->set_lastName($entry['nom']);
|
||||
$obj->set_publicPage($entry['public'] == 1);
|
||||
$obj->set_openPage($entry['pageouverte'] == 1);
|
||||
$obj->set_allowComments($entry['bloquecommentaire'] == 0);
|
||||
$obj->set_allowPostsFriends($entry['autoriser_post_amis'] == 1);
|
||||
$obj->set_allowComunicMails($entry['autorise_mail']);
|
||||
$obj->set_friendsListPublic($entry['liste_amis_publique']);
|
||||
$obj->set_virtualDirectory($entry['sous_repertoire'] == null ? "" : $entry['sous_repertoire']);
|
||||
$obj->set_personnalWebsite($entry['site_web'] == null ? "" : $entry['site_web']);
|
||||
|
||||
return $obj;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -10,14 +10,15 @@ class GeneralSettings {
|
||||
//Private fields
|
||||
private $id;
|
||||
private $email;
|
||||
private $firstname;
|
||||
private $lastname;
|
||||
private $firstName;
|
||||
private $lastName;
|
||||
private $publicPage;
|
||||
private $openPage;
|
||||
private $allowComments;
|
||||
private $allowPostsFriends;
|
||||
private $allowComunicMails;
|
||||
private $friendsListPublic;
|
||||
private $virtualDirectory;
|
||||
private $personnalWebsite;
|
||||
|
||||
//Set and get user ID
|
||||
@ -127,6 +128,19 @@ class GeneralSettings {
|
||||
return $this->virtualDirectory != null ? $this->virtualDirectory : "null";
|
||||
}
|
||||
|
||||
//Set and get the personnal website of the user
|
||||
public function set_personnalWebsite(string $personnalWebsite){
|
||||
$this->personnalWebsite = $personnalWebsite == "" ? null : $personnalWebsite;
|
||||
}
|
||||
|
||||
public function has_personnalWebsite() : bool {
|
||||
return $this->personnalWebsite != null;
|
||||
}
|
||||
|
||||
public function get_personnalWebsite() : string {
|
||||
return $this->personnalWebsite != null ? $this->personnalWebsite : "null";
|
||||
}
|
||||
|
||||
/**
|
||||
* Check wether is object is valid or not
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user