API / Show an object: make API return all accessible attribute

The method now return all accessible attributes and not only thow who 
are configured to be displayed in view
This commit is contained in:
Benjamin Renard 2021-06-30 18:11:26 +02:00
parent 6bc1e46afb
commit 3c7ec2890a
3 changed files with 12 additions and 12 deletions

View file

@ -315,11 +315,13 @@ class LSattribute extends LSlog_staticLoggerClass {
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @param[in] $form LSform The LSform object
* @param[in] $api_mode boolean True if it's a view in API mode (=all accessible attributes present,
* optional, default: false)
*
* @retval boolean True on succes, False otherwise
*/
public function addToView(&$form) {
if (!$this -> getConfig('view', false, 'bool') || ($this -> myRights() == 'n') )
public function addToView(&$form, $api_mode=false) {
if ((!$api_mode && !$this -> getConfig('view', false, 'bool')) || ($this -> myRights() == 'n') )
return true;
$element = $this -> _addToForm($form, 'view');
if ($element) {

View file

@ -242,23 +242,21 @@ class LSldapObject extends LSlog_staticLoggerClass {
}
/**
* Construit un formulaire de l'objet
* Constuct a view for this object
*
* Cette méthode construit un formulaire LSform à partir de la configuration de l'objet
* et de chaque attribut.
* This method create a LSform in view mode from the object and its attributes configurations.
*
* @param[in] $idForm [<b>required</b>] Identifiant du formulaire a créer
* @param[in] $config Configuration spécifique pour le formulaire
* @param[in] $api_mode boolean Enable API mode (defaut: false)
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*
* @retval LSform Le formulaire crée
* @retval LSform The created LSform object
*/
public function getView() {
public function getView($api_mode=false) {
LSsession :: loadLSclass('LSform');
$this -> view = new LSform($this,'view');
$this -> view = new LSform($this, 'view', null, $api_mode);
foreach($this -> attrs as $attr_name => $attr) {
$this -> attrs[$attr_name] -> addToView($this -> view);
$this -> attrs[$attr_name] -> addToView($this -> view, $api_mode);
}
$this -> view -> can_validate = false;
return $this -> view;

View file

@ -1845,7 +1845,7 @@ function handle_api_LSobject_show($request) {
'relations' => array(),
);
$view = $object -> getView();
$view = $object -> getView(true); // get view in API
foreach($view -> elements as $element) {
$data['attributes'][$element -> name] = $element -> getApiValue($data['details']);
}